Class HashPMap<K,V>

Type Parameters:
K -
V -
All Implemented Interfaces:
Serializable, Map<K,V>, PMap<K,V>

public final class HashPMap<K,V> extends AbstractUnmodifiableMap<K,V> implements PMap<K,V>, 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:
  • Field Details

  • Constructor Details

  • Method Details

    • empty

      public static <K,V> HashPMap<K,V> empty(PMap<Integer, PSequence<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 Set<Map.Entry<K,V>> entrySet()
      Specified by:
      entrySet in interface Map<K,V>
      Specified by:
      entrySet in class AbstractMap<K,V>
    • size

      public int size()
      / OVERRIDDEN METHODS FROM AbstractMap ////
      Specified by:
      size in interface Map<K,V>
      Overrides:
      size in class AbstractMap<K,V>
    • containsKey

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

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

      public HashPMap<K,V> plusAll(Map<? extends K, ? extends V> map)
      / IMPLEMENTED METHODS OF PMap////
      Specified by:
      plusAll in interface PMap<K,V>
      Parameters:
      map -
      Returns:
      this combined with map, with map's mappings used for any keys in both map and this
    • minusAll

      public HashPMap<K,V> minusAll(Collection<?> keys)
      Specified by:
      minusAll in interface PMap<K,V>
      Parameters:
      keys -
      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>
      Parameters:
      key -
      value -
      Returns:
      a map with the mappings of this but with key mapped to value
    • minus

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

      private PSequence<Map.Entry<K,V>> getEntries(int hash)
      / PRIVATE UTILITIES ////
    • keyIndexIn

      private static <K,V> int keyIndexIn(PSequence<Map.Entry<K,V>> entries, Object key)
      / PRIVATE STATIC UTILITIES ////