[Issue 19072] New: Object.toHash and typeid(void*).getHash(&ptr) should be more varied in their low bits
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Mon Jul 9 19:52:26 UTC 2018
https://issues.dlang.org/show_bug.cgi?id=19072
Issue ID: 19072
Summary: Object.toHash and typeid(void*).getHash(&ptr) should
be more varied in their low bits
Product: D
Version: D2
Hardware: All
OS: All
Status: NEW
Severity: enhancement
Priority: P1
Component: druntime
Assignee: nobody at puremagic.com
Reporter: n8sh.secondary at hotmail.com
The low bits of `Object.toHash` are insufficiently varied. Depending on the
platform the bottom 4, 3, or 2 bits of the result will always be zero. This is
bad because the low bits of a hash code are typically the most significant for
hashtable implementations. D's builtin AA deals with this and other potential
defects by rehashing the hash codes it receives. Some 3rd party hashtable
implementations do the same, but others assume that keys with a defined
`toHash` have reasonable hashcodes that can be used without need for further
mixing. Fixing this would not be hard. The same can be done for raw pointers;
although it will not always be necessary for them the cost is low and it will
frequently be a benefit.
--
More information about the Digitalmars-d-bugs
mailing list