Class PersistentHashMap<K,​V>

  • All Implemented Interfaces:
    java.io.Serializable, java.lang.Iterable<UnmodMap.UnEntry<K,​V>>, java.util.Map<K,​V>, BaseMap<K,​V>, BaseUnsortedMap<K,​V>, ImMap<K,​V>, Sized, UnmodIterable<UnmodMap.UnEntry<K,​V>>, UnmodMap<K,​V>, Transformable<UnmodMap.UnEntry<K,​V>>

    public class PersistentHashMap<K,​V>
    extends AbstractUnmodMap<K,​V>
    implements ImMap<K,​V>, java.io.Serializable
    Rich Hickey's immutable rendition of Phil Bagwell's Hash Array Mapped Trie. Uses path copying for persistence, HashCollision leaves vs. extended hashing, Node polymorphism vs. conditionals, No sub-tree pools or root-resizing. Any errors are my own (said Rich, but now says Glen 2015-06-06). This file is a derivative work based on a Clojure collection licensed under the Eclipse Public License 1.0 Copyright Rich Hickey. Errors are Glen Peterson's.
    See Also:
    Serialized Form
    • Field Detail

      • EMPTY

        public static final PersistentHashMap<java.lang.Object,​java.lang.Object> EMPTY
    • Method Detail

      • ofEq

        public static <K,​V> PersistentHashMap<K,​V> ofEq​(Equator<K> eq,
                                                                    java.lang.Iterable<java.util.Map.Entry<K,​V>> es)
        Returns a new PersistentHashMap of the given keys and their paired values, skipping any null Entries.
      • of

        public static <K,​V> PersistentHashMap<K,​V> of​(java.lang.Iterable<java.util.Map.Entry<K,​V>> kvPairs)
        Returns a new PersistentHashMap of the given keys and their paired values. There is also a varargs version of this method: StaticImports.map(Map.Entry...). Use the StaticImports.tup(Object, Object) method to define key/value pairs briefly and easily.
        Parameters:
        kvPairs - Key/value pairs (to go into the map). In the case of a duplicate key, later values in the input list overwrite the earlier ones. The resulting map can contain zero or one null key and any number of null values. Null k/v pairs will be silently ignored.
        Returns:
        a new PersistentHashMap of the given key/value pairs
      • equator

        public Equator<K> equator()
        Returns the Equator used by this map for equals comparisons and hashCodes
        Specified by:
        equator in interface BaseUnsortedMap<K,​V>
      • iterator

        public UnmodIterator<UnmodMap.UnEntry<K,​V>> iterator()
        Description copied from interface: UnmodIterable
        A one-time use, mutable, not-thread-safe way to get each value of the underling collection in turn. I experimented with various thread-safe alternatives, but the JVM is optimized around iterators so this is the lowest common denominator of collection iteration, even though iterators are inherently mutable.
        Specified by:
        iterator in interface java.lang.Iterable<K>
        Specified by:
        iterator in interface UnmodIterable<K>
      • size

        public int size()
        Returns the number of items in this collection or iterable.
        Specified by:
        size in interface java.util.Map<K,​V>
        Specified by:
        size in interface Sized