public long get(int key) { int bucket = indexFor(key, _buckets.length); for (BucketEntry e = _buckets[bucket]; e != null; e = e.next) { if (key == e.key) { e.recordAccess(this); return e.value; } } return -1; }
/** * Put an entry for the given key number. If one already exists, old value is replaced. * * @return old value for the given key. if not found, return -1. */ public long put(int key, long value) { assert (value != -1L); int bucket = indexFor(key, _buckets.length); // find an entry BucketEntry e; for (e = _buckets[bucket]; e != null; e = e.next) { if (key == e.key) { long replaced = e.value; e.value = value; e.recordAccess(this); return replaced; // found } } // if not found, create a new entry. addEntry(bucket, key, value, _buckets[bucket]); return -1L; }