@Test public void testAdd() { CompactHashSet<String> set = new CompactHashSet<>(TRANSLATOR); assertTrue(set.add("a")); assertTrue(set.add("b")); assertTrue(set.add("c")); assertFalse(set.add("a")); assertTrue(set.add("d")); assertFalse(set.add("d")); set.checkStructure(); assertTrue(set.add("e")); assertFalse(set.add("a")); assertTrue(set.add("f")); assertTrue(set.add("g")); assertFalse(set.add("b")); assertTrue(set.add("h")); assertFalse(set.add("e")); set.checkStructure(); }
public boolean add(E obj) { Objects.requireNonNull(obj); int index = probe(obj); if (index >= 0) return false; if (size == MAX_TABLE_LEN - 1) throw new IllegalStateException("Maximum size reached"); version++; index = ~index; if (table[index] != TOMBSTONE) filled++; table[index] = translator.serialize(obj); incrementSize(); if (filled == MAX_TABLE_LEN) resize(table.length); return true; }
CompactHashSet extends AbstractSet<E> { public boolean add(E obj) { Objects.requireNonNull(obj); int index = probe(obj); if (index >= 0) return false; if (size == MAX_TABLE_LEN - 1) throw new IllegalStateException("Maximum size reached"); version++; index = ~index; if (table[index] != TOMBSTONE) filled++; table[index] = translator.serialize(obj); incrementSize(); if (filled == MAX_TABLE_LEN) resize(table.length); return true; } }
CompactHashSet extends AbstractSet<E> { public boolean add(E obj) { Objects.requireNonNull(obj); int index = probe(obj); if (index >= 0) return false; if (size == MAX_TABLE_LEN - 1) throw new IllegalStateException("Maximum size reached"); version++; index = ~index; if (table[index] != TOMBSTONE) filled++; table[index] = translator.serialize(obj); incrementSize(); if (filled == MAX_TABLE_LEN) resize(table.length); return true; } CompactHashSet(CompactSetTranslator<E> trans); }
CompactHashSet extends AbstractSet<E> { public boolean add(E obj) { Objects.requireNonNull(obj); int index = probe(obj); if (index >= 0) return false; if (size == MAX_TABLE_LEN - 1) throw new IllegalStateException("Maximum size reached"); version++; index = ~index; if (table[index] != TOMBSTONE) filled++; table[index] = translator.serialize(obj); incrementSize(); if (filled == MAX_TABLE_LEN) resize(table.length); return true; } CompactHashSet(CompactSetTranslator<E> trans); void clear(); int size(); @SuppressWarnings("unchecked") boolean contains(Object obj); boolean add(E obj); boolean remove(Object obj); Iterator<E> iterator(); }
CompactHashSet extends AbstractSet<E> { public boolean add(E obj) { Objects.requireNonNull(obj); int index = probe(obj); if (index >= 0) return false; if (size == MAX_TABLE_LEN - 1) throw new IllegalStateException("Maximum size reached"); version++; index = ~index; if (table[index] != TOMBSTONE) filled++; table[index] = translator.serialize(obj); incrementSize(); if (filled == MAX_TABLE_LEN) resize(table.length); return true; } CompactHashSet(CompactSetTranslator<E> trans); void clear(); int size(); @SuppressWarnings("unchecked") boolean contains(Object obj); boolean add(E obj); boolean remove(Object obj); Iterator<E> iterator();  }