hash-code-uniqueness

How to generate a hash code from three longs

倾然丶 夕夏残阳落幕 提交于 2019-12-03 14:33:38
I have a HashMap with coordinates as keys. Coordinates have 3 longs holding the x, y and z coordinate. (Coordinate is and needs to be a custom class, the coordinates need to be longs). Now i want to be able to access e.g. the field [5, 10, 4] by doing: hashMap.get(new Coordinate(5, 10, 4)) . I have implemented the equals method but that is not enough since apparently i need to provide an implementation for hashCode as well. So my question is how do i generate an unique hashCode from three longs? . Additional: Using a hash generator from an external library is not option. Joshua Bloch tells you

Fast HashCode of a Complex Object Graph

不羁的心 提交于 2019-12-01 21:10:15
I have a pretty complex object and I need to get uniqueness of these objects. One solution can be done by overriding GetHashCode() . I have implemented a code noted below: public override int GetHashCode() { return this._complexObject1.GetHashCode() ^ this._complexObject2.GetHashCode() ^ this._complexObject3.GetHashCode() ^ this._complexObject4.GetHashCode() ^ this._complexObject5.GetHashCode() ^ this._complexObject6.GetHashCode() ^ this._complexObject7.GetHashCode() ^ this._complexObject8.GetHashCode(); } These complex objects also overrides GetHashCode() and does similar operations . My

Tinyurl-style unique code: potential algorithm to prevent collisions

烈酒焚心 提交于 2019-11-29 02:19:12
I have a system that requires a unique 6-digit code to represent an object, and I'm trying to think of a good algorithm for generating them. Here are the pre-reqs: I'm using a base-20 system (no caps, numbers, vowels, or l to prevent confusion and naughty words) The base-20 allows 64 million combinations I'll be inserting potentially 5-10 thousand entries at once, so in theory I'd use bulk inserts, which means using a unique key probably won't be efficient or pretty (especially if there starts being lots of collisions) It's not out of the question to fill up 10% of the combinations so there's

Probability of getting a duplicate value when calling GetHashCode() on strings

戏子无情 提交于 2019-11-27 05:14:47
I want to know the probability of getting duplicate values when calling the GetHashCode() method on string instances. For instance, according to this blog post, blair and brainlessness have the same hashcode (1758039503) on an x86 machine. Large. (Sorry Jon!) The probability of getting a hash collision among short strings is extremely large . Given a set of only ten thousand distinct short strings drawn from common words, the probability of there being at least one collision in the set is approximately 1%. If you have eighty thousand strings, the probability of there being at least one

Probability of getting a duplicate value when calling GetHashCode() on strings

ⅰ亾dé卋堺 提交于 2019-11-26 11:28:44
问题 I want to know the probability of getting duplicate values when calling the GetHashCode() method on string instances. For instance, according to this blog post, blair and brainlessness have the same hashcode (1758039503) on an x86 machine. 回答1: Large. (Sorry Jon!) The probability of getting a hash collision among short strings is extremely large . Given a set of only ten thousand distinct short strings drawn from common words, the probability of there being at least one collision in the set

Why is '397' used for ReSharper GetHashCode override?

自作多情 提交于 2019-11-26 09:16:35
问题 Like many of you, I use ReSharper to speed up the development process. When you use it to override the equality members of a class, the code-gen it produces for GetHashCode() looks like: public override int GetHashCode() { unchecked { int result = (Key != null ? Key.GetHashCode() : 0); result = (result * 397) ^ (EditableProperty != null ? EditableProperty.GetHashCode() : 0); result = (result * 397) ^ ObjectId; return result; } } Of course I have some of my own members in there, but what I am