Package it.unimi.dsi.fastutil.objects
Class ObjectArraySet<K>
- java.lang.Object
-
- java.util.AbstractCollection<K>
-
- it.unimi.dsi.fastutil.objects.AbstractObjectCollection<K>
-
- it.unimi.dsi.fastutil.objects.AbstractObjectSet<K>
-
- it.unimi.dsi.fastutil.objects.ObjectArraySet<K>
-
- All Implemented Interfaces:
ObjectCollection<K>
,ObjectIterable<K>
,ObjectSet<K>
,java.io.Serializable
,java.lang.Cloneable
,java.lang.Iterable<K>
,java.util.Collection<K>
,java.util.Set<K>
public class ObjectArraySet<K> extends AbstractObjectSet<K> 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 ObjectArraySet()
Creates a new empty array set.ObjectArraySet(int capacity)
Creates a new empty array set of given initial capacity.ObjectArraySet(ObjectCollection<K> c)
Creates a new array set copying the contents of a given collection.ObjectArraySet(ObjectSet<K> c)
Creates a new array set copying the contents of a given collection.ObjectArraySet(java.lang.Object[] a)
Creates a new array set using the given backing array.ObjectArraySet(java.lang.Object[] a, int size)
Creates a new array set using the given backing array and the given number of elements of the array.ObjectArraySet(java.util.Collection<? extends K> c)
Creates a new array set copying the contents of a given set.ObjectArraySet(java.util.Set<? extends K> 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(K k)
void
clear()
ObjectArraySet<K>
clone()
Returns a deep copy of this set.boolean
contains(java.lang.Object k)
boolean
isEmpty()
ObjectIterator<K>
iterator()
Returns a type-specific iterator on the elements of this collection.boolean
remove(java.lang.Object k)
int
size()
-
Methods inherited from class it.unimi.dsi.fastutil.objects.AbstractObjectSet
equals, hashCode
-
Methods inherited from class it.unimi.dsi.fastutil.objects.AbstractObjectCollection
toString
-
-
-
-
Constructor Detail
-
ObjectArraySet
public ObjectArraySet(java.lang.Object[] 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.
-
ObjectArraySet
public ObjectArraySet()
Creates a new empty array set.
-
ObjectArraySet
public ObjectArraySet(int capacity)
Creates a new empty array set of given initial capacity.- Parameters:
capacity
- the initial capacity.
-
ObjectArraySet
public ObjectArraySet(ObjectCollection<K> c)
Creates a new array set copying the contents of a given collection.- Parameters:
c
- a collection.
-
ObjectArraySet
public ObjectArraySet(java.util.Collection<? extends K> c)
Creates a new array set copying the contents of a given set.- Parameters:
c
- a collection.
-
ObjectArraySet
public ObjectArraySet(ObjectSet<K> c)
Creates a new array set copying the contents of a given collection.- Parameters:
c
- a collection.
-
ObjectArraySet
public ObjectArraySet(java.util.Set<? extends K> c)
Creates a new array set copying the contents of a given set.- Parameters:
c
- a collection.
-
ObjectArraySet
public ObjectArraySet(java.lang.Object[] 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 ObjectIterator<K> iterator()
Description copied from interface:ObjectCollection
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<K>
- Specified by:
iterator
in interfacejava.lang.Iterable<K>
- Specified by:
iterator
in interfaceObjectCollection<K>
- Specified by:
iterator
in interfaceObjectIterable<K>
- Specified by:
iterator
in interfaceObjectSet<K>
- Specified by:
iterator
in interfacejava.util.Set<K>
- Specified by:
iterator
in classAbstractObjectSet<K>
- Returns:
- a type-specific iterator on the elements of this collection.
- See Also:
Iterable.iterator()
-
contains
public boolean contains(java.lang.Object k)
-
size
public int size()
-
remove
public boolean remove(java.lang.Object k)
-
add
public boolean add(K k)
-
clear
public void clear()
-
isEmpty
public boolean isEmpty()
-
clone
public ObjectArraySet<K> 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.
-
-