Package com.yahoo.collections
Class TinyIdentitySet<E>
java.lang.Object
com.yahoo.collections.TinyIdentitySet<E>
- Type Parameters:
E- the type contained in the Set
- All Implemented Interfaces:
Iterable<E>,Collection<E>,Set<E>
A Set implementation which only considers object identity. It should only be
used for small number of objects, as it is implemented as scanning an
ArrayList for identity matches. In other words: Performance will only be
acceptable for small sets.
The rationale for this class is the high cost of the object identifier used
in IdentityHashMap, where the key set is often used as an identity set.
- Author:
- Steinar Knutsen
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionTinyIdentitySet(int initSize) Create a set with an initial capacity of initSize. -
Method Summary
Modifier and TypeMethodDescriptionbooleanbooleanaddAll(Collection<? extends E> arg) voidclear()booleanbooleancontainsAll(Collection<?> arg) This is an extremely expensive implementation ofSet.containsAll(Collection).intExpose the index in the internal array of a given object. -1 is returned if the object is not present in the internal array.booleanisEmpty()iterator()booleanbooleanremoveAll(Collection<?> arg) This is an extremely expensive implementation ofSet.removeAll(Collection).booleanretainAll(Collection<?> arg) This is an extremely expensive implementation ofSet.retainAll(Collection).intsize()Object[]toArray()<T> T[]toArray(T[] arg) Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface java.util.Collection
parallelStream, removeIf, stream, toArrayMethods inherited from interface java.util.Set
equals, hashCode, spliterator
-
Constructor Details
-
TinyIdentitySet
public TinyIdentitySet(int initSize) Create a set with an initial capacity of initSize. The internal array will grow automatically with a linear growth rate if more elements than initSize are added.- Parameters:
initSize- initial size of internal element array
-
TinyIdentitySet
public TinyIdentitySet()
-
-
Method Details
-
indexOf
Expose the index in the internal array of a given object. -1 is returned if the object is not present in the internal array.- Parameters:
e- an object to check whether exists in this set- Returns:
- the index of the argument e in the internal array, or -1 if the object is not present
-
add
-
addAll
-
clear
public void clear() -
contains
-
containsAll
This is an extremely expensive implementation ofSet.containsAll(Collection). It is implemented as O(n**2).- Specified by:
containsAllin interfaceCollection<E>- Specified by:
containsAllin interfaceSet<E>
-
isEmpty
public boolean isEmpty() -
iterator
-
remove
-
removeAll
This is an extremely expensive implementation ofSet.removeAll(Collection). It is implemented as O(n**2). -
retainAll
This is an extremely expensive implementation ofSet.retainAll(Collection). It is implemented as O(n**2). -
size
public int size() -
toArray
-
toArray
public <T> T[] toArray(T[] arg)
-