...
Code Block | ||
---|---|---|
| ||
/* modulo function giving non-negative result */ private int imod(int i, int j) { return (i < 0) ? ((-i) % j) : (i % j); } private int size=16; public int[] hashTable=new int[size]; public int lookup(int hash) { return hashTable[imod(ihash, jsize)]; } |
Or, an explicit range check must be preformed on the numerator.
...