private void growAndRehash() { if (keys.length * loadFactor >= RandomUtils.MAX_INT_SMALLER_TWIN_PRIME) { throw new IllegalStateException("Can't grow any more"); } rehash(RandomUtils.nextTwinPrime((int) (loadFactor * keys.length))); }
private void growAndRehash() { if (keys.length * loadFactor >= RandomUtils.MAX_INT_SMALLER_TWIN_PRIME) { throw new IllegalStateException("Can't grow any more"); } rehash(RandomUtils.nextTwinPrime((int) (loadFactor * keys.length))); }
private void growAndRehash() { if (keys.length * loadFactor >= RandomUtils.MAX_INT_SMALLER_TWIN_PRIME) { throw new IllegalStateException("Can't grow any more"); } rehash(RandomUtils.nextTwinPrime((int) (loadFactor * keys.length))); }
public void rehash() { rehash(RandomUtils.nextTwinPrime((int) (loadFactor * numEntries))); }
public void rehash() { rehash(RandomUtils.nextTwinPrime((int) (loadFactor * numEntries))); }
public void rehash() { rehash(RandomUtils.nextTwinPrime((int) (loadFactor * numEntries))); }
public static FastIDSet[] parseMenWomen(File genderFile) throws IOException { FastIDSet men = new FastIDSet(50000); FastIDSet women = new FastIDSet(50000); for (String line : new FileLineIterable(genderFile)) { int comma = line.indexOf(','); char gender = line.charAt(comma + 1); if (gender == 'U') { continue; } long profileID = Long.parseLong(line.substring(0, comma)); if (gender == 'M') { men.add(profileID); } else { women.add(profileID); } } men.rehash(); women.rehash(); return new FastIDSet[] { men, women }; }
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; }
@Test public void testRehash() { FastIDSet set = buildTestFastSet(); set.remove(1); set.rehash(); assertFalse(set.contains(1)); }