From: bdemsky Date: Mon, 6 Nov 2006 06:48:55 +0000 (+0000) Subject: Interestingly, % in Java or C doesn't give the results that the modulo is X-Git-Tag: preEdgeChange~760 X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=13cbbf0e639fc22e2d0cef4cce0c28c99b459af3;p=IRC.git Interestingly, % in Java or C doesn't give the results that the modulo is mathematically defined to...it can return negative numbers... --- diff --git a/Robust/src/ClassLibrary/HashMap.java b/Robust/src/ClassLibrary/HashMap.java index d977e052..11dfdf3f 100644 --- a/Robust/src/ClassLibrary/HashMap.java +++ b/Robust/src/ClassLibrary/HashMap.java @@ -21,20 +21,30 @@ public class HashMap { this.numItems=0; } + private int hash(Object o) { + if (o==null) + return 0; + int value=o.hashCode()%table.length; + if (value<0) + return -value; + return value; + } + void resize() { int newCapacity=2*table.length+1; - HashEntry[] newtable=new HashEntry[newCapacity]; - for(int i=0;i