Class OpenHashMap<K,V>
- All Implemented Interfaces:
Serializable,Cloneable,Map<K,,V> SortedMap<K,V>
- Direct Known Subclasses:
OpenHashMapList,OpenHashMapSet
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classstatic classprivate classprivate classprivate final classprivate final class(package private) final classprivate final classprivate classprivate final class -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected booleanprotected Vprotected final floatprotected intprotected Object[]protected intprotected long[]protected intprotected intprotected intprivate static final longprotected intprotected Object[]protected Collection<V> -
Constructor Summary
ConstructorsConstructorDescriptionOpenHashMap(int expected) OpenHashMap(int expected, float f) OpenHashMap(Map<? extends K, ? extends V> m) OpenHashMap(Map<? extends K, ? extends V> m, float f) OpenHashMap(K[] k, V[] v) OpenHashMap(K[] k, V[] v, float f) -
Method Summary
Modifier and TypeMethodDescriptionprivate static intarraySize(int expected, float f) private voidvoidclear()clone()Comparator<? super K> protected VbooleanbooleanvoiddefaultReturnValue(V rv) private voidensureCapacity(int capacity) entrySet()booleanfast()firstKey()protected voidfixPointers(int i) protected voidfixPointers(int s, int d) getOrCompute(K k) inthashCode()private intbooleanisEmpty()keySet()lastKey()private static intmaxFill(int n, float f) private static intmix(int x) private voidmoveIndexToFirst(int i) private voidmoveIndexToLast(int i) private static intnextPowerOfTwo(int x) private static longnextPowerOfTwo(long x) voidputAndMoveToFirst(K k, V v) putAndMoveToLast(K k, V v) private voidprivate intrealSize()protected voidrehash(int newN) Rehashes the map.private VremoveEntry(int pos) private Vprivate Vprotected final voidshiftKeys(int pos) intsize()toString()booleantrim()Rehashes the map, making the table as small as possible.booleantrim(int n) Rehashes this map if the table is too large.private voidtryCapacity(long capacity) private static <K> intprivate static <K> intvalues()private voidMethods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.util.Map
compute, computeIfAbsent, computeIfPresent, forEach, getOrDefault, merge, putIfAbsent, remove, replace, replace, replaceAll
-
Field Details
-
serialVersionUID
private static final long serialVersionUID- See Also:
-
key
-
value
-
mask
protected transient int mask -
containsNullKey
protected transient boolean containsNullKey -
first
protected transient int first -
last
protected transient int last -
link
protected transient long[] link -
n
protected transient int n -
maxFill
protected transient int maxFill -
size
protected int size -
f
protected final float f -
defRetValue
-
fast
-
entries
-
keys
-
values
-
-
Constructor Details
-
OpenHashMap
public OpenHashMap(int expected, float f) -
OpenHashMap
public OpenHashMap(int expected) -
OpenHashMap
public OpenHashMap() -
OpenHashMap
-
OpenHashMap
-
OpenHashMap
-
OpenHashMap
-
-
Method Details
-
defaultReturnValue
-
defaultReturnValue
-
equals
-
toString
-
realSize
private int realSize() -
ensureCapacity
private void ensureCapacity(int capacity) -
tryCapacity
private void tryCapacity(long capacity) -
removeEntry
-
removeNullEntry
-
putAll
-
insert
-
put
-
getOrCompute
-
compute
-
shiftKeys
protected final void shiftKeys(int pos) -
remove
-
setValue
-
removeFirst
-
removeLast
-
moveIndexToFirst
private void moveIndexToFirst(int i) -
moveIndexToLast
private void moveIndexToLast(int i) -
getAndMoveToFirst
-
getAndMoveToLast
-
putAndMoveToFirst
-
putAndMoveToLast
-
get
-
containsKey
- Specified by:
containsKeyin interfaceMap<K,V>
-
containsValue
- Specified by:
containsValuein interfaceMap<K,V>
-
clear
public void clear() -
size
public int size() -
isEmpty
public boolean isEmpty() -
fixPointers
protected void fixPointers(int i) -
fixPointers
protected void fixPointers(int s, int d) -
firstKey
-
lastKey
-
comparator
- Specified by:
comparatorin interfaceSortedMap<K,V>
-
tailMap
-
headMap
-
subMap
-
fast
-
entrySet
-
keySet
-
values
-
trim
public boolean trim()Rehashes the map, making the table as small as possible.This method rehashes the table to the smallest size satisfying the load factor. It can be used when the set will not be changed anymore, so to optimize access speed and size.
If the table size is already the minimum possible, this method does nothing.
- Returns:
- true if there was enough memory to trim the map.
- See Also:
-
trim
public boolean trim(int n) Rehashes this map if the table is too large.Let N be the smallest table size that can hold
max(n,entries, still satisfying the load factor. If the current table size is smaller than or equal to N, this method does nothing. Otherwise, it rehashes this map in a table of size N.size())This method is useful when reusing maps. Clearing a map leaves the table size untouched. If you are reusing a map many times, you can call this method with a typical size to avoid keeping around a very large table just because of a few large transient maps.
- Parameters:
n- the threshold for the trimming.- Returns:
- true if there was enough memory to trim the map.
- See Also:
-
rehash
protected void rehash(int newN) Rehashes the map.This method implements the basic rehashing strategy, and may be overriden by subclasses implementing different rehashing strategies (e.g., disk-based rehashing). However, you should not override this method unless you understand the internal workings of this class.
- Parameters:
newN- the new size
-
clone
-
hashCode
public int hashCode() -
writeObject
- Throws:
IOException
-
readObject
- Throws:
IOExceptionClassNotFoundException
-
checkTable
private void checkTable() -
arraySize
private static int arraySize(int expected, float f) -
maxFill
private static int maxFill(int n, float f) -
nextPowerOfTwo
private static int nextPowerOfTwo(int x) -
nextPowerOfTwo
private static long nextPowerOfTwo(long x) -
mix
private static int mix(int x) -
unwrap
-
unwrap
-