java.lang.Object
java.util.AbstractMap<K,V>
org.jhotdraw8.icollection.impl.champ.AbstractMutableChampMap<K,V,org.jhotdraw8.icollection.impl.champ.SequencedEntry<K,V>>
org.jhotdraw8.icollection.MutableChampVectorMap<K,V>
- Type Parameters:
K- the key typeV- the value type
- All Implemented Interfaces:
Serializable,Cloneable,Iterable<Map.Entry<K,,V>> Map<K,,V> SequencedMap<K,,V> ReadOnlyMap<K,,V> ReadOnlySequencedMap<K,V>
public class MutableChampVectorMap<K,V>
extends org.jhotdraw8.icollection.impl.champ.AbstractMutableChampMap<K,V,org.jhotdraw8.icollection.impl.champ.SequencedEntry<K,V>>
implements SequencedMap<K,V>, ReadOnlySequencedMap<K,V>
Implements the
SequencedMap interface using a Compressed
Hash-Array Mapped Prefix-tree (CHAMP) and a bit-mapped trie (Vector).
Features:
- supports up to 230 entries
- allows null keys and null values
- is mutable
- is not thread-safe
- iterates in the order, in which keys were inserted
Performance characteristics:
- put, putFirst, putLast: O(1) in an amortized sense, because we sometimes have to renumber the elements.
- remove: O(1) in an amortized sense, because we sometimes have to renumber the elements.
- containsKey: O(1)
- toImmutable: O(1) + O(log N) distributed across subsequent updates in this mutable map
- clone: O(1) + O(log N) distributed across subsequent updates in this mutable map and in the clone
- iterator creation: O(1)
- iterator.next: O(1)
- getFirst, getLast: O(1)
Implementation details:
See description at ChampVectorMap.
References:
- 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.champ.AbstractMutableChampMap
modCount, owner, root, size -
Constructor Summary
ConstructorsConstructorDescriptionConstructs a new empty map.MutableChampVectorMap(Iterable<? extends Map.Entry<? extends K, ? extends V>> c) Constructs a map containing the same entries as in the specifiedIterable.MutableChampVectorMap(Map<? extends K, ? extends V> c) 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()Gets the first entry in this map ornullif this map is empty.@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.keySet()Gets the last entry in this map ornullif this map is empty.@Nullable VbooleanAdds all specified elements that are not already in this set.@Nullable V@Nullable VReturns a reversed-order view of this map.@Nullable Vreversed()Returns aSequencedSetview of the entries contained in this map.Returns a spliterator over the entries contained in this map.Returns an immutable copy of this map.values()Methods inherited from class org.jhotdraw8.icollection.impl.champ.AbstractMutableChampMap
equals, getModCount, getOrCreateOwner, getOrDefault, removeAll, removeEntry, retainAll, sizeMethods inherited from class java.util.AbstractMap
containsValue, hashCode, isEmpty, putAll, toStringMethods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.util.Map
compute, computeIfAbsent, computeIfPresent, containsValue, equals, forEach, getOrDefault, hashCode, isEmpty, merge, putAll, putIfAbsent, remove, replace, replace, replaceAll, sizeMethods inherited from interface org.jhotdraw8.icollection.readonly.ReadOnlyMap
containsEntry, containsValue, equals, getOrDefault, hashCode, isEmpty, sizeMethods inherited from interface org.jhotdraw8.icollection.readonly.ReadOnlySequencedMap
asMap, characteristics, readOnlyEntrySet, readOnlyKeySet, readOnlyValues
-
Constructor Details
-
MutableChampVectorMap
public MutableChampVectorMap()Constructs a new empty map. -
MutableChampVectorMap
Constructs a map containing the same entries as in the specifiedMap.- Parameters:
c- a map
-
MutableChampVectorMap
Constructs a map containing the same entries as in the specifiedIterable.- Parameters:
c- an iterable
-
-
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. -
spliterator
Description copied from interface:ReadOnlyMapReturns a spliterator over the entries contained in this map.- Specified by:
spliteratorin interfaceIterable<K>- Specified by:
spliteratorin interfaceReadOnlyMap<K,V> - Returns:
- a spliterator
-
entrySet
-
keySet
-
values
-
sequencedEntrySet
Returns aSequencedSetview of the entries contained in this map.- Specified by:
sequencedEntrySetin interfaceSequencedMap<K,V> - Returns:
- a view of the entries contained in this map
-
firstEntry
Description copied from interface:ReadOnlySequencedMapGets the first entry in this map ornullif this map is empty.- Specified by:
firstEntryin interfaceReadOnlySequencedMap<K,V> - Specified by:
firstEntryin interfaceSequencedMap<K,V> - Returns:
- the first entry or
null
-
get
Returns the value to which the specified key is mapped, ornullif this map contains no entry for the key. -
sequencedKeySet
- Specified by:
sequencedKeySetin interfaceSequencedMap<K,V>
-
lastEntry
Description copied from interface:ReadOnlySequencedMapGets the last entry in this map ornullif this map is empty.- Specified by:
lastEntryin interfaceReadOnlySequencedMap<K,V> - Specified by:
lastEntryin interfaceSequencedMap<K,V> - Returns:
- the last entry or
null
-
pollFirstEntry
- Specified by:
pollFirstEntryin interfaceSequencedMap<K,V>
-
pollLastEntry
- Specified by:
pollLastEntryin interfaceSequencedMap<K,V>
-
put
-
putFirst
- Specified by:
putFirstin interfaceSequencedMap<K,V>
-
putAll
Description copied from class:org.jhotdraw8.icollection.impl.champ.AbstractMutableChampMapAdds all specified elements that are not already in this set. -
putLast
- Specified by:
putLastin interfaceSequencedMap<K,V>
-
readOnlyReversed
Description copied from interface:ReadOnlySequencedMapReturns a reversed-order view of this map.Changes to the underlying map are visible in the reversed view.
- Specified by:
readOnlyReversedin interfaceReadOnlySequencedMap<K,V> - Returns:
- a reversed-order view of this map
-
remove
-
reversed
- Specified by:
reversedin interfaceSequencedMap<K,V>
-
toImmutable
Returns an immutable copy of this map.- Returns:
- an immutable copy
-
sequencedValues
- Specified by:
sequencedValuesin interfaceSequencedMap<K,V>
-