Package com.yahoo.collections
Class ArraySet<E>
java.lang.Object
com.yahoo.collections.ArraySet<E>
- Type Parameters:
E
- the type contained in the Set
- All Implemented Interfaces:
Iterable<E>
,Collection<E>
,Set<E>
A Set implementation with low allocation cost. It should only be used for
small number of objects, as it is implemented as scanning an ArrayList for
equality 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, baldersheim
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionboolean
boolean
addAll
(Collection<? extends E> arg) void
clear()
boolean
boolean
containsAll
(Collection<?> arg) This is an extremely expensive implementation ofSet.containsAll(Collection)
.int
Expose the index in the internal array of a given object.boolean
isEmpty()
iterator()
boolean
boolean
removeAll
(Collection<?> arg) This is an extremely expensive implementation ofSet.removeAll(Collection)
.boolean
retainAll
(Collection<?> arg) This is an extremely expensive implementation ofSet.retainAll(Collection)
.int
size()
Object[]
toArray()
<T> T[]
toArray
(T[] arg) Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface java.util.Collection
parallelStream, removeIf, stream, toArray
Methods inherited from interface java.util.Set
equals, hashCode, spliterator
-
Constructor Details
-
ArraySet
public ArraySet(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
-
-
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:
containsAll
in interfaceCollection<E>
- Specified by:
containsAll
in 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)
-