public class LongHashSet extends AbstractSet<Long> implements Serializable
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
,
Serialized FormModifier and Type | Class and Description |
---|---|
class |
LongHashSet.LongIterator
Iterator which supports unboxed access to values.
|
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 ,
and iterator caching support. |
LongHashSet(int proposedCapacity)
Construct a hash set with a proposed capacity,
Hashing.DEFAULT_LOAD_FACTOR ,
and iterator caching support. |
LongHashSet(int proposedCapacity,
float loadFactor)
Construct a hash set with a proposed initial capacity, load factor, and iterator caching support.
|
LongHashSet(int proposedCapacity,
float loadFactor,
boolean shouldAvoidAllocation)
Construct a hash set with a proposed initial capacity, load factor, and indicated iterator caching support.
|
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 other)
LongHashSet specialised variant of {this#containsAll(Collection)}.
|
void |
copy(LongHashSet that) |
LongHashSet |
difference(LongHashSet other)
Fast Path set difference for comparison with another LongHashSet.
|
boolean |
equals(Object other) |
int |
hashCode() |
boolean |
isEmpty() |
LongHashSet.LongIterator |
iterator() |
float |
loadFactor()
Get the load factor beyond which the set will increase size.
|
boolean |
remove(long value)
An long specialised version of {this#remove(Object)}.
|
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 |
int |
resizeThreshold()
Get the actual threshold which when reached the map will resize.
|
int |
size() |
Object[] |
toArray() |
<T> T[] |
toArray(T[] a) |
String |
toString() |
containsAll, retainAll
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
containsAll, retainAll, spliterator
parallelStream, removeIf, stream
public static final int DEFAULT_INITIAL_CAPACITY
public LongHashSet()
DEFAULT_INITIAL_CAPACITY
, Hashing.DEFAULT_LOAD_FACTOR
,
and iterator caching support.public LongHashSet(int proposedCapacity)
Hashing.DEFAULT_LOAD_FACTOR
,
and iterator caching support.proposedCapacity
- for the initial capacity of the set.public LongHashSet(int proposedCapacity, float loadFactor)
proposedCapacity
- for the initial capacity of the set.loadFactor
- to be used for resizing.public LongHashSet(int proposedCapacity, float loadFactor, boolean shouldAvoidAllocation)
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 addIllegalArgumentException
- if value is missingValuepublic 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 removepublic 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 check 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 allocationscoll
- containing the values to be added.true
if this set changed as a result of the callpublic boolean containsAll(LongHashSet other)
other
- 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 subtractpublic 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 allocationscoll
- containing the values to be removed.true
if this set changed as a result of the callpublic LongHashSet.LongIterator iterator()
public void copy(LongHashSet that)
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-2019 Real Logic Ltd. All Rights Reserved.