From 0a35646ca1120a22aaf4bff56a7cc5f6ac7fc797 Mon Sep 17 00:00:00 2001 From: bdemsky Date: Fri, 3 Nov 2006 02:20:50 +0000 Subject: [PATCH] HashMap --- Robust/src/ClassLibrary/HashMap.java | 5 +++ Robust/src/ClassLibrary/HashMapIterator.java | 46 ++++++++++++++++++++ Robust/src/Main/Main.java | 1 + 3 files changed, 52 insertions(+) create mode 100644 Robust/src/ClassLibrary/HashMapIterator.java diff --git a/Robust/src/ClassLibrary/HashMap.java b/Robust/src/ClassLibrary/HashMap.java index c814f6b5..beb895f6 100644 --- a/Robust/src/ClassLibrary/HashMap.java +++ b/Robust/src/ClassLibrary/HashMap.java @@ -45,6 +45,11 @@ public class HashMap { return numItems; } + /* 0=keys, 1=values */ + public HashMapIterator iterator(int type) { + return new HashMapIterator(this, type); + } + Object remove(Object key) { int bin=key.hashCode()%table.length; HashEntry ptr=table[bin]; diff --git a/Robust/src/ClassLibrary/HashMapIterator.java b/Robust/src/ClassLibrary/HashMapIterator.java new file mode 100644 index 00000000..c0f0eb48 --- /dev/null +++ b/Robust/src/ClassLibrary/HashMapIterator.java @@ -0,0 +1,46 @@ +class HashMapIterator { + HashMap map; + int type; + int bin; + HashEntry he; + + public HashMapIterator(HashMap map, int type) { + this.map=map; + this.type=type; + this.bin=0; + this.he=null; + } + + public boolean hasNext() { + if (he.next!=null) + return true; + int i=bin; + while(map.table[i]==null&&(i