Created
December 30, 2011 00:23
-
-
Save MrTrick/1536892 to your computer and use it in GitHub Desktop.
Terrible hashing function
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Node { | |
public final static boolean GADDAG_PREPEND = false, GADDAG_APPEND = true; | |
Node[] children = new Node[CHILD_COUNT]; | |
boolean end_of_word = false, gaddag_mode = GADDAG_PREPEND; | |
char letter; | |
... | |
/** | |
* Hashcode is calculated from the identity of the child nodes, and internal fields. | |
*/ | |
@Override | |
public int hashCode() { | |
int i, hashcode = 0; | |
for( i=0; i < CHILD_COUNT; i++ ) | |
hashcode += 37*i*System.identityHashCode(this.children[i]); //Hash against the *identity* of the children | |
hashcode += 37*(CHILD_COUNT+1)*(this.end_of_word ? 1 : 0); | |
hashcode += 37*(CHILD_COUNT+2)*(this.gaddag_mode ? 1 : 0); | |
hashcode += 37*(CHILD_COUNT+3)*this.letter; | |
return hashcode; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment