Class IntArraySet
- All Implemented Interfaces:
IntCollection,IntIterable,IntSet,Serializable,Cloneable,Iterable<Integer>,Collection<Integer>,Set<Integer>
public class IntArraySet extends AbstractIntSet 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 IntArraySet()Creates a new empty array set.IntArraySet(int capacity)Creates a new empty array set of given initial capacity.IntArraySet(int[] a)Creates a new array set using the given backing array.IntArraySet(int[] a, int size)Creates a new array set using the given backing array and the given number of elements of the array.IntArraySet(IntCollection c)Creates a new array set copying the contents of a given collection.IntArraySet(Collection<? extends Integer> c)Creates a new array set copying the contents of a given set. -
Method Summary
Modifier and Type Method Description booleanadd(int k)Ensures that this collection contains the specified element (optional operation).voidclear()IntArraySetclone()Returns a deep copy of this set.booleancontains(int k)Returnstrueif this collection contains the specified element.booleanisEmpty()IntIteratoriterator()Returns a type-specific iterator on the elements of this collection.booleanremove(int k)Removes an element from this set.intsize()Methods inherited from class it.unimi.dsi.fastutil.ints.AbstractIntCollection
add, addAll, contains, containsAll, remove, removeAll, retainAll, toArray, toIntArray, toIntArray, toStringMethods inherited from class java.util.AbstractCollection
addAll, containsAll, removeAll, retainAll, toArray, toArrayMethods inherited from interface it.unimi.dsi.fastutil.ints.IntCollection
addAll, containsAll, removeAll, removeIf, removeIf, retainAll, toArray, toIntArray, toIntArrayMethods inherited from interface java.util.Set
addAll, containsAll, removeAll, retainAll, spliterator, toArray, toArray
-
Constructor Details
-
IntArraySet
public IntArraySet(int[] a)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.
-
IntArraySet
public IntArraySet()Creates a new empty array set. -
IntArraySet
public IntArraySet(int capacity)Creates a new empty array set of given initial capacity.- Parameters:
capacity- the initial capacity.
-
IntArraySet
Creates a new array set copying the contents of a given collection.- Parameters:
c- a collection.
-
IntArraySet
Creates a new array set copying the contents of a given set.- Parameters:
c- a collection.
-
IntArraySet
public IntArraySet(int[] a, int size)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:IntCollectionReturns 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<Integer>- Specified by:
iteratorin interfaceIntCollection- Specified by:
iteratorin interfaceIntIterable- Specified by:
iteratorin interfaceIntSet- Specified by:
iteratorin interfaceIterable<Integer>- Specified by:
iteratorin interfaceSet<Integer>- Specified by:
iteratorin classAbstractIntSet- Returns:
- a type-specific iterator on the elements of this collection.
- See Also:
Iterable.iterator()
-
contains
public boolean contains(int k)Description copied from class:AbstractIntCollectionReturnstrueif this collection contains the specified element.This implementation iterates over the elements in the collection, looking for the specified element.
- Specified by:
containsin interfaceIntCollection- Overrides:
containsin classAbstractIntCollection- See Also:
Collection.contains(Object)
-
size
public int size()- Specified by:
sizein interfaceCollection<Integer>- Specified by:
sizein interfaceSet<Integer>- Specified by:
sizein classAbstractCollection<Integer>
-
remove
public boolean remove(int k)Description copied from class:AbstractIntSetRemoves an element from this set.Note that the corresponding method of a type-specific collection is
rem(). This unfortunate situation is caused by the clash with the similarly named index-based method in theListinterface. Delegates to the type-specificrem()method implemented by type-specific abstractCollectionsuperclass.- Specified by:
removein interfaceIntSet- Overrides:
removein classAbstractIntSet- See Also:
Collection.remove(Object)
-
add
public boolean add(int k)Description copied from class:AbstractIntCollectionEnsures that this collection contains the specified element (optional operation).This implementation always throws an
UnsupportedOperationException.- Specified by:
addin interfaceIntCollection- Overrides:
addin classAbstractIntCollection- See Also:
Collection.add(Object)
-
clear
public void clear()- Specified by:
clearin interfaceCollection<Integer>- Specified by:
clearin interfaceSet<Integer>- Overrides:
clearin classAbstractCollection<Integer>
-
isEmpty
public boolean isEmpty()- Specified by:
isEmptyin interfaceCollection<Integer>- Specified by:
isEmptyin interfaceSet<Integer>- Overrides:
isEmptyin classAbstractCollection<Integer>
-
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.
-