org.pcollections
Class IntTreePMap<V>
java.lang.Object
java.util.AbstractMap<Integer,V>
org.pcollections.IntTreePMap<V>
- Type Parameters:
V
-
- All Implemented Interfaces:
- Map<Integer,V>, PMap<Integer,V>
public final class IntTreePMap<V>
- extends AbstractMap<Integer,V>
- implements PMap<Integer,V>
An efficient persistent map from integer keys to non-null values.
Iteration occurs in the integer order of the keys.
This implementation is thread-safe (assuming Java's AbstractMap and AbstractSet are thread-safe),
although its iterators may not be.
The balanced tree is based on the Glasgow Haskell Compiler's Data.Map implementation,
which in turn is based on "size balanced binary trees" as described by:
Stephen Adams, "Efficient sets: a balancing act",
Journal of Functional Programming 3(4):553-562, October 1993,
http://www.swiss.ai.mit.edu/~adams/BB/.
J. Nievergelt and E.M. Reingold, "Binary search trees of bounded balance",
SIAM journal of computing 2(1), March 1973.
- Author:
- harold
Nested classes/interfaces inherited from interface java.util.Map |
Map.Entry<K,V> |
Methods inherited from class java.util.AbstractMap |
clear, clone, containsValue, equals, hashCode, isEmpty, keySet, put, putAll, remove, toString, values |
empty
public static <V> IntTreePMap<V> empty()
- Type Parameters:
V
-
- Returns:
- an empty map
singleton
public static <V> IntTreePMap<V> singleton(Integer key,
V value)
- Type Parameters:
V
- - Parameters:
key
- value
-
- Returns:
- empty().plus(key, value)
from
public static <V> IntTreePMap<V> from(Map<? extends Integer,? extends V> map)
- Type Parameters:
V
- - Parameters:
map
-
- Returns:
- empty().plusAll(map)
entrySet
public Set<Map.Entry<Integer,V>> entrySet()
- Specified by:
entrySet
in interface Map<Integer,V>
- Specified by:
entrySet
in class AbstractMap<Integer,V>
size
public int size()
- Specified by:
size
in interface Map<Integer,V>
- Overrides:
size
in class AbstractMap<Integer,V>
containsKey
public boolean containsKey(Object key)
- Specified by:
containsKey
in interface Map<Integer,V>
- Overrides:
containsKey
in class AbstractMap<Integer,V>
get
public V get(Object key)
- Specified by:
get
in interface Map<Integer,V>
- Overrides:
get
in class AbstractMap<Integer,V>
plus
public IntTreePMap<V> plus(Integer key,
V value)
- Specified by:
plus
in interface PMap<Integer,V>
- Parameters:
key
- non-nullvalue
- non-null
- Returns:
- a map with the mappings of this but with key mapped to value
minus
public IntTreePMap<V> minus(Object key)
- Specified by:
minus
in interface PMap<Integer,V>
- Returns:
- a map with the mappings of this but with no value for key
plusAll
public IntTreePMap<V> plusAll(Map<? extends Integer,? extends V> map)
- Specified by:
plusAll
in interface PMap<Integer,V>
- Returns:
- this combined with map, with map's mappings used for any keys in both map and this
minusAll
public IntTreePMap<V> minusAll(Collection<?> keys)
- Specified by:
minusAll
in interface PMap<Integer,V>
- Returns:
- a map with the mappings of this but with no value for any element of keys
Copyright © 2011. All Rights Reserved.