org.pcollections
Class HashPMap<K,V>

java.lang.Object
  extended by java.util.AbstractMap<K,V>
      extended by org.pcollections.HashPMap<K,V>
Type Parameters:
K -
V -
All Implemented Interfaces:
Map<K,V>, PMap<K,V>

public final class HashPMap<K,V>
extends AbstractMap<K,V>
implements PMap<K,V>

A persistent map from non-null keys to non-null values.

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.

Author:
harold

Nested Class Summary
 
Nested classes/interfaces inherited from class java.util.AbstractMap
AbstractMap.SimpleEntry<K,V>, AbstractMap.SimpleImmutableEntry<K,V>
 
Nested classes/interfaces inherited from interface java.util.Map
Map.Entry<K,V>
 
Method Summary
 boolean containsKey(Object key)
           
static
<K,V> HashPMap<K,V>
empty(PMap<Integer,PSequence<Map.Entry<K,V>>> intMap)
           
 Set<Map.Entry<K,V>> entrySet()
           
 V get(Object key)
           
 HashPMap<K,V> minus(Object key)
           
 HashPMap<K,V> minusAll(Collection<?> keys)
           
 HashPMap<K,V> plus(K key, V value)
           
 HashPMap<K,V> plusAll(Map<? extends K,? extends V> map)
           
 int size()
           
 
Methods inherited from class java.util.AbstractMap
clear, clone, containsValue, equals, hashCode, isEmpty, keySet, put, putAll, remove, toString, values
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.pcollections.PMap
clear, put, putAll, remove
 
Methods inherited from interface java.util.Map
containsValue, equals, hashCode, isEmpty, keySet, values
 

Method Detail

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()
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)
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(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>
Parameters:
key - non-null
value - non-null
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>
Returns:
a map with the mappings of this but with no value for key


Copyright © 2011. All Rights Reserved.