|
Jive Forums API (5.5.20.2-oracle) Developer Javadocs | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.jivesoftware.util.LongHashMap
public final class LongHashMap
Hash map holding (key,value) associations of type (long-->Object); Automatically grows and shrinks as needed; Implemented using open addressing with double hashing.
Adapted from the Colt package by CoolServlets. Please visit the Colt homepage at: http://tilde-hoschek.home.cern.ch/~hoschek/colt/index.htm
Field Summary | |
---|---|
protected static int |
DEFAULT_CAPACITY
|
protected static double |
DEFAULT_MAX_LOAD_FACTOR
|
protected static double |
DEFAULT_MIN_LOAD_FACTOR
|
protected int |
distinct
|
protected static byte |
FREE
|
protected int |
freeEntries
|
protected static byte |
FULL
|
protected int |
highWaterMark
|
static int |
LARGEST_PRIME
The largest prime this class can generate; currently equal to Integer.MAX_VALUE. |
protected int |
lowWaterMark
The table capacity c=table.length always satisfies the invariant c * minLoadFactor <= s <= c * maxLoadFactor, where s=size() is the number of associations currently contained. |
protected double |
maxLoadFactor
|
protected double |
minLoadFactor
|
protected static byte |
REMOVED
|
protected byte[] |
state
|
protected long[] |
table
|
protected java.lang.Object[] |
values
|
Constructor Summary | |
---|---|
LongHashMap()
Constructs an empty map with default capacity and default load factors. |
|
LongHashMap(int initialCapacity)
Constructs an empty map with the specified initial capacity and default load factors. |
|
LongHashMap(int initialCapacity,
double minLoadFactor,
double maxLoadFactor)
Constructs an empty map with the specified initial capacity and the specified minimum and maximum load factor. |
Method Summary | |
---|---|
protected int |
chooseLowWaterMark(int capacity,
double minLoad)
Returns new low water mark threshold based on current capacity and minLoadFactor. |
protected int |
chooseMeanCapacity(int size,
double minLoad,
double maxLoad)
Chooses a new prime table capacity neither favoring shrinking nor growing, that (approximately) satisfies the invariant c * minLoadFactor <= size <= c * maxLoadFactor and has at least one FREE slot for the given size. |
protected int |
chooseShrinkCapacity(int size,
double minLoad,
double maxLoad)
Chooses a new prime table capacity optimized for shrinking that (approximately) satisfies the invariant c * minLoadFactor <= size <= c * maxLoadFactor and has at least one FREE slot for the given size. |
void |
clear()
Removes all (key,value) associations from the receiver. |
boolean |
containsKey(long key)
Returns true if the receiver contains the specified key. |
boolean |
containsValue(java.lang.Object value)
Returns true if the receiver contains the specified value. |
void |
ensureCapacity(int minCapacity)
Ensures that the receiver can hold at least the specified number of associations without needing to allocate new internal memory. |
java.lang.Object |
get(long key)
Returns the value associated with the specified key. |
protected int |
indexOfValue(java.lang.Object value)
|
boolean |
isEmpty()
Returns true if the receiver contains no (key,value) associations. |
long |
keyOf(java.lang.Object value)
Returns the first key the given value is associated with. |
long[] |
keys()
Returns all the keys in the map. |
protected int |
nextPrime(int desiredCapacity)
Returns a prime number which is >= desiredCapacity and
very close to desiredCapacity (within 11% if
desiredCapacity >= 1000 ). |
boolean |
put(long key,
java.lang.Object value)
Associates the given key with the given value. |
protected void |
rehash(int newCapacity)
Rehashes the contents of the receiver into a new table with a smaller or larger capacity. |
boolean |
removeKey(long key)
Removes the given key with its associated element from the receiver, if present. |
protected void |
setUp(int initialCapacity,
double minLoadFactor,
double maxLoadFactor)
Initializes the receiver. |
int |
size()
Returns the number of (key,value) associations currently contained. |
void |
trimToSize()
Trims the capacity of the receiver to be the receiver's current size. |
java.lang.Object[] |
values()
Returns an array of all the values in the Map. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected long[] table
protected java.lang.Object[] values
protected byte[] state
protected int freeEntries
protected int distinct
protected int lowWaterMark
protected int highWaterMark
protected double minLoadFactor
protected double maxLoadFactor
protected static final int DEFAULT_CAPACITY
protected static final double DEFAULT_MIN_LOAD_FACTOR
protected static final double DEFAULT_MAX_LOAD_FACTOR
protected static final byte FREE
protected static final byte FULL
protected static final byte REMOVED
public static final int LARGEST_PRIME
Constructor Detail |
---|
public LongHashMap()
public LongHashMap(int initialCapacity)
initialCapacity
- the initial capacity of the map.
java.lang.IllegalArgumentException
- if the initial capacity is less
than zero.public LongHashMap(int initialCapacity, double minLoadFactor, double maxLoadFactor)
initialCapacity
- the initial capacity.minLoadFactor
- the minimum load factor.maxLoadFactor
- the maximum load factor.
java.lang.IllegalArgumentException
- if initialCapacity < 0 ||
(minLoadFactor < 0.0 || minLoadFactor >= 1.0) ||
(maxLoadFactor <= 0.0 || maxLoadFactor >= 1.0) ||
(minLoadFactor >= maxLoadFactor).Method Detail |
---|
public void clear()
public boolean containsKey(long key)
public boolean containsValue(java.lang.Object value)
public void ensureCapacity(int minCapacity)
This method never need be called; it is for performance tuning only. Calling this method before put()ing a large number of associations boosts performance, because the receiver will grow only once instead of potentially many times and hash collisions get less probable.
minCapacity
- the desired minimum capacity.public final java.lang.Object get(long key)
containsKey(long)
whether the given key has a value associated or not, i.e. whether there
exists an association for the given key or not.
key
- the key to be searched for.
protected int indexOfValue(java.lang.Object value)
value
- the value to be searched in the receiver.
public long keyOf(java.lang.Object value)
value
- the value to search for.
public long[] keys()
public boolean put(long key, java.lang.Object value)
key
- the key the value shall be associated with.value
- the value to be associated.
public int size()
public boolean isEmpty()
protected void rehash(int newCapacity)
public boolean removeKey(long key)
key
- the key to be removed from the receiver.
protected void setUp(int initialCapacity, double minLoadFactor, double maxLoadFactor)
initialCapacity
- the initial capacity of the receiver.minLoadFactor
- the minLoadFactor of the receiver.maxLoadFactor
- the maxLoadFactor of the receiver.
java.lang.IllegalArgumentException
- if initialCapacity < 0 ||
(minLoadFactor < 0.0 || minLoadFactor >= 1.0) ||
(maxLoadFactor <= 0.0 || maxLoadFactor >= 1.0) ||
(minLoadFactor >= maxLoadFactor).public void trimToSize()
public java.lang.Object[] values()
protected int chooseLowWaterMark(int capacity, double minLoad)
protected int chooseMeanCapacity(int size, double minLoad, double maxLoad)
protected int chooseShrinkCapacity(int size, double minLoad, double maxLoad)
protected int nextPrime(int desiredCapacity)
>= desiredCapacity
and
very close to desiredCapacity
(within 11% if
desiredCapacity >= 1000
).
desiredCapacity
- the capacity desired by the user.
|
Jive Forums Project Page | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |