Class BooleanArraySet
- java.lang.Object
-
- java.util.AbstractCollection<Boolean>
-
- it.unimi.dsi.fastutil.booleans.AbstractBooleanCollection
-
- it.unimi.dsi.fastutil.booleans.AbstractBooleanSet
-
- it.unimi.dsi.fastutil.booleans.BooleanArraySet
-
- All Implemented Interfaces:
BooleanCollection
,BooleanIterable
,BooleanSet
,Serializable
,Cloneable
,Iterable<Boolean>
,Collection<Boolean>
,Set<Boolean>
public class BooleanArraySet extends AbstractBooleanSet implements Serializable, 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 BooleanArraySet()
Creates a new empty array set.BooleanArraySet(boolean[] a)
Creates a new array set using the given backing array.BooleanArraySet(boolean[] a, int size)
Creates a new array set using the given backing array and the given number of elements of the array.BooleanArraySet(int capacity)
Creates a new empty array set of given initial capacity.BooleanArraySet(BooleanCollection c)
Creates a new array set copying the contents of a given collection.BooleanArraySet(BooleanSet c)
Creates a new array set copying the contents of a given collection.BooleanArraySet(Collection<? extends Boolean> c)
Creates a new array set copying the contents of a given set.BooleanArraySet(Set<? extends Boolean> 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(boolean k)
Ensures that this collection contains the specified element (optional operation).void
clear()
BooleanArraySet
clone()
Returns a deep copy of this set.boolean
contains(boolean k)
Returnstrue
if this collection contains the specified element.boolean
isEmpty()
BooleanIterator
iterator()
Returns a type-specific iterator on the elements of this collection.boolean
remove(boolean k)
Removes an element from this set.int
size()
-
Methods inherited from class it.unimi.dsi.fastutil.booleans.AbstractBooleanSet
equals, hashCode, rem
-
Methods inherited from class it.unimi.dsi.fastutil.booleans.AbstractBooleanCollection
add, addAll, contains, containsAll, remove, removeAll, retainAll, toArray, toBooleanArray, toBooleanArray, toString
-
Methods inherited from class java.util.AbstractCollection
addAll, containsAll, removeAll, retainAll, toArray, toArray
-
Methods inherited from interface it.unimi.dsi.fastutil.booleans.BooleanCollection
addAll, containsAll, removeAll, retainAll, toArray, toBooleanArray, toBooleanArray
-
Methods inherited from interface it.unimi.dsi.fastutil.booleans.BooleanIterable
forEach, forEach
-
Methods inherited from interface it.unimi.dsi.fastutil.booleans.BooleanSet
add, contains, remove
-
Methods inherited from interface java.util.Collection
parallelStream, removeIf, stream, toArray
-
Methods inherited from interface java.util.Set
addAll, containsAll, removeAll, retainAll, spliterator, toArray, toArray
-
-
-
-
Constructor Detail
-
BooleanArraySet
public BooleanArraySet(boolean[] 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.
-
BooleanArraySet
public BooleanArraySet()
Creates a new empty array set.
-
BooleanArraySet
public BooleanArraySet(int capacity)
Creates a new empty array set of given initial capacity.- Parameters:
capacity
- the initial capacity.
-
BooleanArraySet
public BooleanArraySet(BooleanCollection c)
Creates a new array set copying the contents of a given collection.- Parameters:
c
- a collection.
-
BooleanArraySet
public BooleanArraySet(Collection<? extends Boolean> c)
Creates a new array set copying the contents of a given set.- Parameters:
c
- a collection.
-
BooleanArraySet
public BooleanArraySet(BooleanSet c)
Creates a new array set copying the contents of a given collection.- Parameters:
c
- a collection.
-
BooleanArraySet
public BooleanArraySet(Set<? extends Boolean> c)
Creates a new array set copying the contents of a given set.- Parameters:
c
- a collection.
-
BooleanArraySet
public BooleanArraySet(boolean[] 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 BooleanIterator iterator()
Description copied from interface:BooleanCollection
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 interfaceBooleanCollection
- Specified by:
iterator
in interfaceBooleanIterable
- Specified by:
iterator
in interfaceBooleanSet
- Specified by:
iterator
in interfaceCollection<Boolean>
- Specified by:
iterator
in interfaceIterable<Boolean>
- Specified by:
iterator
in interfaceSet<Boolean>
- Specified by:
iterator
in classAbstractBooleanSet
- Returns:
- a type-specific iterator on the elements of this collection.
- See Also:
Iterable.iterator()
-
contains
public boolean contains(boolean k)
Description copied from class:AbstractBooleanCollection
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 interfaceBooleanCollection
- Overrides:
contains
in classAbstractBooleanCollection
- See Also:
Collection.contains(Object)
-
size
public int size()
- Specified by:
size
in interfaceCollection<Boolean>
- Specified by:
size
in interfaceSet<Boolean>
- Specified by:
size
in classAbstractCollection<Boolean>
-
remove
public boolean remove(boolean k)
Description copied from class:AbstractBooleanSet
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 interfaceBooleanSet
- Overrides:
remove
in classAbstractBooleanSet
- See Also:
Collection.remove(Object)
-
add
public boolean add(boolean k)
Description copied from class:AbstractBooleanCollection
Ensures that this collection contains the specified element (optional operation).This implementation always throws an
UnsupportedOperationException
.- Specified by:
add
in interfaceBooleanCollection
- Overrides:
add
in classAbstractBooleanCollection
- See Also:
Collection.add(Object)
-
clear
public void clear()
- Specified by:
clear
in interfaceCollection<Boolean>
- Specified by:
clear
in interfaceSet<Boolean>
- Overrides:
clear
in classAbstractCollection<Boolean>
-
isEmpty
public boolean isEmpty()
- Specified by:
isEmpty
in interfaceCollection<Boolean>
- Specified by:
isEmpty
in interfaceSet<Boolean>
- Overrides:
isEmpty
in classAbstractCollection<Boolean>
-
clone
public BooleanArraySet 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.
-
-