Skip to content
This repository has been archived by the owner on Oct 12, 2022. It is now read-only.

core.internal.hash.bytesHash: in 64-bit builds use a 64-bit-oriented algorithm #3148

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

n8sh
Copy link
Member

@n8sh n8sh commented Jul 2, 2020

Motivation: doesn't discard high 32 bits of seed; produces 64 bits of output; and is a bit faster.

@dlang-bot
Copy link
Contributor

dlang-bot commented Jul 2, 2020

Thanks for your pull request, @n8sh!

Bugzilla references

Auto-close Bugzilla Severity Description
21006 enhancement core.internal.hash.bytesHash: in 64-bit builds use a 64-bit-oriented algorithm

Testing this PR locally

If you don't have a local development environment setup, you can use Digger to test this PR:

dub run digger -- build "master + druntime#3148"

@dlang-bot dlang-bot added the Enhancement New functionality label Jul 2, 2020
@n8sh n8sh force-pushed the issue-21006 branch 2 times, most recently from b28789a to 077c6dc Compare July 2, 2020 00:52
@n8sh
Copy link
Member Author

n8sh commented Jul 2, 2020

Test runnable/testaa2.d failed: 
expected:
----
foo()
foo() 2
foo() 3
foo() 4
c["foo"] = 3
c["bar"] = 4
Success
----
actual:
----
foo()
foo() 2
foo() 3
foo() 4
c["bar"] = 4
c["foo"] = 3
Success

A DMD test is failing because it depends on a specific AA traversal order. I am inclined to consider that erroneous based on https://dlang.org/spec/hash-map.html:

The built-in associative arrays do not preserve the order of the keys inserted into the array. In particular, in a foreach loop the order in which the elements are iterated is typically unspecified.

@Geod24
Copy link
Member

Geod24 commented Jul 2, 2020

Indeed. This test should be fixed.

@MoonlightSentinel
Copy link
Contributor

Please add a reference for this hash algorithm in a comment

Comment on lines 748 to 832
version (BigEndian)
{
auto k1 =
((cast(ulong) data[0]) << 56) |
((cast(ulong) data[1]) << 48) |
((cast(ulong) data[2]) << 40) |
((cast(ulong) data[3]) << 32) |
((cast(ulong) data[4]) << 24) |
((cast(ulong) data[5]) << 16) |
((cast(ulong) data[6]) << 8) |
(cast(ulong) data[7]);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couldn't this use the pointer read optimization as done for the 32 bit hash above?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now it does.

@n8sh n8sh force-pushed the issue-21006 branch 2 times, most recently from 35ad7df to 2fba8d3 Compare August 2, 2020 19:24
Copy link
Contributor

@RazvanN7 RazvanN7 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@n8sh maybe a rebase will fix the current failures.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Enhancement New functionality stalled
Projects
None yet
5 participants