Class IntArraySet
- java.lang.Object
-
- java.util.AbstractCollection<java.lang.Integer>
-
- it.unimi.dsi.fastutil.ints.AbstractIntCollection
-
- it.unimi.dsi.fastutil.ints.AbstractIntSet
-
- it.unimi.dsi.fastutil.ints.IntArraySet
-
- All Implemented Interfaces:
IntCollection,IntIterable,IntSet,java.io.Serializable,java.lang.Cloneable,java.lang.Iterable<java.lang.Integer>,java.util.Collection<java.lang.Integer>,java.util.Set<java.lang.Integer>
public class IntArraySet extends AbstractIntSet implements java.io.Serializable, java.lang.Cloneable
A simple, brute-force implementation of a set based on a backing array.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(java.util.Collection<? extends java.lang.Integer> c)Creates a new array set copying the contents of a given set.
-
Method Summary
All Methods Instance Methods Concrete Methods 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.AbstractIntSet
equals, hashCode, rem
-
Methods inherited from class it.unimi.dsi.fastutil.ints.AbstractIntCollection
add, addAll, contains, containsAll, remove, removeAll, retainAll, toArray, toIntArray, toIntArray, toString
-
Methods inherited from class java.util.AbstractCollection
addAll, containsAll, removeAll, retainAll, toArray, toArray
-
Methods inherited from interface it.unimi.dsi.fastutil.ints.IntCollection
addAll, containsAll, removeAll, removeIf, removeIf, retainAll, toArray, toIntArray, toIntArray
-
Methods inherited from interface it.unimi.dsi.fastutil.ints.IntIterable
forEach, forEach
-
-
-
-
Constructor Detail
-
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
public IntArraySet(IntCollection c)
Creates a new array set copying the contents of a given collection.- Parameters:
c- a collection.
-
IntArraySet
public IntArraySet(java.util.Collection<? extends java.lang.Integer> c)
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 Detail
-
iterator
public IntIterator 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 interfacejava.util.Collection<java.lang.Integer>- Specified by:
iteratorin interfaceIntCollection- Specified by:
iteratorin interfaceIntIterable- Specified by:
iteratorin interfaceIntSet- Specified by:
iteratorin interfacejava.lang.Iterable<java.lang.Integer>- Specified by:
iteratorin interfacejava.util.Set<java.lang.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 interfacejava.util.Collection<java.lang.Integer>- Specified by:
sizein interfacejava.util.Set<java.lang.Integer>- Specified by:
sizein classjava.util.AbstractCollection<java.lang.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 interfacejava.util.Collection<java.lang.Integer>- Specified by:
clearin interfacejava.util.Set<java.lang.Integer>- Overrides:
clearin classjava.util.AbstractCollection<java.lang.Integer>
-
isEmpty
public boolean isEmpty()
- Specified by:
isEmptyin interfacejava.util.Collection<java.lang.Integer>- Specified by:
isEmptyin interfacejava.util.Set<java.lang.Integer>- Overrides:
isEmptyin classjava.util.AbstractCollection<java.lang.Integer>
-
clone
public IntArraySet 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.
-
-