Package org.kingdoms.utils.internal
Class UnsafeHashMap<K,V>
java.lang.Object
org.kingdoms.utils.internal.UnsafeHashMap<K,V>
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classfinal classstatic final classclassstatic classfinal classfinal classstatic final classstatic classstatic final classEntry for Tree bins.final classstatic final class -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intstatic final floatfinal floatstatic final intstatic final intUnsafeHashMap.Node<K,V>[] static final intstatic final int -
Constructor Summary
ConstructorsConstructorDescriptionConstructs an empty HashMap with the default initial capacity (16) and the default load factor (0.75).UnsafeHashMap(int initialCapacity) Constructs an empty HashMap with the specified initial capacity and the default load factor (0.75).UnsafeHashMap(int initialCapacity, float loadFactor) UnsafeHashMap(Map<? extends K, ? extends V> m) Constructs a new HashMap with the same mappings as the specified Map. -
Method Summary
Modifier and TypeMethodDescriptionfinal intcapacity()voidclear()Removes all of the mappings from this map.clone()Returns a shallow copy of this HashMap instance: the keys and values themselves are not cloned.static Class<?>static intcompareComparables(Class<?> kc, Object k, Object x) @Nullable VcomputeIfAbsent(@NonNull K key, @NonNull Function<? super K, ? extends V> mappingFunction) computeIfPresent(@NonNull K key, @NonNull BiFunction<? super K, ? super V, ? extends V> remappingFunction) booleancontainsKey(@NonNull Object key) booleancontainsValue(@NonNull Object value) Returns true if this map maps one or more keys to the specified value.entrySet()voidforEach(BiConsumer<? super K, ? super V> action) @Nullable UnsafeHashMap.Node<K,V> @Nullable VgetOrDefault(@NonNull Object key, @Nullable V defaultValue) static intvoidbooleanisEmpty()keySet()merge(@NonNull K key, @Nullable V value, @NonNull BiFunction<? super V, ? super V, ? extends V> remappingFunction) newTreeNode(int hash, K key, V value, UnsafeHashMap.Node<K, V> next) static <K,V> UnsafeHashMap<K, V> @Nullable VvoidvoidputAllIfAbsent(@NonNull Map<? extends K, ? extends V> m) final voidputEntries(boolean evict, Map.Entry<? extends K, ? extends V>... entries) @Nullable VputIfAbsent(@NonNull K key, @Nullable V value) final voidputMapEntries(Map<? extends K, ? extends V> m, boolean evict) final voidputMapEntries(Map<? extends K, ? extends V> m, boolean ifAbsent, boolean evict) Implements Map.putAll and Map constructorfinal VvoidReset to initial default state.booleanfinal @Nullable UnsafeHashMap.Node<K,V> removeNode(int hash, @NonNull Object key, @Nullable Object value, boolean matchValue, boolean movable) Implements Map.remove and related methods@Nullable VbooleanvoidreplaceAll(BiFunction<? super K, ? super V, ? extends V> function) replacementNode(UnsafeHashMap.Node<K, V> p, UnsafeHashMap.Node<K, V> next) replacementTreeNode(UnsafeHashMap.Node<K, V> p, UnsafeHashMap.Node<K, V> next) UnsafeHashMap.Node<K,V>[] resize()intsize()static inttableSizeFor(int cap) voidtreeifyBin(UnsafeHashMap.Node<K, V>[] tab, int hash) @NonNull Collection<V>values()
-
Field Details
-
DEFAULT_INITIAL_CAPACITY
public static final int DEFAULT_INITIAL_CAPACITY- See Also:
-
MAXIMUM_CAPACITY
public static final int MAXIMUM_CAPACITY- See Also:
-
DEFAULT_LOAD_FACTOR
public static final float DEFAULT_LOAD_FACTOR- See Also:
-
TREEIFY_THRESHOLD
public static final int TREEIFY_THRESHOLD- See Also:
-
UNTREEIFY_THRESHOLD
public static final int UNTREEIFY_THRESHOLD- See Also:
-
MIN_TREEIFY_CAPACITY
public static final int MIN_TREEIFY_CAPACITY- See Also:
-
loadFactor
public final float loadFactor -
keySet
-
values
-
table
-
entrySet
-
-
Constructor Details
-
UnsafeHashMap
public UnsafeHashMap(int initialCapacity, float loadFactor) -
UnsafeHashMap
public UnsafeHashMap(int initialCapacity) Constructs an empty HashMap with the specified initial capacity and the default load factor (0.75).- Parameters:
initialCapacity- the initial capacity.- Throws:
IllegalArgumentException- if the initial capacity is negative.
-
UnsafeHashMap
public UnsafeHashMap()Constructs an empty HashMap with the default initial capacity (16) and the default load factor (0.75). -
UnsafeHashMap
Constructs a new HashMap with the same mappings as the specified Map. The HashMap is created with default load factor (0.75) and an initial capacity sufficient to hold the mappings in the specified Map.- Parameters:
m- the map whose mappings are to be placed in this map- Throws:
NullPointerException- if the specified map is null
-
-
Method Details
-
of
@SafeVarargs public static <K,V> UnsafeHashMap<K,V> of(Map.Entry<? extends K, ? extends V>... entries) -
hash
-
comparableClassFor
-
compareComparables
-
tableSizeFor
public static int tableSizeFor(int cap) -
putMapEntries
-
putMapEntries
Implements Map.putAll and Map constructor- Parameters:
m- the mapevict- false when initially constructing this map, else true (relayed to method afterNodeInsertion).
-
putEntries
@SafeVarargs public final void putEntries(boolean evict, Map.Entry<? extends K, ? extends V>... entries) -
size
public int size() -
isEmpty
public boolean isEmpty() -
get
-
getNode
-
containsKey
- Specified by:
containsKeyin interfaceMap<K,V>
-
put
-
putVal
-
resize
-
treeifyBin
-
putAll
-
putAllIfAbsent
-
remove
-
removeNode
public final @Nullable UnsafeHashMap.Node<K,V> removeNode(int hash, @NonNull Object key, @Nullable Object value, boolean matchValue, boolean movable) Implements Map.remove and related methods- Parameters:
hash- hash for keykey- the keyvalue- the value to match if matchValue, else ignoredmatchValue- if true only remove if value is equalmovable- if false do not move other nodes while removing- Returns:
- the node, or null if none
-
clear
public void clear()Removes all of the mappings from this map. The map will be empty after this call returns. -
containsValue
Returns true if this map maps one or more keys to the specified value.- Specified by:
containsValuein interfaceMap<K,V> - Parameters:
value- value whose presence in this map is to be tested- Returns:
- true if this map maps one or more keys to the specified value
-
keySet
-
values
-
initValues
public void initValues() -
entrySet
-
getOrDefault
- Specified by:
getOrDefaultin interfaceMap<K,V>
-
putIfAbsent
- Specified by:
putIfAbsentin interfaceMap<K,V>
-
remove
-
replace
-
replace
-
computeIfAbsent
public @Nullable V computeIfAbsent(@NonNull K key, @NonNull Function<? super K, ? extends V> mappingFunction) - Specified by:
computeIfAbsentin interfaceMap<K,V>
-
computeIfPresent
public V computeIfPresent(@NonNull K key, @NonNull BiFunction<? super K, ? super V, ? extends V> remappingFunction) - Specified by:
computeIfPresentin interfaceMap<K,V>
-
compute
-
merge
-
forEach
-
replaceAll
- Specified by:
replaceAllin interfaceMap<K,V>
-
clone
Returns a shallow copy of this HashMap instance: the keys and values themselves are not cloned. -
capacity
public final int capacity() -
newNode
-
replacementNode
public UnsafeHashMap.Node<K,V> replacementNode(UnsafeHashMap.Node<K, V> p, UnsafeHashMap.Node<K, V> next) -
newTreeNode
public UnsafeHashMap.TreeNode<K,V> newTreeNode(int hash, K key, V value, UnsafeHashMap.Node<K, V> next) -
replacementTreeNode
public UnsafeHashMap.TreeNode<K,V> replacementTreeNode(UnsafeHashMap.Node<K, V> p, UnsafeHashMap.Node<K, V> next) -
reinitialize
public void reinitialize()Reset to initial default state. Called by clone and readObject.
-