Class DoubleArraySet
- java.lang.Object
-
- java.util.AbstractCollection<java.lang.Double>
-
- it.unimi.dsi.fastutil.doubles.AbstractDoubleCollection
-
- it.unimi.dsi.fastutil.doubles.AbstractDoubleSet
-
- it.unimi.dsi.fastutil.doubles.DoubleArraySet
-
- All Implemented Interfaces:
DoubleCollection
,DoubleIterable
,DoubleSet
,java.io.Serializable
,java.lang.Cloneable
,java.lang.Iterable<java.lang.Double>
,java.util.Collection<java.lang.Double>
,java.util.Set<java.lang.Double>
public class DoubleArraySet extends AbstractDoubleSet 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 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(java.util.Collection<? extends java.lang.Double> 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 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.AbstractDoubleSet
equals, hashCode, rem
-
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 it.unimi.dsi.fastutil.doubles.DoubleIterable
forEach, forEach
-
-
-
-
Constructor Detail
-
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
public DoubleArraySet(DoubleCollection c)
Creates a new array set copying the contents of a given collection.- Parameters:
c
- a collection.
-
DoubleArraySet
public DoubleArraySet(java.util.Collection<? extends java.lang.Double> c)
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 Detail
-
iterator
public DoubleIterator 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 interfacejava.util.Collection<java.lang.Double>
- Specified by:
iterator
in interfaceDoubleCollection
- Specified by:
iterator
in interfaceDoubleIterable
- Specified by:
iterator
in interfaceDoubleSet
- Specified by:
iterator
in interfacejava.lang.Iterable<java.lang.Double>
- Specified by:
iterator
in interfacejava.util.Set<java.lang.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 interfacejava.util.Collection<java.lang.Double>
- Specified by:
size
in interfacejava.util.Set<java.lang.Double>
- Specified by:
size
in classjava.util.AbstractCollection<java.lang.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 interfacejava.util.Collection<java.lang.Double>
- Specified by:
clear
in interfacejava.util.Set<java.lang.Double>
- Overrides:
clear
in classjava.util.AbstractCollection<java.lang.Double>
-
isEmpty
public boolean isEmpty()
- Specified by:
isEmpty
in interfacejava.util.Collection<java.lang.Double>
- Specified by:
isEmpty
in interfacejava.util.Set<java.lang.Double>
- Overrides:
isEmpty
in classjava.util.AbstractCollection<java.lang.Double>
-
clone
public DoubleArraySet 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.
-
-