longs, implemented using open addressing with linear probing for
collision resolution.
| Modifier and Type | Class and Description |
|---|---|
| protected class | LongHashSet.
An iterator implementation for |
| Modifier and Type | Field and Description |
|---|---|
| protected int | assigned
The number of stored keys (assigned key slots), excluding the special "empty" key, if any. |
| protected boolean | hasEmptyKey
Special treatment for the "empty slot" key marker. |
| protected int | iterationSeed
Seed used to ensure the hash iteration order is different from an iteration to another. |
| public long[] | keys
The hash array holding keys. |
| protected double | loadFactor
The load factor for |
| protected int | |
| protected int |
| Access | Constructor and Description |
|---|---|
| public | |
| public | |
| public | LongHashSet(int
The expected number of elements guaranteed not to cause a rehash
(inclusive). expectedElements, double The load factor for internal buffers. Insane load factors (zero, full
capacity) are rejected by loadFactor)verifyLoadFactor(double).New instance with the provided defaults. |
| public |
| Modifier and Type | Method and Description |
|---|---|
| public boolean | |
| public final int | Returns: Returns the number of elements actually added as a result of this call (not previously present in the set).Adds all elements from the given list (vararg) to this set. |
| public int | Returns: Returns the number of elements actually added as a result of this call (not previously present in the set).Implements com. Adds all elements from the given |
| public int | Returns: Returns the number of elements actually added as a result of this call (not previously present in the set).Adds all elements from the given iterable to this set. |
| protected void | |
| protected void | allocateThenInsertThenRehash(int slot, long pendingKey)
This method is invoked when there is a new key to be inserted into the buffer but there is not enough empty slots to do so. |
| public void | clear()
Implements com. Removes all elements from this collection. |
| public LongHashSet | |
| public boolean | contains(long key)
Implements com. Lookup a given element in the container. |
| public void | ensureCapacity(int
The total number of elements, inclusive. expectedElements)Implements com. Ensure this container can hold at least the given number of elements without resizing its buffers. |
| public boolean | equals(Object
the reference object with which to compare. obj)Overrides java. Indicates whether some other object is "equal to" this one. |
| public <T extends LongProcedure> T | forEach(T procedure)
Implements com. Applies a |
| public <T extends LongPredicate> T | forEach(T predicate)
Implements com. Applies a |
| public static LongHashSet | |
| public int | |
| protected int | |
| public boolean | Returns: Returnstrue if the index corresponds to an existing key or false
otherwise. This is equivalent to checking whether the index is a positive value (existing
keys) or a negative value (non-existing keys).The index of a given key, as returned from index)indexOf.
|
| public long | Returns: Returns the equivalent key currently stored in the set.The index of an existing key. index)Returns the exact value of the existing key. |
| public void | indexInsert(int
The index of a previously non-existing key, as returned from index, long key)indexOf.Inserts a key for an index that is not present in the set. |
| public int | Returns: A non-negative value of the logical "index" of the key in the set or a negative value if the key did not exist.The key to locate in the set. key)Returns a logical "index" of a given key that can be used to speed up follow-up logic in certain scenarios (conditional logic). |
| public void | indexRemove(int
The index of the key to remove, as returned from index)indexOf.Removes a key at an index previously acquired from |
| public long | Returns: Returns the previous key stored in the set.The index of an existing key. index, long The key to put in the set as a replacement. Must be equivalent to the key
currently stored at the provided index. equivalentKey)Replaces the existing equivalent key with the given one and returns any previous value stored for that key. |
| public boolean | |
| public Iterator | iterator()
Implements com. Returns an iterator to a cursor traversing the collection. |
| protected int | nextIterationSeed()
Provides the next iteration seed used to build the iteration starting slot and offset increment. |
| public long | ramBytesAllocated()
Implements com. Allocated memory estimation |
| public long | ramBytesUsed()
Implements com. Bytes that is actually been used |
| protected void | |
| public void | release()
Implements com. Removes all elements from the collection and additionally releases any internal buffers. |
| public boolean | |
| public int | removeAll(long
Element to be removed from this collection, if present. key)Implements com. Removes all occurrences of |
| public int | Returns: Returns the number of elements actually removed as a result of this call.Removes all keys present in a given container. |
| public int | removeAll(LongPredicate predicate)
Implements com. Removes all elements in this collection for which the given predicate returns |
| private boolean | |
| protected void | shiftConflictingKeys(int gapSlot)
Shift all the slot-conflicting keys allocated to (and including) |
| public int | size()
Implements com. Return the current number of elements in this container. |
| public long[] | toArray()
Overrides com. Implements com. Copies all elements of this container to an array. |
| protected double | |
| public String | visualizeKeyDistribution(int
The number of characters to "squeeze" the entire buffer into. characters)Implements com. Visually depict the distribution of keys. |
| assigned | back to summary |
|---|---|
| protected int assigned The number of stored keys (assigned key slots), excluding the special "empty" key, if any.
| |
| hasEmptyKey | back to summary |
|---|---|
| protected boolean hasEmptyKey Special treatment for the "empty slot" key marker. | |
| iterationSeed | back to summary |
|---|---|
| protected int iterationSeed Seed used to ensure the hash iteration order is different from an iteration to another. | |
| keys | back to summary |
|---|---|
| public long[] keys The hash array holding keys. | |
| loadFactor | back to summary |
|---|---|
| protected double loadFactor The load factor for | |
| mask | back to summary |
|---|---|
| protected int mask Mask for slot scans in | |
| resizeAt | back to summary |
|---|---|
| protected int resizeAt | |
| LongHashSet | back to summary |
|---|---|
| public LongHashSet() New instance with sane defaults.
| |
| LongHashSet | back to summary |
|---|---|
| public LongHashSet(int expectedElements) New instance with sane defaults.
| |
| LongHashSet | back to summary |
|---|---|
| public LongHashSet(int expectedElements, double loadFactor) New instance with the provided defaults.
| |
| LongHashSet | back to summary |
|---|---|
| public LongHashSet(LongContainer container) New instance copying elements from another | |
| add | back to summary |
|---|---|
| public boolean add(long key) Implements com. Doc from com. Adds
| |
| addAll | back to summary |
|---|---|
| public final int addAll(long... elements) Adds all elements from the given list (vararg) to this set.
| |
| addAll | back to summary |
|---|---|
| public int addAll(LongContainer container) Implements com. Adds all elements from the given
| |
| addAll | back to summary |
|---|---|
| public int addAll(Iterable<? extends LongCursor> iterable) Adds all elements from the given iterable to this set.
| |
| allocateBuffers | back to summary |
|---|---|
| protected void allocateBuffers(int arraySize) Allocate new internal buffers. This method attempts to allocate and assign internal buffers atomically (either allocations succeed or not). | |
| allocateThenInsertThenRehash | back to summary |
|---|---|
| protected void allocateThenInsertThenRehash(int slot, long pendingKey) This method is invoked when there is a new key to be inserted into the buffer but there is not enough empty slots to do so. New buffers are allocated. If this succeeds, we know we can proceed with rehashing so we assign the pending element to the previous buffer (possibly violating the invariant of having at least one empty slot) and rehash all keys, substituting new buffers at the end. | |
| clear | back to summary |
|---|---|
| public void clear() Implements com. Doc from com. Removes all elements from this collection.
| |
| clone | back to summary |
|---|---|
| public LongHashSet clone() Overrides java. Doc from java. Creates and returns a copy of this object. The precise meaning
of "copy" may depend on the class of the object. The general
intent is that, for any object will be true, and that the expression:x.clone() != x will bex.clone().getClass() == x.getClass() true, but these are not absolute requirements.
While it is typically the case that:
will bex.clone().equals(x) true, this is not an absolute requirement.
By convention, the returned object should be obtained by calling
By convention, the object returned by this method should be independent
of this object (which is being cloned). To achieve this independence,
it may be necessary to modify one or more fields of the object returned
by
| |
| contains | back to summary |
|---|---|
| public boolean contains(long key) Implements com. Doc from com. Lookup a given element in the container. This operation has no speed guarantees (may be linear with respect to the size of this container).
| |
| ensureCapacity | back to summary |
|---|---|
| public void ensureCapacity(int expectedElements) Implements com. Ensure this container can hold at least the given number of elements without resizing its buffers.
| |
| equals | back to summary |
|---|---|
| public boolean equals(Object obj) Overrides java. Doc from java. Indicates whether some other object is "equal to" this one.
The
An equivalence relation partitions the elements it operates on into equivalence classes; all the members of an equivalence class are equal to each other. Members of an equivalence class are substitutable for each other, at least for some purposes. | |
| forEach | back to summary |
|---|---|
| public <T extends LongProcedure> T forEach(T procedure) Implements com. Doc from com. Applies a
int count = container.forEach(new IntProcedure() {
int count; // this is a field declaration in an anonymous class.
public void apply(int value) {
count++;
}
}).count;
| |
| forEach | back to summary |
|---|---|
| public <T extends LongPredicate> T forEach(T predicate) Implements com. Doc from com. Applies a
int count = container.forEach(new IntProcedure() {
int count; // this is a field declaration in an anonymous class.
public void apply(int value) {
count++;
}
}).count;
| |
| from | back to summary |
|---|---|
| public static LongHashSet from(long... elements) Create a set from a variable number of arguments or an array of | |
| hashCode | back to summary |
|---|---|
| public int hashCode() Overrides java. Doc from java. Returns a hash code value for this object. This method is
supported for the benefit of hash tables such as those provided by
The general contract of
| |
| hashKey | back to summary |
|---|---|
| protected int hashKey(long key) Returns a hash code for the given key. The output from this function should evenly distribute keys across the entire integer range. | |
| indexExists | back to summary |
|---|---|
public boolean indexExists(int index)
| |
| indexGet | back to summary |
|---|---|
| public long indexGet(int index) Returns the exact value of the existing key. This method makes sense for sets of objects which define custom key-equality relationship.
| |
| indexInsert | back to summary |
|---|---|
| public void indexInsert(int index, long key) Inserts a key for an index that is not present in the set. This method may help in avoiding double recalculation of the key's hash.
| |
| indexOf | back to summary |
|---|---|
| public int indexOf(long key) Returns a logical "index" of a given key that can be used to speed up follow-up logic in certain scenarios (conditional logic). The semantics of "indexes" are not strictly defined. Indexes may (and typically won't be) contiguous. The index is valid only between modifications (it will not be affected by read-only operations).
| |
| indexRemove | back to summary |
|---|---|
| public void indexRemove(int index) Removes a key at an index previously acquired from
| |
| indexReplace | back to summary |
|---|---|
| public long indexReplace(int index, long equivalentKey) Replaces the existing equivalent key with the given one and returns any previous value stored for that key.
| |
| isEmpty | back to summary |
|---|---|
| public boolean isEmpty() Implements com. Doc from com. Shortcut for
| |
| iterator | back to summary |
|---|---|
| public Iterator Implements com. Doc from com. Returns an iterator to a cursor traversing the collection. The order of traversal is not defined. More than one cursor may be active at a time. The behavior of iterators is undefined if structural changes are made to the underlying collection. The iterator is implemented as a cursor and it returns the same cursor instance on
every call to
for (LongCursor<long> c : container) {
System.out.println("index=" + c.index + " value=" + c.value);
}
| |
| nextIterationSeed | back to summary |
|---|---|
| protected int nextIterationSeed() Provides the next iteration seed used to build the iteration starting slot and offset increment. This method does not need to be synchronized, what matters is that each thread gets a sequence of varying seeds. | |
| ramBytesAllocated | back to summary |
|---|---|
| public long ramBytesAllocated() Implements com. Doc from com. Allocated memory estimation
| |
| ramBytesUsed | back to summary |
|---|---|
| public long ramBytesUsed() Implements com. Doc from com. Bytes that is actually been used
| |
| rehash | back to summary |
|---|---|
| protected void rehash(long[] fromKeys) Rehash from old buffers to new buffers. | |
| release | back to summary |
|---|---|
| public void release() Implements com. Doc from com. Removes all elements from the collection and additionally releases any internal buffers.
Typically, if the object is to be reused, a simple
| |
| remove | back to summary |
|---|---|
| public boolean remove(long key) An alias for the (preferred) | |
| removeAll | back to summary |
|---|---|
| public int removeAll(long key) Implements com. Doc from com. Removes all occurrences of
| |
| removeAll | back to summary |
|---|---|
| public int removeAll(LongContainer other) Removes all keys present in a given container.
| |
| removeAll | back to summary |
|---|---|
| public int removeAll(LongPredicate predicate) Implements com. Doc from com. Removes all elements in this collection for which the given predicate returns
| |
| sameKeys | back to summary |
|---|---|
| private boolean sameKeys(LongSet other) Return true if all keys of some other container exist in this container. | |
| shiftConflictingKeys | back to summary |
|---|---|
| protected void shiftConflictingKeys(int gapSlot) Shift all the slot-conflicting keys allocated to (and including) | |
| size | back to summary |
|---|---|
| public int size() Implements com. Doc from com. Return the current number of elements in this container. The time for calculating the
container's size may take
| |
| toArray | back to summary |
|---|---|
| public long[] toArray() Overrides com. Implements com. Doc from com. Copies all elements of this container to an array. The returned array is always a copy, regardless of the storage used by the container.
| |
| verifyLoadFactor | back to summary |
|---|---|
| protected double verifyLoadFactor(double loadFactor) Validate load factor range and return it. Override and suppress if you need insane load factors. | |
| visualizeKeyDistribution | back to summary |
|---|---|
| public String visualizeKeyDistribution(int characters) Implements com. Doc from com. Visually depict the distribution of keys.
| |
iterator.
| Modifier and Type | Field and Description |
|---|---|
| private final LongCursor | |
| private final int | |
| private int | |
| private int |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| protected LongCursor |
| cursor | back to summary |
|---|---|
| private final LongCursor cursor | |
| increment | back to summary |
|---|---|
| private final int increment | |
| index | back to summary |
|---|---|
| private int index | |
| slot | back to summary |
|---|---|
| private int slot | |
| EntryIterator | back to summary |
|---|---|
| public EntryIterator() | |
| fetch | back to summary |
|---|---|
| protected LongCursor fetch() Implements abstract com. Doc from com. Fetch next element. The implementation must return
| |