FoldedTreeSet implements SortedSet<E> { public double fillRatio() { if (nodeCount > 1) { return (size + (Node.NODE_SIZE - root.getRightMostNode().size)) / (double) (nodeCount * Node.NODE_SIZE); } return 1.0; } FoldedTreeSet();  FoldedTreeSet(Comparator<E> comparator); @Override Comparator<? super E> comparator(); @Override SortedSet<E> subSet(E fromElement, E toElement); @Override SortedSet<E> headSet(E toElement); @Override SortedSet<E> tailSet(E fromElement); @Override E first(); @Override E last(); @Override int size(); @Override boolean isEmpty(); E get(Object obj, Comparator<?> cmp); E get(E entry); @Override @SuppressWarnings("unchecked") boolean contains(Object obj); @Override Iterator<E> iterator(); @Override Object[] toArray(); @Override @SuppressWarnings("unchecked") T[] toArray(T[] a); E addOrReplace(E entry); @Override boolean add(E entry); boolean addSortedLast(E entry); E removeAndGet(Object obj, Comparator<?> cmp); E removeAndGet(Object obj); boolean remove(Object obj, Comparator<?> cmp); @Override boolean remove(Object obj); @Override boolean containsAll(Collection<?> c); @Override boolean addAll(Collection<? extends E> c); @Override boolean retainAll(Collection<?> c); @Override boolean removeAll(Collection<?> c); @Override void clear(); double fillRatio(); boolean compact(long timeout);  }
@Test public void testFillRatio() { FoldedTreeSet<Integer> set = new FoldedTreeSet<>(); final int size = 1024; for (int i = 1; i <= size; i++) { set.add(i); assertEquals("Iteration: " + i, 1.0, set.fillRatio(), 0.0); } for (int i = 1; i <= size / 2; i++) { set.remove(i * 2); assertEquals("Iteration: " + i, Math.max((size - i) / (double) size, 0.53125), set.fillRatio(), 0.0); } }