Package me.ahoo.cosid.sharding
Class ExactCollection<E>
java.lang.Object
java.util.AbstractCollection<E>
me.ahoo.cosid.sharding.ExactCollection<E>
- All Implemented Interfaces:
Iterable<E>,Collection<E>,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.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidbooleanaddAll(Collection<? extends E> c) voidclear()booleanstatic <E> ExactCollection<E> empty()booleanget(int index) inthashCode()intiterator()booleanbooleanremoveAll(Collection<?> c) booleanretainAll(Collection<?> c) intsize()Object[]toArray()<T> T[]toArray(T[] a) Methods inherited from class java.util.AbstractCollection
add, containsAll, isEmpty, toStringMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.util.Collection
parallelStream, removeIf, spliterator, stream, toArray
-
Constructor Details
-
ExactCollection
public ExactCollection(int size) -
ExactCollection
-
-
Method Details
-
empty
-
size
public int size()- Specified by:
sizein interfaceCollection<E>- Specified by:
sizein classAbstractCollection<E>
-
get
-
add
-
indexOf
-
contains
- Specified by:
containsin interfaceCollection<E>- Overrides:
containsin classAbstractCollection<E>
-
iterator
- Specified by:
iteratorin interfaceCollection<E>- Specified by:
iteratorin interfaceIterable<E>- Specified by:
iteratorin classAbstractCollection<E>
-
toArray
- Specified by:
toArrayin interfaceCollection<E>- Overrides:
toArrayin classAbstractCollection<E>
-
toArray
public <T> T[] toArray(T[] a) - Specified by:
toArrayin interfaceCollection<E>- Overrides:
toArrayin classAbstractCollection<E>
-
remove
- Specified by:
removein interfaceCollection<E>- Overrides:
removein classAbstractCollection<E>
-
addAll
- Specified by:
addAllin interfaceCollection<E>- Overrides:
addAllin classAbstractCollection<E>
-
removeAll
- Specified by:
removeAllin interfaceCollection<E>- Overrides:
removeAllin classAbstractCollection<E>
-
retainAll
- Specified by:
retainAllin interfaceCollection<E>- Overrides:
retainAllin classAbstractCollection<E>
-
hashCode
public int hashCode()- Specified by:
hashCodein interfaceCollection<E>- Overrides:
hashCodein classObject
-
equals
- Specified by:
equalsin interfaceCollection<E>- Overrides:
equalsin classObject
-
clear
public void clear()- Specified by:
clearin interfaceCollection<E>- Overrides:
clearin classAbstractCollection<E>
-