1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
| public class Hashtable<K, V> extends Dictionary<K, V> implements Map<K, V>, Cloneable, Serializable {
private static class Entry<K, V> implements java.util.Map.Entry<K, V> { }
private transient Hashtable.Entry<?, ?>[] table; private transient int count; private int threshold; private float loadFactor; private transient int modCount = 0;
private void addEntry(int hash, K key, V value, int entry) { this.modCount++; Hashtable.Entry[] tab = this.table;
if (this.count >= this.threshold) { this.rehash(); tab = this.table; hash = key.hashCode(); entry = (hash & 0x7FFFFFFF) % tab.length; }
Hashtable.Entry<K, V> e = (Entry<K, V>) tab[index]; tab[entry] = new Hashtable.Entry(hash, key, value, e); this.count++; }
public synchronized V put(K key, V value) { if (value == null) { throw new NullPointerException(); } else {
Hashtable.Entry<?, ?>[] tab = this.table; int hash = key.hashCode(); int index = (hash & 0x7FFFFFFF) % tab.length; Hashtable.Entry<K, V> e = (Entry<K, V>) tab[index]; for (; e != null; e = e.next) { if (e.hash == hash && e.key.equals(key)) { V old = e.value; e.value = value; return old; } }
this.addEntry(hash, key, value, index); return null; } }
public synchronized V get(Object key) { Hashtable.Entry<?, ?>[] tab = this.table; int hash = key.hashCode(); int index = (hash & 0x7FFFFFFF) % tab.length; Hashtable.Entry<?, ?> e = tab[index]; for (; e != null; e = e.next) { if (e.hash == hash && e.key.equals(key)) { return (V) e.value; } } return null; } }
|