Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public boolean checkAndMove(Entry<K, V> entry) {
- // calculate hashValue for key
- int hashValue = hashValue(entry.getKey());
- // index of this entry is equal to hash value of key then return true
- if (bucket[hashValue] == entry)
- return true;
- // save old entry stored in index[hashValue]
- Entry<K, V> entryToMove = bucket[hashValue];
- // this will be equal to index in bucket of entry in input
- int index = hashValue;
- // search entry in bucket
- while (bucket[index] != null || bucket[index] == AVAILABLE) {
- // linear probing
- index = (index + 1) % capacity;
- // this is to avoid an infinite loop or an IndexOutBoundException
- if (index >= bucket.length)
- index = 0;
- }
- // swap elements
- bucket[hashValue] = entry;
- bucket[index] = entryToMove;
- return false;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement