com.carrotsearch.hppc
Class LongHashSet
- java.lang.Object
-
- com.carrotsearch.hppc.LongHashSet
-
- All Implemented Interfaces:
- LongCollection, LongContainer, LongLookupContainer, LongSet, Preallocable, java.lang.Cloneable, java.lang.Iterable<LongCursor>
- Direct Known Subclasses:
- LongScatterSet
@Generated(date="2015-05-07T09:33:03+0200", value="KTypeHashSet.java") public class LongHashSet extends java.lang.Object implements LongLookupContainer, LongSet, Preallocable, java.lang.CloneableA hash set oflongs, implemented using using open addressing with linear probing for collision resolution.Note: read about important differences between hash and scatter sets.
- See Also:
LongScatterSet, HPPC interfaces diagram
-
-
Field Summary
Fields Modifier and Type Field and Description long[]keysThe hash array holding keys.
-
Constructor Summary
Constructors Constructor and Description LongHashSet()New instance with sane defaults.LongHashSet(int expectedElements)New instance with sane defaults.LongHashSet(int expectedElements, double loadFactor)New instance with sane defaults.LongHashSet(int expectedElements, double loadFactor, HashOrderMixingStrategy orderMixer)New instance with the provided defaults.LongHashSet(LongContainer container)New instance copying elements from anotherLongContainer.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method and Description booleanadd(long key)Addskto the set.intaddAll(java.lang.Iterable<? extends LongCursor> iterable)Adds all elements from the given iterable to this set.intaddAll(long... elements)Adds all elements from the given list (vararg) to this set.intaddAll(LongContainer container)Adds all elements from the givenLongContainerto this set.voidclear()Removes all elements from this collection.LongHashSetclone()booleancontains(long key)Lookup a given element in the container.voidensureCapacity(int expectedElements)Ensure this container can hold at least the given number of elements without resizing its buffers.booleanequals(java.lang.Object obj)<T extends LongPredicate>
TforEach(T predicate)Applies apredicateto container elements as long, as the predicate returnstrue.<T extends LongProcedure>
TforEach(T procedure)Applies aprocedureto all container elements.static LongHashSetfrom(long... elements)Create a set from a variable number of arguments or an array oflong.inthashCode()booleanindexExists(int index)longindexGet(int index)Returns the exact value of the existing key.voidindexInsert(int index, long key)Inserts a key for an index that is not present in the set.intindexOf(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).longindexReplace(int index, long equivalentKey)Replaces the existing equivalent key with the given one and returns any previous value stored for that key.booleanisEmpty()Shortcut forsize() == 0.java.util.Iterator<LongCursor>iterator()Returns an iterator to a cursor traversing the collection.voidrelease()Removes all elements from the collection and additionally releases any internal buffers.booleanremove(long key)An alias for the (preferred)removeAll(long).intremoveAll(long key)Removes all occurrences ofefrom this collection.intremoveAll(LongLookupContainer c)Default implementation uses a predicate for removal.intremoveAll(LongPredicate predicate)Removes all elements in this collection for which the given predicate returnstrue.intretainAll(LongLookupContainer c)Default implementation uses a predicate for retaining.intretainAll(LongPredicate predicate)Default implementation redirects toLongCollection.removeAll(LongPredicate)and negates the predicate.intsize()Return the current number of elements in this container.long[]toArray()Default implementation of copying to an array.java.lang.StringtoString()Convert the contents of this container to a human-friendly string.java.lang.StringvisualizeKeyDistribution(int characters)Visually depict the distribution of keys.-
Methods inherited from interface com.carrotsearch.hppc.LongCollection
removeAll, retainAll, retainAll
-
-
-
-
Constructor Detail
-
LongHashSet
public LongHashSet()
New instance with sane defaults.
-
LongHashSet
public LongHashSet(int expectedElements)
New instance with sane defaults.
-
LongHashSet
public LongHashSet(int expectedElements, double loadFactor)New instance with sane defaults.
-
LongHashSet
public LongHashSet(int expectedElements, double loadFactor, HashOrderMixingStrategy orderMixer)New instance with the provided defaults.- Parameters:
expectedElements- The expected number of elements guaranteed not to cause a rehash (inclusive).loadFactor- The load factor for internal buffers. Insane load factors (zero, full capacity) are rejected byverifyLoadFactor(double).orderMixer- Hash key order mixing strategy. SeeHashOrderMixingfor predefined implementations. Use constant mixers only if you understand the potential consequences.
-
LongHashSet
public LongHashSet(LongContainer container)
New instance copying elements from anotherLongContainer.
-
-
Method Detail
-
add
public boolean add(long key)
Addskto the set.
-
addAll
public final int addAll(long... elements)
Adds all elements from the given list (vararg) to this set.- Returns:
- Returns the number of elements actually added as a result of this call (not previously present in the set).
-
addAll
public int addAll(LongContainer container)
Adds all elements from the givenLongContainerto this set.- Returns:
- Returns the number of elements actually added as a result of this call (not previously present in the set).
-
addAll
public int addAll(java.lang.Iterable<? extends LongCursor> iterable)
Adds all elements from the given iterable to this set.- Returns:
- Returns the number of elements actually added as a result of this call (not previously present in the set).
-
toArray
public long[] toArray()
Default implementation of copying to an array.- Specified by:
toArrayin interfaceLongContainer
-
remove
public boolean remove(long key)
An alias for the (preferred)removeAll(long).
-
removeAll
public int removeAll(long key)
Removes all occurrences ofefrom this collection.- Specified by:
removeAllin interfaceLongCollection- Parameters:
key- Element to be removed from this collection, if present.- Returns:
- The number of removed elements as a result of this call.
-
removeAll
public int removeAll(LongPredicate predicate)
Removes all elements in this collection for which the given predicate returnstrue.- Specified by:
removeAllin interfaceLongCollection- Returns:
- Returns the number of removed elements.
-
contains
public boolean contains(long key)
Lookup a given element in the container. This operation has no speed guarantees (may be linear with respect to the size of this container).- Specified by:
containsin interfaceLongContainer- Specified by:
containsin interfaceLongLookupContainer- Returns:
- Returns
trueif this container has an element equal toe.
-
clear
public void clear()
Removes all elements from this collection.- Specified by:
clearin interfaceLongCollection- See Also:
LongCollection.release()
-
release
public void release()
Removes all elements from the collection and additionally releases any internal buffers. Typically, if the object is to be reused, a simpleLongCollection.clear()should be a better alternative since it'll avoid reallocation.- Specified by:
releasein interfaceLongCollection- See Also:
LongCollection.clear()
-
isEmpty
public boolean isEmpty()
Shortcut forsize() == 0.- Specified by:
isEmptyin interfaceLongContainer
-
ensureCapacity
public void ensureCapacity(int expectedElements)
Ensure this container can hold at least the given number of elements without resizing its buffers.- Specified by:
ensureCapacityin interfacePreallocable- Parameters:
expectedElements- The total number of elements, inclusive.
-
size
public int size()
Return the current number of elements in this container. The time for calculating the container's size may takeO(n)time, although implementing classes should try to maintain the current size and return in constant time.- Specified by:
sizein interfaceLongContainer
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
equals
public boolean equals(java.lang.Object obj)
- Overrides:
equalsin classjava.lang.Object
-
clone
public LongHashSet clone()
- Overrides:
clonein classjava.lang.Object
-
iterator
public java.util.Iterator<LongCursor> iterator()
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
Iterator.next()(to avoid boxing of primitive types). To read the current list's value (or index in the list) use the cursor's public fields. An example is shown below.for (LongCursor<long> c : container) { System.out.println("index=" + c.index + " value=" + c.value); }- Specified by:
iteratorin interfaceLongContainer- Specified by:
iteratorin interfacejava.lang.Iterable<LongCursor>
-
forEach
public <T extends LongProcedure> T forEach(T procedure)
Applies aprocedureto all container elements. Returns the argument (any subclass ofLongProcedure. This lets the caller to call methods of the argument by chaining the call (even if the argument is an anonymous type) to retrieve computed values, for example (IntContainer):int count = container.forEach(new IntProcedure() { int count; // this is a field declaration in an anonymous class. public void apply(int value) { count++; } }).count;- Specified by:
forEachin interfaceLongContainer
-
forEach
public <T extends LongPredicate> T forEach(T predicate)
Applies apredicateto container elements as long, as the predicate returnstrue. The iteration is interrupted otherwise.- Specified by:
forEachin interfaceLongContainer
-
from
public static LongHashSet from(long... elements)
Create a set from a variable number of arguments or an array oflong. The elements are copied from the argument to the internal buffer.
-
indexOf
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).- Parameters:
key- The key to locate in the set.- 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.
- See Also:
indexExists(int),indexGet(int),indexInsert(int, long),indexReplace(int, long)
-
indexExists
public boolean indexExists(int index)
- Parameters:
index- The index of a given key, as returned fromindexOf(long).- Returns:
- Returns
trueif 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). - See Also:
indexOf(long)
-
indexGet
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.- Parameters:
index- The index of an existing key.- Returns:
- Returns the equivalent key currently stored in the set.
- Throws:
java.lang.AssertionError- If assertions are enabled and the index does not correspond to an existing key.- See Also:
indexOf(long)
-
indexReplace
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.- Parameters:
index- The index of an existing key.equivalentKey- The key to put in the set as a replacement. Must be equivalent to the key currently stored at the provided index.- Returns:
- Returns the previous key stored in the set.
- Throws:
java.lang.AssertionError- If assertions are enabled and the index does not correspond to an existing key.- See Also:
indexOf(long)
-
indexInsert
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.- Parameters:
index- The index of a previously non-existing key, as returned fromindexOf(long).- Throws:
java.lang.AssertionError- If assertions are enabled and the index does not correspond to an existing key.- See Also:
indexOf(long)
-
visualizeKeyDistribution
public java.lang.String visualizeKeyDistribution(int characters)
Description copied from interface:LongSetVisually depict the distribution of keys.- Specified by:
visualizeKeyDistributionin interfaceLongSet- Parameters:
characters- The number of characters to "squeeze" the entire buffer into.- Returns:
- Returns a sequence of characters where '.' depicts an empty fragment of the internal buffer and 'X' depicts full or nearly full capacity within the buffer's range and anything between 1 and 9 is between.
-
removeAll
public int removeAll(LongLookupContainer c)
Default implementation uses a predicate for removal.- Specified by:
removeAllin interfaceLongCollection- Returns:
- Returns the number of removed elements.
-
retainAll
public int retainAll(LongLookupContainer c)
Default implementation uses a predicate for retaining.- Specified by:
retainAllin interfaceLongCollection- Returns:
- Returns the number of removed elements.
-
retainAll
public int retainAll(LongPredicate predicate)
Default implementation redirects toLongCollection.removeAll(LongPredicate)and negates the predicate.- Specified by:
retainAllin interfaceLongCollection- Returns:
- Returns the number of removed elements.
-
toString
public java.lang.String toString()
Convert the contents of this container to a human-friendly string.- Overrides:
toStringin classjava.lang.Object
-
-
DataMelt 3.0 © DataMelt by jWork.ORG