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 int hash(Object o) {
27 int value=o.hashCode()%table.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;
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) {
65 HashEntry ptr=table[bin];
66 if (ptr.key.equals(key)) {
71 while(ptr.next!=null) {
72 if (ptr.next.key.equals(key)) {
73 Object oldvalue=ptr.value;
74 ptr.next=ptr.next.next;
83 Object get(Object key) {
85 HashEntry ptr=table[bin];
87 if (ptr.key.equals(key)) {
95 boolean containsKey(Object key) {
97 HashEntry ptr=table[bin];
99 if (ptr.key.equals(key)) {
107 Object put(Object key, Object value) {
109 if (numItems>(loadFactor*table.length)) {
114 HashEntry ptr=table[bin];
116 if (ptr.key.equals(key)) {
117 Object oldvalue=ptr.value;
123 HashEntry he=new HashEntry();