private Entry getEntry(Long key) { int hash = (key == null) ? 0 : hash(key); FileBucket fb = table[indexFor(hash, table.length)]; for (Entry e = fb.getEntry(); e != null; e = e.next) { Long k; if (e.getKey().equals(key)) return e; } return null; }
@Override public boolean containsValue(String value) { if (value == null) return false; for (FileBucket fb : table) { for (Entry e = fb.getEntry(); e != null; e = e.next) if (e.getValue().equals(value)) { return true; } } return false; }
@Override public Long getKey(String value) { if (value == null) return 0L; for (FileBucket fb : table) for (Entry e = fb.getEntry(); e != null; e = e.next) { if (e.getValue().equals(value)) { return e.getKey(); } } return null; }
private void transfer(FileBucket[] newTable) { int newCapacity = newTable.length; for (FileBucket fb : table) { Entry e = fb.getEntry(); while (null != e) { Entry next = e.next; int i = indexFor(e.hash, newCapacity); e.next = newTable[i].getEntry(); newTable[i].putEntry(e); e = next; } } }
@Override public void put(Long key, String value) { if (key == null) return; int hash = hash(key); int i = indexFor(hash, table.length); FileBucket fb = table[i]; for (Entry e = fb.getEntry(); e != null; e = e.next) { Long k; if (e.hash == hash && ((k = e.key) == key || key.equals(k))) { e.value = value; return; } } addEntry(hash, key, value, i); }
private void createEntry(int hash, Long key, String value, int bucketIndex) { FileBucket fb = table[bucketIndex]; Entry e = fb.getEntry(); fb.putEntry(new Entry(hash, key, value, e)); size++; }