コード例 #1
0
 private void rehash(BucketEntry[] newTable) {
   int oldsize = _buckets.length;
   int newsize = newTable.length;
   for (int i = 0; i < oldsize; i++) {
     BucketEntry oldEntry = _buckets[i];
     while (oldEntry != null) {
       BucketEntry e = oldEntry;
       oldEntry = oldEntry.next;
       int bucket = indexFor(e.key, newsize);
       e.next = newTable[bucket];
       newTable[bucket] = e;
     }
   }
 }
コード例 #2
0
 public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
   this.key = in.readInt();
   this.value = in.readLong();
   boolean hasNext = in.readBoolean();
   BucketEntry cur = this;
   while (hasNext) {
     int k = in.readInt();
     long v = in.readLong();
     BucketEntry n = new BucketEntry(k, v);
     cur.next = n;
     cur = n;
     hasNext = in.readBoolean();
   }
 }
コード例 #3
0
 public long remove(int key) {
   final int bucket = indexFor(key, _buckets.length);
   // find an entry
   BucketEntry e, prev = null;
   for (e = _buckets[bucket]; e != null; prev = e, e = e.next) {
     if (key == e.key) {
       if (prev != null) {
         prev.next = e.next;
       } else {
         _buckets[bucket] = e.next;
       }
       --_size;
       e.recordRemoval(this);
       return e.value;
     }
   }
   return -1;
 }