CompactHashSet extends java.util.AbstractSet<E> { @Override public boolean add(Object o) { if (o == null) o = nullObject; int hash = o.hashCode(); int index = (hash & 0x7FFFFFFF) % objects.length; int offset = 1; int deletedix = -1; while(objects[index] != null && !(objects[index].hashCode() == hash && objects[index].equals(o))) { if (objects[index] == deletedObject) deletedix = index; index = ((index + offset) & 0x7FFFFFFF) % objects.length; offset = offset*2 + 1; if (offset == -1) offset = 2; } if (objects[index] == null) { if (deletedix != -1) index = deletedix; else freecells--; modCount++; elements++; objects[index] = (E) o; if (1 - (freecells / (double) objects.length) > LOAD_FACTOR) rehash(); return true; } else return false; } CompactHashSet();  CompactHashSet(int size);  CompactHashSet(Collection<E> c); @Override Iterator<E> iterator(); @Override int size(); @Override boolean isEmpty(); @Override boolean contains(Object o); @Override boolean add(Object o); @Override boolean remove(Object o); @Override void clear(); @Override Object[] toArray(); @Override T[] toArray(T[] a); void dump();  }
@Test public void testAdd() { set.add("hei"); Assert.assertTrue("set with 1 element thinks it's empty", !set.isEmpty()); Assert.assertTrue("set size != 1", set.size() == 1); Assert.assertTrue("add thinks object just added is not contained", !set.add("hei")); Assert.assertTrue("set with 1 element thinks it's empty", !set.isEmpty()); Assert.assertTrue("set size != 1", set.size() == 1); Assert.assertTrue("set thinks new object is already contained", set.add("hei2")); Assert.assertTrue("set size != 2", set.size() == 2); Assert.assertTrue("add thinks object just added is not contained", !set.add("hei")); Assert.assertTrue("add thinks object just added is not contained", !set.add("hei2")); }