Class DoubleArraySet
- All Implemented Interfaces:
DoubleCollection,DoubleIterable,DoubleSet,Serializable,Cloneable,Iterable<Double>,Collection<Double>,Set<Double>
public class DoubleArraySet extends AbstractDoubleSet 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 DoubleArraySet()Creates a new empty array set.DoubleArraySet(double[] a)Creates a new array set using the given backing array.DoubleArraySet(double[] a, int size)Creates a new array set using the given backing array and the given number of elements of the array.DoubleArraySet(int capacity)Creates a new empty array set of given initial capacity.DoubleArraySet(DoubleCollection c)Creates a new array set copying the contents of a given collection.DoubleArraySet(Collection<? extends Double> c)Creates a new array set copying the contents of a given set. -
Method Summary
Modifier and Type Method Description booleanadd(double k)Ensures that this collection contains the specified element (optional operation).voidclear()DoubleArraySetclone()Returns a deep copy of this set.booleancontains(double k)Returnstrueif this collection contains the specified element.booleanisEmpty()DoubleIteratoriterator()Returns a type-specific iterator on the elements of this collection.booleanremove(double k)Removes an element from this set.intsize()Methods inherited from class it.unimi.dsi.fastutil.doubles.AbstractDoubleCollection
add, addAll, contains, containsAll, remove, removeAll, retainAll, toArray, toDoubleArray, toDoubleArray, toStringMethods inherited from class java.util.AbstractCollection
addAll, containsAll, removeAll, retainAll, toArray, toArrayMethods inherited from interface it.unimi.dsi.fastutil.doubles.DoubleCollection
addAll, containsAll, removeAll, removeIf, removeIf, retainAll, toArray, toDoubleArray, toDoubleArrayMethods inherited from interface java.util.Set
addAll, containsAll, removeAll, retainAll, spliterator, toArray, toArray
-
Constructor Details
-
DoubleArraySet
public DoubleArraySet(double[] 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.
-
DoubleArraySet
public DoubleArraySet()Creates a new empty array set. -
DoubleArraySet
public DoubleArraySet(int capacity)Creates a new empty array set of given initial capacity.- Parameters:
capacity- the initial capacity.
-
DoubleArraySet
Creates a new array set copying the contents of a given collection.- Parameters:
c- a collection.
-
DoubleArraySet
Creates a new array set copying the contents of a given set.- Parameters:
c- a collection.
-
DoubleArraySet
public DoubleArraySet(double[] 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:DoubleCollectionReturns 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<Double>- Specified by:
iteratorin interfaceDoubleCollection- Specified by:
iteratorin interfaceDoubleIterable- Specified by:
iteratorin interfaceDoubleSet- Specified by:
iteratorin interfaceIterable<Double>- Specified by:
iteratorin interfaceSet<Double>- Specified by:
iteratorin classAbstractDoubleSet- Returns:
- a type-specific iterator on the elements of this collection.
- See Also:
Iterable.iterator()
-
contains
public boolean contains(double k)Description copied from class:AbstractDoubleCollectionReturnstrueif this collection contains the specified element.This implementation iterates over the elements in the collection, looking for the specified element.
- Specified by:
containsin interfaceDoubleCollection- Overrides:
containsin classAbstractDoubleCollection- See Also:
Collection.contains(Object)
-
size
public int size()- Specified by:
sizein interfaceCollection<Double>- Specified by:
sizein interfaceSet<Double>- Specified by:
sizein classAbstractCollection<Double>
-
remove
public boolean remove(double k)Description copied from class:AbstractDoubleSetRemoves 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 interfaceDoubleSet- Overrides:
removein classAbstractDoubleSet- See Also:
Collection.remove(Object)
-
add
public boolean add(double k)Description copied from class:AbstractDoubleCollectionEnsures that this collection contains the specified element (optional operation).This implementation always throws an
UnsupportedOperationException.- Specified by:
addin interfaceDoubleCollection- Overrides:
addin classAbstractDoubleCollection- See Also:
Collection.add(Object)
-
clear
public void clear()- Specified by:
clearin interfaceCollection<Double>- Specified by:
clearin interfaceSet<Double>- Overrides:
clearin classAbstractCollection<Double>
-
isEmpty
public boolean isEmpty()- Specified by:
isEmptyin interfaceCollection<Double>- Specified by:
isEmptyin interfaceSet<Double>- Overrides:
isEmptyin classAbstractCollection<Double>
-
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.
-