Skip to content

Instantly share code, notes, and snippets.

@MrTrick
Created December 30, 2011 00:23
Show Gist options
  • Save MrTrick/1536892 to your computer and use it in GitHub Desktop.
Save MrTrick/1536892 to your computer and use it in GitHub Desktop.
Terrible hashing function
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