From 13cbbf0e639fc22e2d0cef4cce0c28c99b459af3 Mon Sep 17 00:00:00 2001 From: bdemsky Date: Mon, 6 Nov 2006 06:48:55 +0000 Subject: [PATCH] Interestingly, % in Java or C doesn't give the results that the modulo is mathematically defined to...it can return negative numbers... --- Robust/src/ClassLibrary/HashMap.java | 32 ++++++++++++++++++---------- 1 file changed, 21 insertions(+), 11 deletions(-) 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