Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: fixing code sample for compilation

...

Code Block
bgColor#ccccff
// 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="a5f0944bea06c70a-445452ed-4fbc4a2e-8cf6a25f-9f64ada6cfe3a2769f8bd417"><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>

...