public boolean add(long key) { Preconditions.checkArgument(key != NULL && key != REMOVED); // If less than half the slots are open, let's clear it up if (numSlotsUsed * loadFactor >= keys.length) { // If over half the slots used are actual entries, let's grow if (numEntries * loadFactor >= numSlotsUsed) { growAndRehash(); } else { // Otherwise just rehash to clear REMOVED entries and don't grow rehash(); } } // Here we may later consider implementing Brent's variation described on page 532 int index = findForAdd(key); long keyIndex = keys[index]; if (keyIndex != key) { keys[index] = key; numEntries++; if (keyIndex == NULL) { numSlotsUsed++; } return true; } return false; }
public boolean add(long key) { Preconditions.checkArgument(key != NULL && key != REMOVED); // If less than half the slots are open, let's clear it up if (numSlotsUsed * loadFactor >= keys.length) { // If over half the slots used are actual entries, let's grow if (numEntries * loadFactor >= numSlotsUsed) { growAndRehash(); } else { // Otherwise just rehash to clear REMOVED entries and don't grow rehash(); } } // Here we may later consider implementing Brent's variation described on page 532 int index = findForAdd(key); long keyIndex = keys[index]; if (keyIndex != key) { keys[index] = key; numEntries++; if (keyIndex == NULL) { numSlotsUsed++; } return true; } return false; }
public boolean add(long key) { Preconditions.checkArgument(key != NULL && key != REMOVED); // If less than half the slots are open, let's clear it up if (numSlotsUsed * loadFactor >= keys.length) { // If over half the slots used are actual entries, let's grow if (numEntries * loadFactor >= numSlotsUsed) { growAndRehash(); } else { // Otherwise just rehash to clear REMOVED entries and don't grow rehash(); } } // Here we may later consider implementing Brent's variation described on page 532 int index = findForAdd(key); long keyIndex = keys[index]; if (keyIndex != key) { keys[index] = key; numEntries++; if (keyIndex == NULL) { numSlotsUsed++; } return true; } return false; }