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;
25 int newCapacity=2*table.length+1;
26 HashEntry[] newtable=new HashEntry[newCapacity];
27 for(int i=0;i<table.length;i++) {
30 HashEntry next=e.next;
31 int bin=e.key.hashCode()%newCapacity;
40 public boolean isEmpty() {
48 /* 0=keys, 1=values */
49 public HashMapIterator iterator(int type) {
50 return new HashMapIterator(this, type);
53 Object remove(Object key) {
54 int bin=key.hashCode()%table.length;
55 HashEntry ptr=table[bin];
61 while(ptr.next!=null) {
62 if (ptr.next.key==key) {
63 Object oldvalue=ptr.value;
64 ptr.next=ptr.next.next;
72 Object get(Object key) {
73 int bin=key.hashCode()%table.length;
74 HashEntry ptr=table[bin];
83 boolean containsKey(Object key) {
84 int bin=key.hashCode()%table.length;
85 HashEntry ptr=table[bin];
94 Object put(Object key, Object value) {
96 if (numItems>(loadFactor*table.length)) {
100 int bin=key.hashCode()%table.length;
101 HashEntry ptr=table[bin];
104 Object oldvalue=ptr.value;
109 HashEntry he=new HashEntry();