eliminate alias
authorjjenista <jjenista>
Mon, 10 Nov 2008 22:52:40 +0000 (22:52 +0000)
committerjjenista <jjenista>
Mon, 10 Nov 2008 22:52:40 +0000 (22:52 +0000)
Robust/src/ClassLibrary/HashMap.java

index 78040e77e2a73719ec9e2366dab567a20421718c..db028844a80aa36bad8a0228b02967e2147193f6 100644 (file)
@@ -21,10 +21,10 @@ public class HashMap {
     this.numItems=0;
   }
 
-  private int hash(Object o) {
+  private static int hash(Object o, int length) {
     if (o==null)
       return 0;
-    int value=o.hashCode()%table.length;
+    int value=o.hashCode()%length;
     if (value<0)
       return -value;
     return value;
@@ -39,7 +39,7 @@ public class HashMap {
       HashEntry e=oldtable[i];
       while(e!=null) {
        HashEntry next=e.next;
-       int bin=hash(e.key);
+       int bin=hash(e.key, newCapacity);
        e.next=table[bin];
        table[bin]=e;
        e=next;
@@ -61,7 +61,7 @@ public class HashMap {
   }
 
   Object remove(Object key) {
-    int bin=hash(key);
+    int bin=hash(key, table.length);
     HashEntry ptr=table[bin];
     if (ptr!=null) {
       if (ptr.key.equals(key)) {
@@ -83,7 +83,7 @@ public class HashMap {
   }
 
   Object get(Object key) {
-    int bin=hash(key);
+    int bin=hash(key, table.length);
     HashEntry ptr=table[bin];
     while(ptr!=null) {
       if (ptr.key.equals(key)) {
@@ -95,7 +95,7 @@ public class HashMap {
   }
 
   boolean containsKey(Object key) {
-    int bin=hash(key);
+    int bin=hash(key, table.length);
     HashEntry ptr=table[bin];
     while(ptr!=null) {
       if (ptr.key.equals(key)) {
@@ -112,7 +112,7 @@ public class HashMap {
       //Resize the table
       resize();
     }
-    int bin=hash(key);
+    int bin=hash(key, table.length);
     HashEntry ptr=table[bin];
     while(ptr!=null) {
       if (ptr.key.equals(key)) {