Class MutableChampMap<K,V>

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 type
V - 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:
  • Constructor Details

    • MutableChampMap

      public MutableChampMap()
      Constructs a new empty map.
    • MutableChampMap

      public MutableChampMap(Map<? extends K,? extends V> m)
      Constructs a map containing the same entries as in the specified Map.
      Parameters:
      m - a map
    • MutableChampMap

      public MutableChampMap(Iterable<? extends Map.Entry<? extends K,? extends V>> m)
      Constructs a map containing the same entries as in the specified Iterable.
      Parameters:
      m - an iterable
  • Method Details

    • clear

      public void clear()
      Removes all entries from this map.
      Specified by:
      clear in interface Map<K,V>
      Overrides:
      clear in class AbstractMap<K,V>
    • clone

      public MutableChampMap<K,V> clone()
      Returns a shallow copy of this map.
      Overrides:
      clone in class org.jhotdraw8.icollection.impl.champmap.AbstractMutableChampMap<K,V>
    • containsKey

      public boolean containsKey(@Nullable Object o)
      Description copied from interface: ReadOnlyMap
      Returns true if this map contains a entry for the specified key.
      Specified by:
      containsKey in interface Map<K,V>
      Specified by:
      containsKey in interface ReadOnlyMap<K,V>
      Overrides:
      containsKey in class AbstractMap<K,V>
      Parameters:
      o - a key
      Returns:
      true if this map contains a entry for the specified key
    • iterator

      public Iterator<Map.Entry<K,V>> iterator()
      Description copied from interface: ReadOnlyMap
      Returns an iterator over the entries contained in this map.
      Returns:
      an iterator
    • spliterator

      public Spliterator<Map.Entry<K,V>> spliterator()
      Description copied from interface: ReadOnlyMap
      Returns a spliterator over the entries contained in this map.
      Returns:
      a spliterator
    • entrySet

      public Set<Map.Entry<K,V>> entrySet()
      Returns a Set view of the entries contained in this map.
      Specified by:
      entrySet in interface Map<K,V>
      Specified by:
      entrySet in class AbstractMap<K,V>
      Returns:
      a view of the entries contained in this map
    • get

      public @Nullable V get(Object o)
      Returns the value to which the specified key is mapped, or null if this map contains no entry for the key.
      Specified by:
      get in interface Map<K,V>
      Specified by:
      get in interface ReadOnlyMap<K,V>
      Overrides:
      get in class AbstractMap<K,V>
      Parameters:
      o - the key whose associated value is to be returned
      Returns:
      the associated value or null
    • put

      public @Nullable V put(K key, V value)
      Specified by:
      put in interface Map<K,V>
      Overrides:
      put in class AbstractMap<K,V>
    • remove

      public V remove(Object o)
      Specified by:
      remove in interface Map<K,V>
      Overrides:
      remove in class AbstractMap<K,V>
    • removeAll

      public boolean removeAll(Iterable<?> c)
      Description copied from class: org.jhotdraw8.icollection.impl.champmap.AbstractMutableChampMap
      Removes all specified entries that are in this set.
      Overrides:
      removeAll in class org.jhotdraw8.icollection.impl.champmap.AbstractMutableChampMap<K,V>
      Parameters:
      c - an iterable of keys
      Returns:
      true if this map changed
    • removeEntry

      protected boolean removeEntry(@Nullable Object o)
      Description copied from class: org.jhotdraw8.icollection.impl.champmap.AbstractMutableChampMap
      Removes the specified entry from the map.
      Overrides:
      removeEntry in class org.jhotdraw8.icollection.impl.champmap.AbstractMutableChampMap<K,V>
      Parameters:
      o - an entry (should be a Map.Entry).
      Returns:
      true if the element was contained in the map
    • toImmutable

      public ChampMap<K,V> toImmutable()
      Returns an immutable copy of this map.
      Returns:
      an immutable copy