public class LongHashSet extends AbstractLongSet implements LongSet
Most operations are O(1), assuming no hash collisions. In the worst case (where all hashes collide), operations are O(n). Setting the initial capacity too low will force many resizing operations, but setting the initial capacity too high (or loadfactor too low) leads to wasted memory and slower iteration.
HashSet accepts the null key and null values. It is not synchronized, so if
you need multi-threaded access, consider using:
Set s = Collections.synchronizedSet(new HashSet(...));
The iterators are fail-fast, meaning that any structural modification,
except for remove() called on the iterator itself, cause the
iterator to throw a ConcurrentModificationException rather than
exhibit non-deterministic behavior.
LongCollection,
LongSet,
LongKeyHashMap| Constructor and Description |
|---|
LongHashSet()
Construct a new, empty HashSet whose backing HashMap has the default
capacity (11) and loadFacor (0.75).
|
LongHashSet(int initialCapacity)
Construct a new, empty HashSet whose backing HashMap has the supplied
capacity and the default load factor (0.75).
|
LongHashSet(int initialCapacity,
float loadFactor)
Construct a new, empty HashSet whose backing HashMap has the supplied
capacity and load factor.
|
LongHashSet(LongCollection c)
Construct a new HashSet with the same elements as are in the supplied
collection (eliminating any duplicates, of course).
|
| Modifier and Type | Method and Description |
|---|---|
boolean |
add(long v)
Adds the given Object to the set if it is not already in the Set.
|
void |
clear()
Empties this Set of all elements; this takes constant time.
|
boolean |
contains(long v)
Returns true if the supplied element is in this Set.
|
boolean |
isEmpty()
Returns true if this set has no elements in it.
|
LongIterator |
iterator()
Returns an Iterator over the elements of this Set, which visits the
elements in no particular order.
|
boolean |
remove(long v)
Removes the supplied Object from this Set if it is in the Set.
|
int |
size()
Returns the number of elements in this Set (its cardinality).
|
equals, hashCode, removeAlladdAll, containsAll, retainAll, toArray, toArray, toStringpublic LongHashSet()
public LongHashSet(int initialCapacity)
initialCapacity - the initial capacity of the backing HashMapjava.lang.IllegalArgumentException - if the capacity is negativepublic LongHashSet(int initialCapacity,
float loadFactor)
initialCapacity - the initial capacity of the backing HashMaploadFactor - the load factor of the backing HashMapjava.lang.IllegalArgumentException - if either argument is negative, or if loadFactor is
POSITIVE_INFINITY or NaNpublic LongHashSet(LongCollection c)
c - a collection of initial set elementsjava.lang.NullPointerException - if c is nullpublic boolean add(long v)
add in interface LongCollectionadd in interface LongSetadd in class AbstractLongCollectionv - the Object to add to this Setpublic void clear()
clear in interface LongCollectionclear in interface LongSetclear in class AbstractLongCollectionLongIterator.remove()public boolean contains(long v)
contains in interface LongCollectioncontains in interface LongSetcontains in class AbstractLongCollectionv - the long to look forpublic boolean isEmpty()
isEmpty in interface LongCollectionisEmpty in interface LongSetisEmpty in class AbstractLongCollectionsize() == 0.AbstractLongCollection.size()public LongIterator iterator()
ConcurrentModificationException if the set is modified
externally.iterator in interface LongCollectioniterator in interface LongIterableiterator in interface LongSetiterator in class AbstractLongCollectionpublic boolean remove(long v)
remove in interface LongCollectionremove in interface LongSetremove in class AbstractLongCollectionv - the long to removeLongIterator.remove()public int size()
size in interface LongCollectionsize in interface LongSetsize in class AbstractLongCollection