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];
--- /dev/null
+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<map.table.length))
+ i++;
+ return (i<map.table.length);
+ }
+
+ public Object next() {
+ if (he.next!=null) {
+ he=he.next;
+ Object o;
+ if (type==0)
+ o=he.key;
+ else
+ o=he.value;
+ return o;
+ }
+ while((map.table[bin]==null)&&(bin<map.table.length))
+ bin++;
+ if (bin<map.table.length) {
+ he=map.table[bin];
+ Object o;
+ if (type==0)
+ o=he.key;
+ else
+ o=he.value;
+ return o;
+ } else System.error();
+ }
+
+}
readSourceFile(state, ClassLibraryPrefix+"System.java");
readSourceFile(state, ClassLibraryPrefix+"String.java");
readSourceFile(state, ClassLibraryPrefix+"HashMap.java");
+ readSourceFile(state, ClassLibraryPrefix+"HashMapIterator.java");
readSourceFile(state, ClassLibraryPrefix+"HashEntry.java");
readSourceFile(state, ClassLibraryPrefix+"Integer.java");
readSourceFile(state, ClassLibraryPrefix+"StringBuffer.java");