www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - hash function

reply "Adam D. Ruppe" <destructionator gmail.com> writes:
druntime has a hash implementation in module rt.util.hash that 
looks pretty useful, but isn't publicaly exported by the library 
anywhere.

Does phobos or druntime offer a public hash function like that? 
If no, can it expose this one?
Feb 14 2013
next sibling parent "H. S. Teoh" <hsteoh quickfur.ath.cx> writes:
On Fri, Feb 15, 2013 at 03:26:28AM +0100, Adam D. Ruppe wrote:
 druntime has a hash implementation in module rt.util.hash that looks
 pretty useful, but isn't publicaly exported by the library anywhere.
 
 Does phobos or druntime offer a public hash function like that? If
 no, can it expose this one?

+1. This is a very good and useful hash function that should be usable by user code. No need to force the user to reinvent the wheel or copy-n-paste code. T -- The diminished 7th chord is the most flexible and fear-instilling chord. Use it often, use it unsparingly, to subdue your listeners into submission!
Feb 14 2013
prev sibling next sibling parent reply "Zach the Mystic" <reachBUTMINUSTHISzach gOOGLYmail.com> writes:
On Friday, 15 February 2013 at 02:26:31 UTC, Adam D. Ruppe wrote:
 druntime has a hash implementation in module rt.util.hash that 
 looks pretty useful, but isn't publicaly exported by the 
 library anywhere.

 Does phobos or druntime offer a public hash function like that? 
 If no, can it expose this one?

This might be a good time to bring up something that was bothering me when I examined the current druntime hash implementation. Just out of curiosity I was researching hash functions, and I found the hash function expert Bob Jenkins' FAQ about hashes: http://burtleburtle.net/bob/hash/hashfaq.html He says specifically that any hash function requiring a modulo prime at the end is bad (inefficient), but if I'm not mistaken, the druntime does just that. At line 50 of the associative array module there is a list of primes, and I believe the implementation assumes them to be necessary. https://github.com/D-Programming-Language/druntime/blob/master/src/rt/aaA.d I don't know enough to be sure this is a problem. There might be some other reason for the modulo prime, but I'd like to put my mind at ease on it.
Feb 14 2013
parent "Zach the Mystic" <reachBUTMINUSTHISzach gOOGLYmail.com> writes:
On Friday, 15 February 2013 at 03:33:13 UTC, Zach the Mystic 
wrote:
 This might be a good time to bring up something that was 
 bothering me when I examined the current druntime hash 
 implementation. Just out of curiosity I was researching hash 
 functions, and I found the hash function expert Bob Jenkins' 
 FAQ about hashes:

 http://burtleburtle.net/bob/hash/hashfaq.html

 He says specifically that any hash function requiring a modulo 
 prime at the end is bad (inefficient), but if I'm not mistaken, 
 the druntime does just that. At line 50 of the associative 
 array module there is a list of primes, and I believe the 
 implementation assumes them to be necessary.

 https://github.com/D-Programming-Language/druntime/blob/master/src/rt/aaA.d

 I don't know enough to be sure this is a problem. There might 
 be some other reason for the modulo prime, but I'd like to put 
 my mind at ease on it.

Without objection, so filed... http://d.puremagic.com/issues/show_bug.cgi?id=9522
Feb 16 2013
prev sibling parent reply Jacob Carlborg <doob me.com> writes:
On 2013-02-15 03:26, Adam D. Ruppe wrote:
 druntime has a hash implementation in module rt.util.hash that looks
 pretty useful, but isn't publicaly exported by the library anywhere.

 Does phobos or druntime offer a public hash function like that? If no,
 can it expose this one?

TypeInfo has a "getHash" method. -- /Jacob Carlborg
Feb 14 2013
parent reply "H. S. Teoh" <hsteoh quickfur.ath.cx> writes:
On Fri, Feb 15, 2013 at 08:28:34AM +0100, Jacob Carlborg wrote:
 On 2013-02-15 03:26, Adam D. Ruppe wrote:
druntime has a hash implementation in module rt.util.hash that looks
pretty useful, but isn't publicaly exported by the library anywhere.

Does phobos or druntime offer a public hash function like that? If no,
can it expose this one?

TypeInfo has a "getHash" method.

[...] Which has a lot of bugs and inconsistencies. Like the fact that hashing a char[], a const(char)[], and a string (immutable(char)[]) gives different results. T -- Blunt statements really don't have a point.
Feb 15 2013
parent Jacob Carlborg <doob me.com> writes:
On 2013-02-15 16:13, H. S. Teoh wrote:

 Which has a lot of bugs and inconsistencies. Like the fact that hashing
 a char[], a const(char)[], and a string (immutable(char)[]) gives
 different results.

Didn't know that. I just knew it existed. -- /Jacob Carlborg
Feb 15 2013