ssteenkiste / nettiers

Automatically exported from code.google.com/p/nettiers
1 stars 0 forks source link

Broken Hashing On Entities - New Implementation (patch attached) #398

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
The current implementation of GetHashCode() is broken and not as good as it 
could be either.  It currently uses basic XOR to perform the hash.

If you create a new entity and call GetHashCode on it then it will generate a 
NullReferenceException.  The only null checks which take place are on nullable 
fields.   If you perform the check with a completely empty entity then it will 
fall over.

Having done further research on hashing many people have recommended the 
Jenkins Hash rather than just XORing.  
http://en.wikipedia.org/wiki/Jenkins_hash_function

I have added support for the Jenkins hash.  It hashes a byte array into an int. 
 The byte array conversion is different depending if [Serialize] or 
[DataContract] is used.

If you need something more robust than what is already present (or you are 
having problems with NullReferenceException then please consider using this 
patch.

Comments welcome

Original issue reported on code.google.com by james.pa...@gmail.com on 2 Sep 2011 at 8:46

Attachments:

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
Hello,

Thanks for your patch! I'm assigning this to Jeff as his team has had long 
discussions and research into the .netTiers HashCode function.

There was an issue located 
http://code.google.com/p/nettiers/issues/detail?id=88 as well as on our forums 
someplace. I looked but couldn't find the discussion (but this hits on it a bit 
(http://community.codesmithtools.com/nettiers/f/16/p/6101/23634.aspx#23634) :\.

Original comment by bniemyjski on 6 Sep 2011 at 2:13