public class LongHashSet
extends java.util.AbstractSet<java.lang.Long>
implements java.io.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 |
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(java.lang.Long value) |
boolean |
addAll(java.util.Collection<? extends java.lang.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) |
boolean |
contains(java.lang.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(java.lang.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(java.lang.Object value) |
boolean |
removeAll(java.util.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() |
java.lang.Object[] |
toArray() |
<T> T[] |
toArray(T[] longo) |
java.lang.String |
toString() |
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(java.lang.Long value)
add
in interface java.util.Collection<java.lang.Long>
add
in interface java.util.Set<java.lang.Long>
add
in class java.util.AbstractCollection<java.lang.Long>
public boolean add(long value)
value
- the value to addjava.lang.IllegalArgumentException
- if value is missingValuepublic boolean remove(java.lang.Object value)
remove
in interface java.util.Collection<java.lang.Long>
remove
in interface java.util.Set<java.lang.Long>
remove
in class java.util.AbstractCollection<java.lang.Long>
public boolean remove(long value)
value
- the value to removepublic void compact()
public boolean contains(java.lang.Object value)
contains
in interface java.util.Collection<java.lang.Long>
contains
in interface java.util.Set<java.lang.Long>
contains
in class java.util.AbstractCollection<java.lang.Long>
public boolean contains(long value)
public int size()
size
in interface java.util.Collection<java.lang.Long>
size
in interface java.util.Set<java.lang.Long>
size
in class java.util.AbstractCollection<java.lang.Long>
public boolean isEmpty()
isEmpty
in interface java.util.Collection<java.lang.Long>
isEmpty
in interface java.util.Set<java.lang.Long>
isEmpty
in class java.util.AbstractCollection<java.lang.Long>
public void clear()
clear
in interface java.util.Collection<java.lang.Long>
clear
in interface java.util.Set<java.lang.Long>
clear
in class java.util.AbstractCollection<java.lang.Long>
public boolean addAll(java.util.Collection<? extends java.lang.Long> coll)
addAll
in interface java.util.Collection<java.lang.Long>
addAll
in interface java.util.Set<java.lang.Long>
addAll
in class java.util.AbstractCollection<java.lang.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(java.util.Collection<?> coll)
removeAll
in interface java.util.Collection<java.lang.Long>
removeAll
in interface java.util.Set<java.lang.Long>
removeAll
in class java.util.AbstractSet<java.lang.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()
iterator
in interface java.lang.Iterable<java.lang.Long>
iterator
in interface java.util.Collection<java.lang.Long>
iterator
in interface java.util.Set<java.lang.Long>
iterator
in class java.util.AbstractCollection<java.lang.Long>
public void copy(LongHashSet that)
public java.lang.String toString()
toString
in class java.util.AbstractCollection<java.lang.Long>
public <T> T[] toArray(T[] longo)
toArray
in interface java.util.Collection<java.lang.Long>
toArray
in interface java.util.Set<java.lang.Long>
toArray
in class java.util.AbstractCollection<java.lang.Long>
public java.lang.Object[] toArray()
toArray
in interface java.util.Collection<java.lang.Long>
toArray
in interface java.util.Set<java.lang.Long>
toArray
in class java.util.AbstractCollection<java.lang.Long>
public boolean equals(java.lang.Object other)
equals
in interface java.util.Collection<java.lang.Long>
equals
in interface java.util.Set<java.lang.Long>
equals
in class java.util.AbstractSet<java.lang.Long>
public int hashCode()
hashCode
in interface java.util.Collection<java.lang.Long>
hashCode
in interface java.util.Set<java.lang.Long>
hashCode
in class java.util.AbstractSet<java.lang.Long>
Copyright © 2014-2018 Real Logic Ltd. All Rights Reserved.