...
| Code Block | ||
|---|---|---|
| ||
// method imod() gives non-negative result
private int SIZE = 16;
public int[] hash = new int[SIZE];
private int imod(int i, int j) {
int temp = i % j;
return (temp < 0) ? -temp : temp; // unary - will succeed without overflow
// because temp cannot be Integer.MIN_VALUE
}
public int lookup(int hashKey) {
return hash[imod(hashKey, sizeSIZE)];
}
|
Risk Assessment
Incorrectly assuming a positive remainder from a remainder operation can result in erroneous code.
...
<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="7918b8e94aa50afc-0db054c6-42784d79-a1c3a79a-90aa6b454537ddde383aeb74"><ac:plain-text-body><![CDATA[ | [[JLS 2005 | AA. Bibliography#JLS 05]] | [§15.17.3, "Remainder Operators" | http://java.sun.com/docs/books/jls/third_edition/html/expressions.html#15.17.3] | ]]></ac:plain-text-body></ac:structured-macro> |
...