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:
java.lang.Iterable<E>
,java.util.Collection<E>
,java.util.Set<E>
public final class ArraySet<E> extends java.lang.Object implements java.util.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
Constructors Constructor Description ArraySet(int initSize)
Create a set with an initial capacity of initSize.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
add(E arg)
boolean
addAll(java.util.Collection<? extends E> arg)
void
clear()
boolean
contains(java.lang.Object arg)
boolean
containsAll(java.util.Collection<?> arg)
This is an extremely expensive implementation ofSet.containsAll(Collection)
.int
indexOf(java.lang.Object e)
Expose the index in the internal array of a given object.boolean
isEmpty()
java.util.Iterator<E>
iterator()
boolean
remove(java.lang.Object arg)
boolean
removeAll(java.util.Collection<?> arg)
This is an extremely expensive implementation ofSet.removeAll(Collection)
.boolean
retainAll(java.util.Collection<?> arg)
This is an extremely expensive implementation ofSet.retainAll(Collection)
.int
size()
java.lang.Object[]
toArray()
<T> T[]
toArray(T[] arg)
-
-
-
Method Detail
-
indexOf
public int indexOf(java.lang.Object e)
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
public boolean add(E arg)
-
addAll
public boolean addAll(java.util.Collection<? extends E> arg)
-
clear
public void clear()
-
contains
public boolean contains(java.lang.Object arg)
-
containsAll
public boolean containsAll(java.util.Collection<?> arg)
This is an extremely expensive implementation ofSet.containsAll(Collection)
. It is implemented as O(n**2).
-
isEmpty
public boolean isEmpty()
-
iterator
public java.util.Iterator<E> iterator()
-
remove
public boolean remove(java.lang.Object arg)
-
removeAll
public boolean removeAll(java.util.Collection<?> arg)
This is an extremely expensive implementation ofSet.removeAll(Collection)
. It is implemented as O(n**2).
-
retainAll
public boolean retainAll(java.util.Collection<?> arg)
This is an extremely expensive implementation ofSet.retainAll(Collection)
. It is implemented as O(n**2).
-
size
public int size()
-
toArray
public java.lang.Object[] toArray()
-
-