/** * Java version of the assembler hashCode used in the BBL Forth compiler. * Because of the 1-bit shift you don't lose data completely on long keys. * The shift breaks up patterns in the data. * @return a hash code value for the byte[] val byte array in this object. */ public int hashCode() { // byte[] val holds the data. int hash = 0; int len = val.length(); for ( int i=0; i<len; i++ ) { // rotate left and xor (very fast in assembler, a bit clumsy to specify in Java, but a smart compiler might collapse it to two machine instructions) hash <<= 1; if ( hash < 0 ) { hash |= 1; } hash ^= val[ i ]; } return hash; }