public class IntHashSet extends AbstractSet<Integer> implements Serializable
By storing elements as int primitives this significantly reduces memory consumption compared with Java's builtin
HashSet<Integer>
. It implements Set<Integer>
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.
IntHashSet.IntIterator
,
Set
Modifier and Type | Class and Description |
---|---|
class |
IntHashSet.IntIterator
Iterator which supports unboxed access to values via
IntHashSet.IntIterator.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 |
---|
IntHashSet()
Construct a hash set with
DEFAULT_INITIAL_CAPACITY , Hashing.DEFAULT_LOAD_FACTOR ,
and iterator caching support. |
IntHashSet(int proposedCapacity)
Construct a hash set with a proposed capacity,
Hashing.DEFAULT_LOAD_FACTOR ,
and iterator caching support. |
IntHashSet(int proposedCapacity,
float loadFactor)
Construct a hash set with a proposed initial capacity, load factor, and iterator caching support.
|
IntHashSet(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(int value)
Primitive specialised overload of {this#add(Integer)}
|
boolean |
add(Integer value) |
boolean |
addAll(Collection<? extends Integer> coll) |
boolean |
addAll(IntHashSet coll)
Alias for
addAll(Collection) for the specialized case when adding another IntHashSet,
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(int value)
Contains method that does not box values.
|
boolean |
contains(Object value) |
boolean |
containsAll(IntHashSet other)
IntHashSet specialised variant of {this#containsAll(Collection)}.
|
void |
copy(IntHashSet that)
Copye values from another
IntHashSet into this one. |
IntHashSet |
difference(IntHashSet other)
Fast Path set difference for comparison with another IntHashSet.
|
boolean |
equals(Object other) |
int |
hashCode() |
boolean |
isEmpty() |
IntHashSet.IntIterator |
iterator() |
float |
loadFactor()
Get the load factor beyond which the set will increase size.
|
boolean |
remove(int value)
An int specialised version of {this#remove(Object)}.
|
boolean |
remove(Object value) |
boolean |
removeAll(Collection<?> coll) |
boolean |
removeAll(IntHashSet coll)
Alias for
removeAll(Collection) for the specialized case when removing another IntHashSet,
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 IntHashSet()
DEFAULT_INITIAL_CAPACITY
, Hashing.DEFAULT_LOAD_FACTOR
,
and iterator caching support.public IntHashSet(int proposedCapacity)
Hashing.DEFAULT_LOAD_FACTOR
,
and iterator caching support.proposedCapacity
- for the initial capacity of the set.public IntHashSet(int proposedCapacity, float loadFactor)
proposedCapacity
- for the initial capacity of the set.loadFactor
- to be used for resizing.public IntHashSet(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(Integer value)
add
in interface Collection<Integer>
add
in interface Set<Integer>
add
in class AbstractCollection<Integer>
public boolean add(int value)
value
- the value to addIllegalArgumentException
- if value is missingValuepublic boolean remove(Object value)
remove
in interface Collection<Integer>
remove
in interface Set<Integer>
remove
in class AbstractCollection<Integer>
public boolean remove(int value)
value
- the value to removepublic void compact()
public boolean contains(Object value)
contains
in interface Collection<Integer>
contains
in interface Set<Integer>
contains
in class AbstractCollection<Integer>
public boolean contains(int value)
value
- to be check for if the set contains it.Collection.contains(Object)
public int size()
size
in interface Collection<Integer>
size
in interface Set<Integer>
size
in class AbstractCollection<Integer>
public boolean isEmpty()
isEmpty
in interface Collection<Integer>
isEmpty
in interface Set<Integer>
isEmpty
in class AbstractCollection<Integer>
public void clear()
clear
in interface Collection<Integer>
clear
in interface Set<Integer>
clear
in class AbstractCollection<Integer>
public boolean addAll(Collection<? extends Integer> coll)
addAll
in interface Collection<Integer>
addAll
in interface Set<Integer>
addAll
in class AbstractCollection<Integer>
public boolean addAll(IntHashSet coll)
addAll(Collection)
for the specialized case when adding another IntHashSet,
avoids boxing and allocationscoll
- containing the values to be added.true
if this set changed as a result of the callpublic boolean containsAll(IntHashSet other)
other
- int hash set to compare against.public IntHashSet difference(IntHashSet other)
Note: garbage free in the identical case, allocates otherwise.
other
- the other set to subtractpublic boolean removeAll(Collection<?> coll)
removeAll
in interface Collection<Integer>
removeAll
in interface Set<Integer>
removeAll
in class AbstractSet<Integer>
public boolean removeAll(IntHashSet coll)
removeAll(Collection)
for the specialized case when removing another IntHashSet,
avoids boxing and allocationscoll
- containing the values to be removed.true
if this set changed as a result of the callpublic IntHashSet.IntIterator iterator()
public void copy(IntHashSet that)
IntHashSet
into this one.that
- set to copy values from.public String toString()
toString
in class AbstractCollection<Integer>
public <T> T[] toArray(T[] a)
toArray
in interface Collection<Integer>
toArray
in interface Set<Integer>
toArray
in class AbstractCollection<Integer>
public Object[] toArray()
toArray
in interface Collection<Integer>
toArray
in interface Set<Integer>
toArray
in class AbstractCollection<Integer>
public boolean equals(Object other)
equals
in interface Collection<Integer>
equals
in interface Set<Integer>
equals
in class AbstractSet<Integer>
public int hashCode()
hashCode
in interface Collection<Integer>
hashCode
in interface Set<Integer>
hashCode
in class AbstractSet<Integer>
Copyright © 2014-2021 Real Logic Limited. All Rights Reserved.