Package net.cscott.jutil
Class PersistentMap<K,V>
java.lang.Object
net.cscott.jutil.PersistentMap<K,V>
- All Implemented Interfaces:
Serializable
PersistentMap implements a persistent map, based on a
persistent randomized treap. Unlike the Maps returned
by PersistentMapFactory, PersistentMap
does not implement that standard Map API
but instead exposes the underlying functional operations.- Author:
- C. Scott Ananian <cananian@alumni.princeton.edu>
- See Also:
- Tests:
- A {@link PersistentMap} is never changed: {@link #put put()} and {@link #remove remove()} return a new map, which shares most of its structure with the old one.
js> empty = new PersistentMap() {} js> one = empty.put("a", "apple") {a=apple} js> two = one.put("b", "banana") {a=apple, b=banana} js> two.remove("a") {b=banana} js> one {a=apple} js> two.get("b") banana
-
Constructor Summary
ConstructorsConstructorDescriptionCreates an emptyPersistentMapwhose key objects will all implementComparable.PersistentMap(Comparator<K> c) Creates an emptyPersistentMapwhose key objects are ordered by the givenComparator. -
Method Summary
Modifier and TypeMethodDescriptionasMap()Collections view of the mapping.clone()Cloning takes constant time, regardless of the size of the map.booleancontainsKey(K key) Determines if there is a mapping for the givenkey.Gets the value whichkeymaps to.inthashCode()booleanisEmpty()Determines if thisPersistentMaphas any mappings.Creates and returns a newPersistentMapidentical to this one, except it contains a mapping fromkeytovalue.putAll(PersistentMap<K, V> map) Put all the mappings in the given map into this map, throwing out conflicting mappings from this set as necessary.Make a newPersistentMapidentical to this one, except that it does not contain a mapping forkey.intsize()Count the number of key->value mappings in thisPersistentMap.toString()Human-readable representation of the map.
-
Constructor Details
-
PersistentMap
public PersistentMap()Creates an emptyPersistentMapwhose key objects will all implementComparable. Note that good hashcode implementations for the key objects are still required. -
PersistentMap
Creates an emptyPersistentMapwhose key objects are ordered by the givenComparator. Note that good hashcode implementations for the key objects are still required.
-
-
Method Details
-
isEmpty
public boolean isEmpty()Determines if thisPersistentMaphas any mappings. -
size
public int size()Count the number of key->value mappings in thisPersistentMap. -
put
Creates and returns a newPersistentMapidentical to this one, except it contains a mapping fromkeytovalue. -
get
Gets the value whichkeymaps to. -
containsKey
Determines if there is a mapping for the givenkey. -
remove
Make a newPersistentMapidentical to this one, except that it does not contain a mapping forkey. -
putAll
Put all the mappings in the given map into this map, throwing out conflicting mappings from this set as necessary. -
clone
Cloning takes constant time, regardless of the size of the map. -
toString
Human-readable representation of the map. -
hashCode
public int hashCode() -
asMap
Collections view of the mapping.
-