Class HashPMap<K,​V>

  • Type Parameters:
    K -
    V -
    All Implemented Interfaces:
    java.io.Serializable, java.util.Map<K,​V>, PMap<K,​V>

    public final class HashPMap<K,​V>
    extends AbstractUnmodifiableMap<K,​V>
    implements PMap<K,​V>, java.io.Serializable
    A persistent map from keys to values. Keys and values can be null.

    This map uses a given integer map to map hashcodes to lists of elements with the same hashcode. Thus if all elements have the same hashcode, performance is reduced to that of an association list.

    This implementation is thread-safe (assuming Java's AbstractMap and AbstractSet are thread-safe), although its iterators may not be.

    See Also:
    Serialized Form
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      (package private) static class  HashPMap.SequenceIterator<E>  
      • Nested classes/interfaces inherited from class java.util.AbstractMap

        java.util.AbstractMap.SimpleEntry<K extends java.lang.Object,​V extends java.lang.Object>, java.util.AbstractMap.SimpleImmutableEntry<K extends java.lang.Object,​V extends java.lang.Object>
      • Nested classes/interfaces inherited from interface java.util.Map

        java.util.Map.Entry<K extends java.lang.Object,​V extends java.lang.Object>
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private java.util.Set<java.util.Map.Entry<K,​V>> entrySet  
      private PMap<java.lang.Integer,​PSequence<java.util.Map.Entry<K,​V>>> intMap  
      private static long serialVersionUID  
      private int size  
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      private HashPMap​(PMap<java.lang.Integer,​PSequence<java.util.Map.Entry<K,​V>>> intMap, int size)  
    • Field Detail

      • intMap

        private final PMap<java.lang.Integer,​PSequence<java.util.Map.Entry<K,​V>>> intMap
      • size

        private final int size
      • entrySet

        private transient java.util.Set<java.util.Map.Entry<K,​V>> entrySet
    • Constructor Detail

      • HashPMap

        private HashPMap​(PMap<java.lang.Integer,​PSequence<java.util.Map.Entry<K,​V>>> intMap,
                         int size)
    • Method Detail

      • empty

        public static <K,​V> HashPMap<K,​V> empty​(PMap<java.lang.Integer,​PSequence<java.util.Map.Entry<K,​V>>> intMap)
        Type Parameters:
        K -
        V -
        Parameters:
        intMap -
        Returns:
        a map backed by an empty version of intMap, i.e. backed by intMap.minusAll(intMap.keySet())
      • entrySet

        public java.util.Set<java.util.Map.Entry<K,​V>> entrySet()
        Specified by:
        entrySet in interface java.util.Map<K,​V>
        Specified by:
        entrySet in class java.util.AbstractMap<K,​V>
      • size

        public int size()
        Specified by:
        size in interface java.util.Map<K,​V>
        Overrides:
        size in class java.util.AbstractMap<K,​V>
      • containsKey

        public boolean containsKey​(java.lang.Object key)
        Specified by:
        containsKey in interface java.util.Map<K,​V>
        Overrides:
        containsKey in class java.util.AbstractMap<K,​V>
      • get

        public V get​(java.lang.Object key)
        Specified by:
        get in interface java.util.Map<K,​V>
        Overrides:
        get in class java.util.AbstractMap<K,​V>
      • plusAll

        public HashPMap<K,​V> plusAll​(java.util.Map<? extends K,​? extends V> map)
        Specified by:
        plusAll in interface PMap<K,​V>
        Returns:
        this combined with map, with map's mappings used for any keys in both map and this
      • minusAll

        public HashPMap<K,​V> minusAll​(java.util.Collection<?> keys)
        Specified by:
        minusAll in interface PMap<K,​V>
        Returns:
        a map with the mappings of this but with no value for any element of keys
      • plus

        public HashPMap<K,​V> plus​(K key,
                                        V value)
        Specified by:
        plus in interface PMap<K,​V>
        Returns:
        a map with the mappings of this but with key mapped to value
      • minus

        public HashPMap<K,​V> minus​(java.lang.Object key)
        Specified by:
        minus in interface PMap<K,​V>
        Returns:
        a map with the mappings of this but with no value for key
      • getEntries

        private PSequence<java.util.Map.Entry<K,​V>> getEntries​(int hash)
      • keyIndexIn

        private static <K,​V> int keyIndexIn​(PSequence<java.util.Map.Entry<K,​V>> entries,
                                                  java.lang.Object key)