E
- The type of the elements stored in the setpublic class OAHashSet<E> extends AbstractSet<E>
Set
implementation with linear
probing for CPU cache efficiency. This implementation caches the hashes
of the elements stored in the set. This caching enables avoiding
expensive hashCode()
calls when rehashing at the cost of the
increased memory consumption.
Besides avoiding hashCode()
calls on rehashing, this
implementation offers methods that accept the hash together with the
element if it is already known on the caller side.
See add(Object, int)
, contains(Object, int)
, remove(Object, int)
.
This Set
implementation does not permit null elements.
This Set
implementation does not permit concurrent modifications
during iteration.
Please note that this Set
implementation does not shrink when
elements are removed.
Constructor and Description |
---|
OAHashSet()
Constructs an
OAHashSet instance with default initial
capacity and default load factor |
OAHashSet(int initialCapacity)
Constructs an
OAHashSet instance with the specified
initial capacity and with the default load factor |
OAHashSet(int initialCapacity,
float loadFactor)
Constructs an
OAHashSet instance with the specified
initial capacity and load factor |
Modifier and Type | Method and Description |
---|---|
boolean |
add(E element) |
boolean |
add(E elementToAdd,
int hash)
Adds the specified element to this set if it is not already present.
|
int |
capacity()
Returns the capacity of the set
|
void |
clear() |
boolean |
contains(Object objectToCheck) |
boolean |
contains(Object objectToCheck,
int hash)
Returns true if this set contains the specified element
with the hash provided in parameter.
|
long |
footprint()
Returns the current memory consumption (in bytes)
|
int |
hashCode() |
Iterator<E> |
iterator() |
float |
loadFactor()
Returns the load factor of the set
|
boolean |
remove(Object objectToRemove) |
boolean |
remove(Object objectToRemove,
int hash)
Removes the specified element from this set if it is present with
the hash provided in parameter.
|
boolean |
removeAll(Collection<?> elementsToRemove) |
boolean |
retainAll(Collection<?> elementsToRetain) |
int |
size() |
Object[] |
toArray() |
<T> T[] |
toArray(T[] array) |
equals
addAll, containsAll, isEmpty, toString
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
addAll, containsAll, isEmpty, spliterator
parallelStream, removeIf, stream
public OAHashSet()
OAHashSet
instance with default initial
capacity and default load factorDEFAULT_INITIAL_CAPACITY
,
DEFAULT_LOAD_FACTOR
public OAHashSet(int initialCapacity)
OAHashSet
instance with the specified
initial capacity and with the default load factorinitialCapacity
- the initial capacity of the set to be createdDEFAULT_LOAD_FACTOR
public OAHashSet(int initialCapacity, float loadFactor)
OAHashSet
instance with the specified
initial capacity and load factorinitialCapacity
- the initial capacity of the set to be createdloadFactor
- the load factor of the set to be createdpublic boolean add(E element)
add
in interface Collection<E>
add
in interface Set<E>
add
in class AbstractCollection<E>
public boolean add(E elementToAdd, int hash)
This variant of add(Object)
acts as an optimisation to
enable avoiding hashCode()
calls if the hash is already
known on the caller side.
elementToAdd
- element to be added to this sethash
- the hash of the element to be addedadd(Object)
public boolean contains(Object objectToCheck)
contains
in interface Collection<E>
contains
in interface Set<E>
contains
in class AbstractCollection<E>
public boolean contains(Object objectToCheck, int hash)
This variant of contains(Object)
acts as an optimisation to
enable avoiding hashCode()
calls if the hash is already
known on the caller side.
objectToCheck
- element whose presence in this set is to be testedhash
- the hash of the element to be testedcontains(Object)
public boolean remove(Object objectToRemove)
remove
in interface Collection<E>
remove
in interface Set<E>
remove
in class AbstractCollection<E>
public boolean remove(Object objectToRemove, int hash)
This variant of remove(Object)
acts as an optimisation to
enable avoiding hashCode()
calls if the hash is already
known on the caller side.
objectToRemove
- object to be removed from this set, if presenthash
- the hash of the element to be removedremove(Object)
public boolean removeAll(Collection<?> elementsToRemove)
removeAll
in interface Collection<E>
removeAll
in interface Set<E>
removeAll
in class AbstractSet<E>
public boolean retainAll(Collection<?> elementsToRetain)
retainAll
in interface Collection<E>
retainAll
in interface Set<E>
retainAll
in class AbstractCollection<E>
public int size()
size
in interface Collection<E>
size
in interface Set<E>
size
in class AbstractCollection<E>
public Object[] toArray()
toArray
in interface Collection<E>
toArray
in interface Set<E>
toArray
in class AbstractCollection<E>
public <T> T[] toArray(T[] array)
toArray
in interface Collection<E>
toArray
in interface Set<E>
toArray
in class AbstractCollection<E>
public void clear()
clear
in interface Collection<E>
clear
in interface Set<E>
clear
in class AbstractCollection<E>
public int capacity()
public long footprint()
public float loadFactor()
public int hashCode()
hashCode
in interface Collection<E>
hashCode
in interface Set<E>
hashCode
in class AbstractSet<E>
Copyright © 2022 Hazelcast, Inc.. All Rights Reserved.