10 public HashMap(int initialCapacity) {
11 init(initialCapacity, 0.75f);
14 public HashMap(int initialCapacity, float loadFactor) {
15 init(initialCapacity, loadFactor);
18 private void init(int initialCapacity, float loadFactor) {
19 table=new HashEntry[initialCapacity];
20 this.loadFactor=loadFactor;
24 private static int hash(Object o, int length) {
27 int value=o.hashCode()%length;
34 int newCapacity=2*table.length+1;
35 HashEntry[] oldtable=table;
36 this.table=new HashEntry[newCapacity];
38 for(int i=0; i<oldtable.length; i++) {
39 HashEntry e=oldtable[i];
41 HashEntry next=e.next;
42 int bin=hash(e.key, newCapacity);
50 public boolean isEmpty() {
58 /* 0=keys, 1=values */
59 public HashMapIterator iterator(int type) {
60 return new HashMapIterator(this, type);
63 Object remove(Object key) {
64 int bin=hash(key, table.length);
65 HashEntry ptr=table[bin];
67 if (ptr.key.equals(key)) {
72 while(ptr.next!=null) {
73 if (ptr.next.key.equals(key)) {
74 Object oldvalue=ptr.value;
75 ptr.next=ptr.next.next;
85 Object get(Object key) {
86 int bin=hash(key, table.length);
87 HashEntry ptr=table[bin];
89 if (ptr.key.equals(key)) {
97 boolean containsKey(Object key) {
98 int bin=hash(key, table.length);
99 HashEntry ptr=table[bin];
101 if (ptr.key.equals(key)) {
109 Object put(Object key, Object value) {
111 if (numItems>(loadFactor*table.length)) {
115 int bin=hash(key, table.length);
116 HashEntry ptr=table[bin];
118 if (ptr.key.equals(key)) {
119 Object oldvalue=ptr.value;
125 HashEntry he=new HashEntry();