From 8c99752a4272d9b4eb969e80555d312a8cfb3179 Mon Sep 17 00:00:00 2001 From: corey Date: Fri, 30 Jan 2004 07:42:30 +0000 Subject: [PATCH] 2003/12/02 20:23:39 darcs-hash:20040130074230-93698-9ec55ff676683530c09e9c8bce32a789600e6c69.gz --- src/org/xwt/util/Hash.java | 31 ++++++++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/src/org/xwt/util/Hash.java b/src/org/xwt/util/Hash.java index a7524cd..e36f667 100644 --- a/src/org/xwt/util/Hash.java +++ b/src/org/xwt/util/Hash.java @@ -7,9 +7,10 @@ import java.util.*; * keys, using Radke's quadradic residue linear probing instead of * buckets to minimize object count (less allocations, faster GC). * See C. Radke, Communications of the ACM, 1970, 103-105 + * + * Not threadsafe. */ public class Hash { - /** this object is inserted as key in a slot when the * corresponding value is removed -- this ensures that the * probing sequence for any given key remains the same even if @@ -51,8 +52,7 @@ public class Hash { /** returns all the primary keys in the table */ public Enumeration keys() { - // FIXME!!! - return null; + return new HashEnum(this); } public Hash() { this(25, 3); } @@ -146,6 +146,31 @@ public class Hash { vals[dest] = v; } + class HashEnum implements java.util.Enumeration { + private final Hash parent; + private int iterator = 0; + private int found = 0; + + public HashEnum (Hash parent) { this.parent = parent; } + + public boolean hasMoreElements() { + return found < parent.usedslots; + } + + public Object nextElement() { + if (!hasMoreElements()) throw new java.util.NoSuchElementException(); + + Object o = null; + while (o == null) { + o = parent.keys1[iterator++]; + } + + if (o == null) throw new IllegalStateException("Didn't find an element, when I should have."); + found++; + + return o; + } + } } -- 1.7.10.4