@Test public void testAdd() { assertTrue(set.add(key1)); assertFalse(set.add(key1)); assertEquals(1, set.size()); }
@Override public boolean add(KType key) { if (Intrinsics.isEmpty(key)) { assert Intrinsics.isEmpty(keys[mask + 1]); boolean added = !hasEmptyKey; hasEmptyKey = true; return added; } else { final KType [] keys = Intrinsics.<KType[]> cast(this.keys); final int mask = this.mask; int slot = hashKey(key) & mask; KType existing; while (!Intrinsics.isEmpty(existing = keys[slot])) { if (Intrinsics.equals(this, key, existing)) { return false; } slot = (slot + 1) & mask; } if (assigned == resizeAt) { allocateThenInsertThenRehash(slot, key); } else { keys[slot] = key; } assigned++; return true; } }
KTypeHashSet extends AbstractKTypeCollection<KType> implements /*! #if ($templateonly) !*/ Intrinsics.KeyHasher<KType>, /*! #end !*/
             KTypeLookupContainer<KType>, 
             KTypeSet<KType>,
             Preallocable,
             Cloneable,
             Accountable { @Override public boolean add(KType key) { if (Intrinsics.isEmpty(key)) { assert Intrinsics.isEmpty(keys[mask + 1]); boolean added = !hasEmptyKey; hasEmptyKey = true; return added; } else { final KType [] keys = Intrinsics.<KType[]> cast(this.keys); final int mask = this.mask; int slot = hashKey(key) & mask; KType existing; while (!Intrinsics.isEmpty(existing = keys[slot])) { if (Intrinsics.equals(this, key, existing)) { return false; } slot = (slot + 1) & mask; } if (assigned == resizeAt) { allocateThenInsertThenRehash(slot, key); } else { keys[slot] = key; } assigned++; return true; } } }
KTypeHashSet extends AbstractKTypeCollection<KType> implements /*! #if ($templateonly) !*/ Intrinsics.KeyHasher<KType>, /*! #end !*/
             KTypeLookupContainer<KType>, 
             KTypeSet<KType>,
             Preallocable,
             Cloneable,
             Accountable { @Override public boolean add(KType key) { if (Intrinsics.isEmpty(key)) { assert Intrinsics.isEmpty(keys[mask + 1]); boolean added = !hasEmptyKey; hasEmptyKey = true; return added; } else { final KType [] keys = Intrinsics.<KType[]> cast(this.keys); final int mask = this.mask; int slot = hashKey(key) & mask; KType existing; while (!Intrinsics.isEmpty(existing = keys[slot])) { if (Intrinsics.equals(this, key, existing)) { return false; } slot = (slot + 1) & mask; } if (assigned == resizeAt) { allocateThenInsertThenRehash(slot, key); } else { keys[slot] = key; } assigned++; return true; } } KTypeHashSet();  KTypeHashSet(int expectedElements);  KTypeHashSet(int expectedElements, double loadFactor);  KTypeHashSet(KTypeContainer<? extends KType> container); }
KTypeHashSet extends AbstractKTypeCollection<KType> implements /*! #if ($templateonly) !*/ Intrinsics.KeyHasher<KType>, /*! #end !*/
             KTypeLookupContainer<KType>, 
             KTypeSet<KType>,
             Preallocable,
             Cloneable,
             Accountable { @Override public boolean add(KType key) { if (Intrinsics.isEmpty(key)) { assert Intrinsics.isEmpty(keys[mask + 1]); boolean added = !hasEmptyKey; hasEmptyKey = true; return added; } else { final KType [] keys = Intrinsics.<KType[]> cast(this.keys); final int mask = this.mask; int slot = hashKey(key) & mask; KType existing; while (!Intrinsics.isEmpty(existing = keys[slot])) { if (Intrinsics.equals(this, key, existing)) { return false; } slot = (slot + 1) & mask; } if (assigned == resizeAt) { allocateThenInsertThenRehash(slot, key); } else { keys[slot] = key; } assigned++; return true; } } KTypeHashSet();  KTypeHashSet(int expectedElements);  KTypeHashSet(int expectedElements, double loadFactor);  KTypeHashSet(KTypeContainer<? extends KType> container); @Override boolean add(KType key); @SafeVarargs /* #end */ final int addAll(KType... elements); int addAll(KTypeContainer<? extends KType> container); int addAll(Iterable<? extends KTypeCursor<? extends KType>> iterable); @Override /*! #if ($TemplateOptions.KTypePrimitive) KType [] toArray() { #else !*/ Object[] toArray(); boolean remove(KType key); @Override int removeAll(KType key); int removeAll(KTypeContainer<? super KType> other); @Override int removeAll(KTypePredicate<? super KType> predicate); @Override boolean contains(KType key); @Override void clear(); @Override void release(); @Override boolean isEmpty(); @Override void ensureCapacity(int expectedElements); @Override int size(); @Override int hashCode(); @Override boolean equals(Object obj); @Override KTypeHashSet<KType> clone(); @Override Iterator<KTypeCursor<KType>> iterator(); @Override long ramBytesAllocated(); @Override long ramBytesUsed(); @Override T forEach(T procedure); @Override T forEach(T predicate); @SafeVarargs /* #end */ static KTypeHashSet<KType> from(KType... elements); @Override int hashKey(KType key); int indexOf(KType key); boolean indexExists(int index); KType indexGet(int index); KType indexReplace(int index, KType equivalentKey); void indexInsert(int index, KType key); @Override String visualizeKeyDistribution(int characters); }
KTypeHashSet extends AbstractKTypeCollection<KType> implements /*! #if ($templateonly) !*/ Intrinsics.KeyHasher<KType>, /*! #end !*/
             KTypeLookupContainer<KType>, 
             KTypeSet<KType>,
             Preallocable,
             Cloneable,
             Accountable { @Override public boolean add(KType key) { if (Intrinsics.isEmpty(key)) { assert Intrinsics.isEmpty(keys[mask + 1]); boolean added = !hasEmptyKey; hasEmptyKey = true; return added; } else { final KType [] keys = Intrinsics.<KType[]> cast(this.keys); final int mask = this.mask; int slot = hashKey(key) & mask; KType existing; while (!Intrinsics.isEmpty(existing = keys[slot])) { if (Intrinsics.equals(this, key, existing)) { return false; } slot = (slot + 1) & mask; } if (assigned == resizeAt) { allocateThenInsertThenRehash(slot, key); } else { keys[slot] = key; } assigned++; return true; } } KTypeHashSet();  KTypeHashSet(int expectedElements);  KTypeHashSet(int expectedElements, double loadFactor);  KTypeHashSet(KTypeContainer<? extends KType> container); @Override boolean add(KType key); @SafeVarargs /* #end */ final int addAll(KType... elements); int addAll(KTypeContainer<? extends KType> container); int addAll(Iterable<? extends KTypeCursor<? extends KType>> iterable); @Override /*! #if ($TemplateOptions.KTypePrimitive) KType [] toArray() { #else !*/ Object[] toArray(); boolean remove(KType key); @Override int removeAll(KType key); int removeAll(KTypeContainer<? super KType> other); @Override int removeAll(KTypePredicate<? super KType> predicate); @Override boolean contains(KType key); @Override void clear(); @Override void release(); @Override boolean isEmpty(); @Override void ensureCapacity(int expectedElements); @Override int size(); @Override int hashCode(); @Override boolean equals(Object obj); @Override KTypeHashSet<KType> clone(); @Override Iterator<KTypeCursor<KType>> iterator(); @Override long ramBytesAllocated(); @Override long ramBytesUsed(); @Override T forEach(T procedure); @Override T forEach(T predicate); @SafeVarargs /* #end */ static KTypeHashSet<KType> from(KType... elements); @Override int hashKey(KType key); int indexOf(KType key); boolean indexExists(int index); KType indexGet(int index); KType indexReplace(int index, KType equivalentKey); void indexInsert(int index, KType key); @Override String visualizeKeyDistribution(int characters); public Object [] keys; }