public class IntHashSet
extends java.util.AbstractSet<java.lang.Integer>
implements java.io.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,
Serialized Form| Modifier and Type | Class and Description |
|---|---|
class |
IntHashSet.IntIterator |
| 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(java.lang.Integer value) |
boolean |
addAll(java.util.Collection<? extends java.lang.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) |
boolean |
contains(java.lang.Object value) |
boolean |
containsAll(IntHashSet other)
IntHashSet specialised variant of {this#containsAll(Collection)}.
|
void |
copy(IntHashSet that) |
IntHashSet |
difference(IntHashSet other)
Fast Path set difference for comparison with another IntHashSet.
|
boolean |
equals(java.lang.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(java.lang.Object value) |
boolean |
removeAll(java.util.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() |
java.lang.Object[] |
toArray() |
<T> T[] |
toArray(T[] into) |
java.lang.String |
toString() |
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(java.lang.Integer value)
add in interface java.util.Collection<java.lang.Integer>add in interface java.util.Set<java.lang.Integer>add in class java.util.AbstractCollection<java.lang.Integer>public boolean add(int 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.Integer>remove in interface java.util.Set<java.lang.Integer>remove in class java.util.AbstractCollection<java.lang.Integer>public boolean remove(int value)
value - the value to removepublic void compact()
public boolean contains(java.lang.Object value)
contains in interface java.util.Collection<java.lang.Integer>contains in interface java.util.Set<java.lang.Integer>contains in class java.util.AbstractCollection<java.lang.Integer>public boolean contains(int value)
public int size()
size in interface java.util.Collection<java.lang.Integer>size in interface java.util.Set<java.lang.Integer>size in class java.util.AbstractCollection<java.lang.Integer>public boolean isEmpty()
isEmpty in interface java.util.Collection<java.lang.Integer>isEmpty in interface java.util.Set<java.lang.Integer>isEmpty in class java.util.AbstractCollection<java.lang.Integer>public void clear()
clear in interface java.util.Collection<java.lang.Integer>clear in interface java.util.Set<java.lang.Integer>clear in class java.util.AbstractCollection<java.lang.Integer>public boolean addAll(java.util.Collection<? extends java.lang.Integer> coll)
addAll in interface java.util.Collection<java.lang.Integer>addAll in interface java.util.Set<java.lang.Integer>addAll in class java.util.AbstractCollection<java.lang.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(java.util.Collection<?> coll)
removeAll in interface java.util.Collection<java.lang.Integer>removeAll in interface java.util.Set<java.lang.Integer>removeAll in class java.util.AbstractSet<java.lang.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()
iterator in interface java.lang.Iterable<java.lang.Integer>iterator in interface java.util.Collection<java.lang.Integer>iterator in interface java.util.Set<java.lang.Integer>iterator in class java.util.AbstractCollection<java.lang.Integer>public void copy(IntHashSet that)
public java.lang.String toString()
toString in class java.util.AbstractCollection<java.lang.Integer>public <T> T[] toArray(T[] into)
toArray in interface java.util.Collection<java.lang.Integer>toArray in interface java.util.Set<java.lang.Integer>toArray in class java.util.AbstractCollection<java.lang.Integer>public java.lang.Object[] toArray()
toArray in interface java.util.Collection<java.lang.Integer>toArray in interface java.util.Set<java.lang.Integer>toArray in class java.util.AbstractCollection<java.lang.Integer>public boolean equals(java.lang.Object other)
equals in interface java.util.Collection<java.lang.Integer>equals in interface java.util.Set<java.lang.Integer>equals in class java.util.AbstractSet<java.lang.Integer>public int hashCode()
hashCode in interface java.util.Collection<java.lang.Integer>hashCode in interface java.util.Set<java.lang.Integer>hashCode in class java.util.AbstractSet<java.lang.Integer>Copyright © 2014-2019 Real Logic Ltd. All Rights Reserved.