Class OpenHashMap<K,V>
- All Implemented Interfaces:
Serializable
,Cloneable
,Map<K,
,V> SequencedMap<K,
,V> SortedMap<K,
V>
- Direct Known Subclasses:
OpenHashMapList
,OpenHashMapSet
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
static class
private class
private class
private final class
private final class
(package private) final class
private final class
private class
private final class
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected boolean
protected V
protected final float
protected int
protected Object[]
protected int
protected long[]
protected int
protected int
protected int
private static final long
protected int
protected 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 int
arraySize
(int expected, float f) private void
void
clear()
clone()
Comparator
<? super K> protected V
boolean
boolean
void
defaultReturnValue
(V rv) private void
ensureCapacity
(int capacity) entrySet()
boolean
fast()
firstKey()
protected void
fixPointers
(int i) protected void
fixPointers
(int s, int d) getOrCompute
(K k) int
hashCode()
private int
boolean
isEmpty()
keySet()
lastKey()
private static int
maxFill
(int n, float f) private static int
mix
(int x) private void
moveIndexToFirst
(int i) private void
moveIndexToLast
(int i) private static int
nextPowerOfTwo
(int x) private static long
nextPowerOfTwo
(long x) void
putAndMoveToFirst
(K k, V v) putAndMoveToLast
(K k, V v) private void
private int
realSize()
protected void
rehash
(int newN) Rehashes the map.private V
removeEntry
(int pos) private V
private V
protected final void
shiftKeys
(int pos) int
size()
toString()
boolean
trim()
Rehashes the map, making the table as small as possible.boolean
trim
(int n) Rehashes this map if the table is too large.private void
tryCapacity
(long capacity) private static <K> int
private static <K> int
values()
private void
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.util.Map
compute, computeIfAbsent, computeIfPresent, forEach, getOrDefault, merge, putIfAbsent, remove, replace, replace, replaceAll
Methods inherited from interface java.util.SequencedMap
firstEntry, lastEntry, pollFirstEntry, pollLastEntry, sequencedEntrySet, sequencedKeySet, sequencedValues
-
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:
containsKey
in interfaceMap<K,
V>
-
containsValue
- Specified by:
containsValue
in 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:
comparator
in 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:
IOException
ClassNotFoundException
-
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
-