public class LongHashSet extends AbstractSet<Long>
By storing elements as long primitives this significantly reduces memory consumption compared with Java's builtin
HashSet<Long>. It implements Set<Long> for convenience, but calling
functionality via those methods can add boxing overhead to your usage.
This class is not Threadsafe.
This HashSet caches its iterator object by default, so nested iteration is not supported. You can override this behaviour at construction by indicating that the iterator should not be cached.
LongHashSet.LongIterator,
Set| Modifier and Type | Class and Description |
|---|---|
class |
LongHashSet.LongIterator
Iterator which supports unboxed access to the values via
LongHashSet.LongIterator.nextValue(). |
| Modifier and Type | Field and Description |
|---|---|
static int |
DEFAULT_INITIAL_CAPACITY
The initial capacity used when none is specified in the constructor.
|
| Constructor and Description |
|---|
LongHashSet()
Construct a hash set with
DEFAULT_INITIAL_CAPACITY, Hashing.DEFAULT_LOAD_FACTOR, iterator
caching support and -1 as a missing value. |
LongHashSet(int proposedCapacity)
Construct a hash set with a proposed capacity,
Hashing.DEFAULT_LOAD_FACTOR, iterator
caching support and -1 as a missing value. |
LongHashSet(int proposedCapacity,
float loadFactor)
Construct a hash set with a proposed initial capacity, load factor, iterator caching support and
-1 as a
missing value. |
LongHashSet(int proposedCapacity,
float loadFactor,
boolean shouldAvoidAllocation)
Construct a hash set with a proposed initial capacity, load factor, iterator caching support and
-1 as a
missing value. |
| Modifier and Type | Method and Description |
|---|---|
boolean |
add(long value)
Primitive specialised overload of {this#add(Long)}.
|
boolean |
add(Long value) |
boolean |
addAll(Collection<? extends Long> coll) |
boolean |
addAll(LongHashSet coll)
Alias for
addAll(Collection) for the specialized case when adding another LongHashSet,
avoids boxing and allocations. |
int |
capacity()
Get the total capacity for the set to which the load factor with be a fraction of.
|
void |
clear() |
void |
compact()
Compact the backing arrays by rehashing with a capacity just larger than current size
and giving consideration to the load factor.
|
boolean |
contains(long value)
Contains method that does not box values.
|
boolean |
contains(Object value) |
boolean |
containsAll(LongHashSet coll)
LongHashSet specialised variant of {this#containsAll(Collection)}.
|
void |
copy(LongHashSet that)
Copy values from another
LongHashSet longo this one. |
LongHashSet |
difference(LongHashSet other)
Fast Path set difference for comparison with another LongHashSet.
|
boolean |
equals(Object other) |
void |
forEachLong(LongConsumer action)
Iterate over the collection without boxing.
|
int |
hashCode() |
boolean |
isEmpty() |
LongHashSet.LongIterator |
iterator() |
float |
loadFactor()
Get the load factor beyond which the set will increase size.
|
boolean |
remove(long value)
Specialised version of {this#remove(Object)} for long.
|
boolean |
remove(Object value) |
boolean |
removeAll(Collection<?> coll) |
boolean |
removeAll(LongHashSet coll)
Alias for
removeAll(Collection) for the specialized case when removing another LongHashSet,
avoids boxing and allocations. |
boolean |
removeIf(Predicate<? super Long> filter) |
boolean |
removeIfLong(LongPredicate filter)
Removes all the elements of this collection that satisfy the given predicate.
|
int |
resizeThreshold()
Get the actual threshold which when reached the map will resize.
|
boolean |
retainAll(Collection<?> coll) |
boolean |
retainAll(LongHashSet coll)
Alias for
retainAll(Collection) for the specialized case when retaining on another LongHashSet,
avoids boxing and allocations. |
int |
size() |
Object[] |
toArray() |
<T> T[] |
toArray(T[] a) |
String |
toString() |
containsAllclone, finalize, getClass, notify, notifyAll, wait, wait, waitcontainsAll, spliteratorparallelStream, streampublic static final int DEFAULT_INITIAL_CAPACITY
public LongHashSet()
DEFAULT_INITIAL_CAPACITY, Hashing.DEFAULT_LOAD_FACTOR, iterator
caching support and -1 as a missing value.public LongHashSet(int proposedCapacity)
Hashing.DEFAULT_LOAD_FACTOR, iterator
caching support and -1 as a missing value.proposedCapacity - for the initial capacity of the set.public LongHashSet(int proposedCapacity,
float loadFactor)
-1 as a
missing value.proposedCapacity - for the initial capacity of the set.loadFactor - to be used for resizing.public LongHashSet(int proposedCapacity,
float loadFactor,
boolean shouldAvoidAllocation)
-1 as a
missing value.proposedCapacity - for the initial capacity of the set.loadFactor - to be used for resizing.shouldAvoidAllocation - should the iterator be cached to avoid further allocation.public float loadFactor()
public int capacity()
public int resizeThreshold()
public boolean add(Long value)
add in interface Collection<Long>add in interface Set<Long>add in class AbstractCollection<Long>public boolean add(long value)
value - the value to add.public boolean remove(Object value)
remove in interface Collection<Long>remove in interface Set<Long>remove in class AbstractCollection<Long>public boolean remove(long value)
value - the value to remove.public void compact()
public boolean contains(Object value)
contains in interface Collection<Long>contains in interface Set<Long>contains in class AbstractCollection<Long>public boolean contains(long value)
value - to be checked for if the set contains it.Collection.contains(Object)public int size()
size in interface Collection<Long>size in interface Set<Long>size in class AbstractCollection<Long>public boolean isEmpty()
isEmpty in interface Collection<Long>isEmpty in interface Set<Long>isEmpty in class AbstractCollection<Long>public void clear()
clear in interface Collection<Long>clear in interface Set<Long>clear in class AbstractCollection<Long>public boolean addAll(Collection<? extends Long> coll)
addAll in interface Collection<Long>addAll in interface Set<Long>addAll in class AbstractCollection<Long>public boolean addAll(LongHashSet coll)
addAll(Collection) for the specialized case when adding another LongHashSet,
avoids boxing and allocations.coll - containing the values to be added.true if this set changed as a result of the call.public boolean containsAll(LongHashSet coll)
coll - long hash set to compare against.public LongHashSet difference(LongHashSet other)
Note: garbage free in the identical case, allocates otherwise.
other - the other set to subtract.public boolean removeIfLong(LongPredicate filter)
NB: Renamed from removeIf to avoid overloading on parameter types of lambda expression, which doesn't play well with type inference in lambda expressions.
filter - which returns true for elements to be removed.true if any elements were removed.public boolean removeAll(Collection<?> coll)
removeAll in interface Collection<Long>removeAll in interface Set<Long>removeAll in class AbstractSet<Long>public boolean removeAll(LongHashSet coll)
removeAll(Collection) for the specialized case when removing another LongHashSet,
avoids boxing and allocations.coll - containing the values to be removed.true if this set changed as a result of the call.public boolean retainAll(Collection<?> coll)
retainAll in interface Collection<Long>retainAll in interface Set<Long>retainAll in class AbstractCollection<Long>public boolean retainAll(LongHashSet coll)
retainAll(Collection) for the specialized case when retaining on another LongHashSet,
avoids boxing and allocations.coll - containing elements to be retained in this set.true if this set changed as a result of the call.public LongHashSet.LongIterator iterator()
public void forEachLong(LongConsumer action)
action - to be taken for each element.public void copy(LongHashSet that)
LongHashSet longo this one.that - set to copy values from.public String toString()
toString in class AbstractCollection<Long>public <T> T[] toArray(T[] a)
toArray in interface Collection<Long>toArray in interface Set<Long>toArray in class AbstractCollection<Long>public Object[] toArray()
toArray in interface Collection<Long>toArray in interface Set<Long>toArray in class AbstractCollection<Long>public boolean equals(Object other)
equals in interface Collection<Long>equals in interface Set<Long>equals in class AbstractSet<Long>public int hashCode()
hashCode in interface Collection<Long>hashCode in interface Set<Long>hashCode in class AbstractSet<Long>Copyright © 2014-2022 Real Logic Limited. All Rights Reserved.