js delete key fix
authorbrian <brian@brianweb.net>
Thu, 20 May 2004 04:05:12 +0000 (04:05 +0000)
committerbrian <brian@brianweb.net>
Thu, 20 May 2004 04:05:12 +0000 (04:05 +0000)
darcs-hash:20040520040512-24bed-6e83fedd64ae1bfe845046dc0fad8fb2a1407f87.gz

src/org/ibex/util/Hash.java

index 4b38870..4ee02c8 100644 (file)
@@ -151,21 +151,22 @@ public class Hash {
     }
 
     private class HashEnum implements java.util.Enumeration {
-        private int iterator = 0;
-        private int found = 0;
+        private int iterator;
+        
+        public HashEnum() { findNext(); }
+        
+        private void findNext() {
+            while(iterator < keys1.length && (keys1[iterator] == null || keys1[iterator] == placeholder)) iterator++;
+        }
         
         public boolean hasMoreElements() {
-            return found < usedslots;
+            return iterator < keys1.length;
         }
 
         public Object nextElement() {
-            if (!hasMoreElements()) throw new java.util.NoSuchElementException();
-
-            Object o = null;
-            while (o == null) o = keys1[iterator++];
-            if (o == null) throw new IllegalStateException("Didn't find an element, when I should have.");
-            found++;
-            
+            if (iterator == keys1.length) throw new NoSuchElementException();
+            Object o = keys1[iterator];
+            findNext();
             return o;
         }
     }