Class ExactCollection<E>

java.lang.Object
java.util.AbstractCollection<E>
me.ahoo.cosid.sharding.ExactCollection<E>
All Implemented Interfaces:
Iterable<E>, Collection<E>, RandomAccess

public class ExactCollection<E> extends AbstractCollection<E> implements RandomAccess
Exact-size collection optimized for known node counts.

Used by Interval and Mod algorithms where the number of nodes is known in advance, avoiding the memory overhead of HashSet and unnecessary array expansion.

The algorithm fills the slots by index (add(int, Object)); through the Collection interface the collection is read-only. Every mutator (add, remove, clear, the bulk ones and the iterator's remove) throws UnsupportedOperationException: the collections returned by Sharding are often the algorithm's own nodes (its effective nodes, a cached range) and are shared by every caller, so a caller that removed a node would change the routing of every later call.