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(DoubleSet 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.DoubleArraySet(Set<? extends Double> c)
Creates a new array set copying the contents of a given set. -
Method Summary
Modifier and Type Method Description boolean
add(double k)
Ensures that this collection contains the specified element (optional operation).void
clear()
DoubleArraySet
clone()
Returns a deep copy of this set.boolean
contains(double k)
Returnstrue
if this collection contains the specified element.boolean
isEmpty()
DoubleIterator
iterator()
Returns a type-specific iterator on the elements of this collection.boolean
remove(double k)
Removes an element from this set.int
size()
Methods inherited from class it.unimi.dsi.fastutil.doubles.AbstractDoubleCollection
add, addAll, contains, containsAll, remove, removeAll, retainAll, toArray, toDoubleArray, toDoubleArray, toString
Methods inherited from class java.util.AbstractCollection
addAll, containsAll, removeAll, retainAll, toArray, toArray
Methods inherited from interface it.unimi.dsi.fastutil.doubles.DoubleCollection
addAll, containsAll, removeAll, removeIf, removeIf, retainAll, toArray, toDoubleArray, toDoubleArray
Methods 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
a
are 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
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
size
elements ofa
are distinct.- Parameters:
a
- the backing array.size
- the number of valid elements ina
.
-
-
Method Details
-
iterator
Description copied from interface:DoubleCollection
Returns 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:
iterator
in interfaceCollection<Double>
- Specified by:
iterator
in interfaceDoubleCollection
- Specified by:
iterator
in interfaceDoubleIterable
- Specified by:
iterator
in interfaceDoubleSet
- Specified by:
iterator
in interfaceIterable<Double>
- Specified by:
iterator
in interfaceSet<Double>
- Specified by:
iterator
in 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:AbstractDoubleCollection
Returnstrue
if this collection contains the specified element.This implementation iterates over the elements in the collection, looking for the specified element.
- Specified by:
contains
in interfaceDoubleCollection
- Overrides:
contains
in classAbstractDoubleCollection
- See Also:
Collection.contains(Object)
-
size
public int size()- Specified by:
size
in interfaceCollection<Double>
- Specified by:
size
in interfaceSet<Double>
- Specified by:
size
in classAbstractCollection<Double>
-
remove
public boolean remove(double k)Description copied from class:AbstractDoubleSet
Removes 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 theList
interface. Delegates to the type-specificrem()
method implemented by type-specific abstractCollection
superclass.- Specified by:
remove
in interfaceDoubleSet
- Overrides:
remove
in classAbstractDoubleSet
- See Also:
Collection.remove(Object)
-
add
public boolean add(double k)Description copied from class:AbstractDoubleCollection
Ensures that this collection contains the specified element (optional operation).This implementation always throws an
UnsupportedOperationException
.- Specified by:
add
in interfaceDoubleCollection
- Overrides:
add
in classAbstractDoubleCollection
- See Also:
Collection.add(Object)
-
clear
public void clear()- Specified by:
clear
in interfaceCollection<Double>
- Specified by:
clear
in interfaceSet<Double>
- Overrides:
clear
in classAbstractCollection<Double>
-
isEmpty
public boolean isEmpty()- Specified by:
isEmpty
in interfaceCollection<Double>
- Specified by:
isEmpty
in interfaceSet<Double>
- Overrides:
isEmpty
in 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.
-