java.lang.Object
java.util.AbstractMap<K,V>
org.jhotdraw8.icollection.impl.champmap.AbstractMutableChampMap<K,V>
org.jhotdraw8.icollection.MutableChampMap<K,V>
- Type Parameters:
K- the key typeV- the value type
- All Implemented Interfaces:
Serializable,Cloneable,Iterable<Map.Entry<K,,V>> Map<K,,V> ReadOnlyMap<K,V>
public class MutableChampMap<K,V>
extends org.jhotdraw8.icollection.impl.champmap.AbstractMutableChampMap<K,V>
Implements the
Map interface using a Compressed Hash-Array Mapped
Prefix-tree (CHAMP).
Features:
- supports up to 231 - 1 entries
- allows null keys and null values
- is mutable
- is not thread-safe
- does not guarantee a specific iteration order
Performance characteristics:
- put: O(log₃₂ N)
- remove: O(log₃₂ N)
- containsKey: O(log₃₂ N)
- toImmutable: O(1) + O(log₃₂ N) distributed across subsequent updates in this map
- clone: O(1) + O(log₃₂ N) distributed across subsequent updates in this map and in the clone
- iterator.next: O(1)
Implementation details:
See description at ChampMap.
References:
Portions of the code in this class has been derived from 'The Capsule Hash Trie Collections Library'.
- Michael J. Steindorfer (2017). Efficient Immutable Collections.
- michael.steindorfer.name
- The Capsule Hash Trie Collections Library.
Copyright (c) Michael Steindorfer. BSD-2-Clause License - github.com
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class java.util.AbstractMap
AbstractMap.SimpleEntry<K,V>, AbstractMap.SimpleImmutableEntry<K, V> -
Field Summary
Fields inherited from class org.jhotdraw8.icollection.impl.champmap.AbstractMutableChampMap
modCount, owner, root, size -
Constructor Summary
ConstructorsConstructorDescriptionConstructs a new empty map.MutableChampMap(Iterable<? extends Map.Entry<? extends K, ? extends V>> m) Constructs a map containing the same entries as in the specifiedIterable.MutableChampMap(Map<? extends K, ? extends V> m) Constructs a map containing the same entries as in the specifiedMap. -
Method Summary
Modifier and TypeMethodDescriptionvoidclear()Removes all entries from this map.clone()Returns a shallow copy of this map.booleancontainsKey(@Nullable Object o) Returnstrueif this map contains a entry for the specified key.entrySet()Returns aSetview of the entries contained in this map.@Nullable VReturns the value to which the specified key is mapped, ornullif this map contains no entry for the key.iterator()Returns an iterator over the entries contained in this map.@Nullable VbooleanRemoves all specified entries that are in this set.protected booleanremoveEntry(@Nullable Object o) Removes the specified entry from the map.Returns a spliterator over the entries contained in this map.Returns an immutable copy of this map.Methods inherited from class org.jhotdraw8.icollection.impl.champmap.AbstractMutableChampMap
equals, getModCount, getOrCreateOwner, getOrDefault, putAll, retainAll, sizeMethods inherited from class java.util.AbstractMap
containsValue, hashCode, isEmpty, keySet, putAll, toString, valuesMethods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.util.Map
compute, computeIfAbsent, computeIfPresent, forEach, merge, putIfAbsent, remove, replace, replace, replaceAllMethods inherited from interface org.jhotdraw8.icollection.readonly.ReadOnlyMap
asMap, characteristics, containsEntry, containsValue, hashCode, isEmpty, readOnlyEntrySet, readOnlyKeySet, readOnlyValues
-
Constructor Details
-
Method Details
-
clear
public void clear()Removes all entries from this map. -
clone
Returns a shallow copy of this map. -
containsKey
Description copied from interface:ReadOnlyMapReturnstrueif this map contains a entry for the specified key.- Specified by:
containsKeyin interfaceMap<K,V> - Specified by:
containsKeyin interfaceReadOnlyMap<K,V> - Overrides:
containsKeyin classAbstractMap<K,V> - Parameters:
o- a key- Returns:
trueif this map contains a entry for the specified key
-
iterator
Description copied from interface:ReadOnlyMapReturns an iterator over the entries contained in this map.- Returns:
- an iterator
-
spliterator
Description copied from interface:ReadOnlyMapReturns a spliterator over the entries contained in this map.- Returns:
- a spliterator
-
entrySet
Returns aSetview of the entries contained in this map. -
get
Returns the value to which the specified key is mapped, ornullif this map contains no entry for the key. -
put
-
remove
-
removeAll
Description copied from class:org.jhotdraw8.icollection.impl.champmap.AbstractMutableChampMapRemoves all specified entries that are in this set. -
removeEntry
Description copied from class:org.jhotdraw8.icollection.impl.champmap.AbstractMutableChampMapRemoves the specified entry from the map. -
toImmutable
Returns an immutable copy of this map.- Returns:
- an immutable copy
-