|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.carrotsearch.hppc.ShortOpenHashSet
@Generated(date="2011-11-28T23:36:05+0000", value="HPPC generated from: ShortOpenHashSet.java") public class ShortOpenHashSet
A hash set of short
s, implemented using using open
addressing with linear probing for collision resolution.
The internal buffers of this implementation (keys
), allocated
)
are always allocated to the nearest size that is a power of two. When
the capacity exceeds the given load factor, the buffer size is doubled.
See ObjectOpenHashSet
class for API similarities and differences against Java
Collections.
Important node. The implementation uses power-of-two tables and linear
probing, which may cause poor performance (many collisions) if hash values are
not properly distributed.
This implementation uses MurmurHash3
for rehashing keys.
Field Summary | |
---|---|
boolean[] |
allocated
Information if an entry (slot) in the keys table is allocated
or empty. |
int |
assigned
Cached number of assigned slots in allocated . |
static int |
DEFAULT_CAPACITY
Default capacity. |
static float |
DEFAULT_LOAD_FACTOR
Default load factor. |
short[] |
keys
Hash-indexed array holding all set entries. |
float |
loadFactor
The load factor for this set (fraction of allocated or deleted slots before the buffers must be rehashed or reallocated). |
static int |
MIN_CAPACITY
Minimum capacity for the set. |
Constructor Summary | |
---|---|
ShortOpenHashSet()
Creates a hash set with the default capacity of 16, load factor of 0.75f. |
|
ShortOpenHashSet(int initialCapacity)
Creates a hash set with the given capacity, load factor of 0.75f. |
|
ShortOpenHashSet(int initialCapacity,
float loadFactor)
Creates a hash set with the given capacity and load factor. |
|
ShortOpenHashSet(ShortContainer container)
Creates a hash set from elements of another container. |
Method Summary | ||
---|---|---|
int |
add(short... elements)
Vararg-signature method for adding elements to this set. |
|
boolean |
add(short e)
Adds k to the set. |
|
int |
add(short e1,
short e2)
Adds two elements to the set. |
|
int |
addAll(java.lang.Iterable<? extends ShortCursor> iterable)
Adds all elements from a given iterable to this set. |
|
int |
addAll(ShortContainer container)
Adds all elements from a given container to this set. |
|
void |
clear()
Removes all elements from this collection. |
|
ShortOpenHashSet |
clone()
|
|
boolean |
contains(short key)
Lookup a given element in the container. |
|
boolean |
equals(java.lang.Object obj)
Compares the specified object with this set for equality. |
|
|
forEach(T predicate)
Applies a predicate to container elements as long, as the predicate
returns true . |
|
|
forEach(T procedure)
Applies a procedure to all container elements. |
|
static ShortOpenHashSet |
from(short... elements)
Create a set from a variable number of arguments or an array of short . |
|
static ShortOpenHashSet |
from(ShortContainer container)
Create a set from elements of another container. |
|
int |
hashCode()
|
|
boolean |
isEmpty()
Shortcut for size() == 0 . |
|
java.util.Iterator<ShortCursor> |
iterator()
Returns an iterator to a cursor traversing the collection. |
|
short |
lget()
Returns the last value saved in a call to contains(short) . |
|
static ShortOpenHashSet |
newInstance()
Returns a new object of this class with no need to declare generic type (shortcut instead of using a constructor). |
|
static ShortOpenHashSet |
newInstanceWithCapacity(int initialCapacity,
float loadFactor)
Returns a new object of this class with no need to declare generic type (shortcut instead of using a constructor). |
|
protected int |
nextCapacity(int current)
Return the next possible capacity, counting from the current buffers' size. |
|
boolean |
remove(short key)
An alias for the (preferred) removeAllOccurrences(short) . |
|
int |
removeAll(ShortLookupContainer c)
Default implementation uses a predicate for removal. |
|
int |
removeAll(ShortPredicate predicate)
Removes all elements in this collection for which the given predicate returns true . |
|
int |
removeAllOccurrences(short key)
Removes all occurrences of e from this collection. |
|
int |
retainAll(ShortLookupContainer c)
Default implementation uses a predicate for retaining. |
|
int |
retainAll(ShortPredicate predicate)
Default implementation redirects to ShortCollection.removeAll(ShortPredicate)
and negates the predicate. |
|
protected int |
roundCapacity(int requestedCapacity)
Round the capacity to the next allowed value. |
|
protected void |
shiftConflictingKeys(int slotCurr)
Shift all the slot-conflicting keys allocated to (and including) slot . |
|
int |
size()
Return the current number of elements in this container. |
|
short[] |
toArray()
Default implementation of copying to an array. |
|
java.lang.String |
toString()
Convert the contents of this container to a human-friendly string. |
Methods inherited from class java.lang.Object |
---|
finalize, getClass, notify, notifyAll, wait, wait, wait |
Methods inherited from interface com.carrotsearch.hppc.ShortCollection |
---|
removeAll, retainAll, retainAll |
Field Detail |
---|
public static final int DEFAULT_CAPACITY
public static final int MIN_CAPACITY
public static final float DEFAULT_LOAD_FACTOR
public short[] keys
allocated
public boolean[] allocated
keys
table is allocated
or empty.
assigned
public int assigned
allocated
.
public final float loadFactor
Constructor Detail |
---|
public ShortOpenHashSet()
public ShortOpenHashSet(int initialCapacity)
public ShortOpenHashSet(int initialCapacity, float loadFactor)
public ShortOpenHashSet(ShortContainer container)
Method Detail |
---|
public boolean add(short e)
k
to the set.
add
in interface ShortSet
true
if this element was not part of the set before. Returns
false
if an equal element is part of the set, and replaces the existing
equal element with the argument (if keys are object types).public int add(short e1, short e2)
public int add(short... elements)
This method is handy, but costly if used in tight loops (anonymous array passing)
public final int addAll(ShortContainer container)
public final int addAll(java.lang.Iterable<? extends ShortCursor> iterable)
public int removeAllOccurrences(short key)
e
from this collection.
removeAllOccurrences
in interface ShortCollection
key
- Element to be removed from this collection, if present.
public boolean remove(short key)
removeAllOccurrences(short)
.
protected final void shiftConflictingKeys(int slotCurr)
slot
.
public short lget()
contains(short)
.
contains(short)
public boolean contains(short key)
Saves the associated value for fast access using lget()
.
if (map.contains(key)) value = map.lget();
contains
in interface ShortContainer
contains
in interface ShortLookupContainer
true
if this container has an element
equal to e
.protected int roundCapacity(int requestedCapacity)
protected int nextCapacity(int current)
public void clear()
Does not release internal buffers.
clear
in interface ShortCollection
public int size()
O(n)
time, although implementing classes
should try to maintain the current size and return in constant time.
size
in interface ShortContainer
public boolean isEmpty()
size() == 0
.
isEmpty
in interface ShortContainer
public int hashCode()
hashCode
in interface ShortSet
hashCode
in class java.lang.Object
Set.hashCode()
(sum of hash codes of elements
within the set). Because sum is commutative, this ensures that different order
of elements in a set does not affect the hash code.public boolean equals(java.lang.Object obj)
ObjectSet
and both objects contains exactly the same objects.
equals
in interface ShortSet
equals
in class java.lang.Object
public java.util.Iterator<ShortCursor> iterator()
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 (ShortCursor<short> c : container) { System.out.println("index=" + c.index + " value=" + c.value); }
iterator
in interface ShortContainer
iterator
in interface java.lang.Iterable<ShortCursor>
public <T extends ShortProcedure> T forEach(T procedure)
procedure
to all container elements. Returns the argument (any
subclass of ShortProcedure
. 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;
forEach
in interface ShortContainer
public final short[] toArray()
toArray
in interface ShortContainer
public ShortOpenHashSet clone()
clone
in class java.lang.Object
public <T extends ShortPredicate> T forEach(T predicate)
predicate
to container elements as long, as the predicate
returns true
. The iteration is interrupted otherwise.
forEach
in interface ShortContainer
public int removeAll(ShortPredicate predicate)
true
.
removeAll
in interface ShortCollection
public static ShortOpenHashSet from(short... elements)
short
.
The elements are copied from the argument to the internal buffer.
public static ShortOpenHashSet from(ShortContainer container)
public static ShortOpenHashSet newInstance()
public static ShortOpenHashSet newInstanceWithCapacity(int initialCapacity, float loadFactor)
public int removeAll(ShortLookupContainer c)
removeAll
in interface ShortCollection
public int retainAll(ShortLookupContainer c)
retainAll
in interface ShortCollection
public int retainAll(ShortPredicate predicate)
ShortCollection.removeAll(ShortPredicate)
and negates the predicate.
retainAll
in interface ShortCollection
public java.lang.String toString()
toString
in class java.lang.Object
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |