Class ReferenceArraySet<K>
- All Implemented Interfaces:
ObjectIterable<K>,ReferenceCollection<K>,ReferenceSet<K>,Serializable,Cloneable,Iterable<K>,Collection<K>,Set<K>
public class ReferenceArraySet<K> extends AbstractReferenceSet<K> implements Serializable, Cloneable
The main purpose of this implementation is that of wrapping cleanly the brute-force approach to the storage of a very small number of items: just put them into an array and scan linearly to find an item.
- See Also:
- Serialized Form
-
Constructor Summary
Constructors Constructor Description ReferenceArraySet()Creates a new empty array set.ReferenceArraySet(int capacity)Creates a new empty array set of given initial capacity.ReferenceArraySet(ReferenceCollection<K> c)Creates a new array set copying the contents of a given collection.ReferenceArraySet(ReferenceSet<K> c)Creates a new array set copying the contents of a given collection.ReferenceArraySet(Object[] a)Creates a new array set using the given backing array.ReferenceArraySet(Object[] a, int size)Creates a new array set using the given backing array and the given number of elements of the array.ReferenceArraySet(Collection<? extends K> c)Creates a new array set copying the contents of a given set.ReferenceArraySet(Set<? extends K> c)Creates a new array set copying the contents of a given set. -
Method Summary
Modifier and Type Method Description booleanadd(K k)voidclear()ReferenceArraySet<K>clone()Returns a deep copy of this set.booleancontains(Object k)booleanisEmpty()ObjectIterator<K>iterator()Returns a type-specific iterator on the elements of this collection.booleanremove(Object k)intsize()Methods inherited from class it.unimi.dsi.fastutil.objects.AbstractReferenceSet
equals, hashCodeMethods inherited from class it.unimi.dsi.fastutil.objects.AbstractReferenceCollection
toStringMethods inherited from class java.util.AbstractCollection
addAll, containsAll, removeAll, retainAll, toArray, toArrayMethods inherited from interface java.util.Collection
parallelStream, removeIf, stream, toArrayMethods inherited from interface java.util.Set
addAll, containsAll, removeAll, retainAll, spliterator, toArray, toArray
-
Constructor Details
-
ReferenceArraySet
Creates a new array set using the given backing array. The resulting set will have as many elements as the array.It is responsibility of the caller that the elements of
aare distinct.- Parameters:
a- the backing array.
-
ReferenceArraySet
public ReferenceArraySet()Creates a new empty array set. -
ReferenceArraySet
public ReferenceArraySet(int capacity)Creates a new empty array set of given initial capacity.- Parameters:
capacity- the initial capacity.
-
ReferenceArraySet
Creates a new array set copying the contents of a given collection.- Parameters:
c- a collection.
-
ReferenceArraySet
Creates a new array set copying the contents of a given set.- Parameters:
c- a collection.
-
ReferenceArraySet
Creates a new array set copying the contents of a given collection.- Parameters:
c- a collection.
-
ReferenceArraySet
Creates a new array set copying the contents of a given set.- Parameters:
c- a collection.
-
ReferenceArraySet
Creates a new array set using the given backing array and the given number of elements of the array.It is responsibility of the caller that the first
sizeelements ofaare distinct.- Parameters:
a- the backing array.size- the number of valid elements ina.
-
-
Method Details
-
iterator
Description copied from interface:ReferenceCollectionReturns a type-specific iterator on the elements of this collection.Note that this specification strengthens the one given in
Iterable.iterator(), which was already strengthened in the corresponding type-specific class, but was weakened by the fact that this interface extendsCollection.- Specified by:
iteratorin interfaceCollection<K>- Specified by:
iteratorin interfaceIterable<K>- Specified by:
iteratorin interfaceObjectIterable<K>- Specified by:
iteratorin interfaceReferenceCollection<K>- Specified by:
iteratorin interfaceReferenceSet<K>- Specified by:
iteratorin interfaceSet<K>- Specified by:
iteratorin classAbstractReferenceSet<K>- Returns:
- a type-specific iterator on the elements of this collection.
- See Also:
Iterable.iterator()
-
contains
- Specified by:
containsin interfaceCollection<K>- Specified by:
containsin interfaceSet<K>- Overrides:
containsin classAbstractCollection<K>
-
size
public int size()- Specified by:
sizein interfaceCollection<K>- Specified by:
sizein interfaceSet<K>- Specified by:
sizein classAbstractCollection<K>
-
remove
- Specified by:
removein interfaceCollection<K>- Specified by:
removein interfaceSet<K>- Overrides:
removein classAbstractCollection<K>
-
add
- Specified by:
addin interfaceCollection<K>- Specified by:
addin interfaceSet<K>- Overrides:
addin classAbstractCollection<K>
-
clear
public void clear()- Specified by:
clearin interfaceCollection<K>- Specified by:
clearin interfaceSet<K>- Overrides:
clearin classAbstractCollection<K>
-
isEmpty
public boolean isEmpty()- Specified by:
isEmptyin interfaceCollection<K>- Specified by:
isEmptyin interfaceSet<K>- Overrides:
isEmptyin classAbstractCollection<K>
-
clone
Returns a deep copy of this set.This method performs a deep copy of this array set; the data stored in the set, however, is not cloned. Note that this makes a difference only for object keys.
- Returns:
- a deep copy of this set.
-