scala.collection.immutable

class TreeHashMap

[source: scala/collection/immutable/TreeHashMap.scala]

class TreeHashMap[Key, +Value](private underlying : IntMap[scala.collection.immutable.AssocMap[Key, Value]])
extends Map[Key, Value]
An immutable Map which is based on an IntMap mapping hash codes to lists of (Key, Value) pairs with the same hashCode. Unlike the usual immutable.HashMap it is truly immutable behind the scenes. Consequently it is entirely safe to share between multiple threads and should achieve a much greater degree of sharing between instances. Performancewise, get and update seem to be somewhat slower than with a traditional hash map, but bulk operations such as filter, foreach and transform appear to get something of a speedup.
Author
David MacIver
Value Summary
override lazy val size : Int
Compute the number of key-to-value mappings.
Method Summary
override def ++ [V >: Value](that : Iterable[(Key, V)]) : TreeHashMap[Key, V]
Add a sequence of key/value pairs to this map.
def ++ [V >: Value](that : TreeHashMap[Key, V]) : TreeHashMap[Key, V]
def - (key : Key) : TreeHashMap[Key, Value]
Remove a key from this map
override def apply (key : Key) : Value
Retrieve the value which is associated with the given key. This method throws an exception if there is no mapping from the given key to a value.
def elements : Iterator[(Key, Value)]
Creates a new iterator over all elements contained in this object.
def empty [V] : TreeHashMap[Key, V]
This method returns a new map instance of the same class mapping keys of the same type to values of type C.
override def equals (that : Any) : Boolean
Compares two maps structurally; i.e. checks if all mappings contained in this map are also contained in the other map, and vice versa.
override def filter (f : ((Key, Value)) => Boolean) : TreeHashMap[Key, Value]
This method removes all the mappings for which the predicate p returns false.
override def foreach (f : ((Key, Value)) => Unit) : Unit
Apply a function f to all elements of this iterable object.
def get (key : Key) : Option[Value]
Check if this map maps key to a value and return the value if it exists.
override def hashCode : Int
A hash method compatible with equals
override def isEmpty : Boolean
Is this an empty map?
override def stringPrefix : java.lang.String
Defines the prefix of this object's toString representation.
override def toList : List[(Key, Value)]
Returns a list containing all of the elements in this iterable object.
override def transform [C](f : (Key, Value) => C) : TreeHashMap[Key, C]
This function transforms all the values of mappings contained in this map with function f.
def update [S >: Value](key : Key, value : S) : TreeHashMap[Key, S]
This method allows one to create a new map with an additional mapping from key to value. If the map contains already a mapping for key, it will be overridden by this function.
Methods inherited from Map
+, +, ++, -, --, --, withDefault, withDefaultValue, +, incl, incl, excl, excl, mappingToString
Methods inherited from Map
getOrElse, contains, isDefinedAt, keys, keySet, values, toString, default, projection, filterKeys, mapElements
Methods inherited from Collection
toArray
Methods inherited from Iterable
concat, ++, map, flatMap, partition, takeWhile, dropWhile, take, drop, forall, exists, find, findIndexOf, indexOf, foldLeft, foldRight, /:, :\, reduceLeft, reduceRight, copyToBuffer, sameElements, toSeq, toStream, mkString, mkString, mkString, addString, addString, addString, copyToArray, hasDefiniteSize
Methods inherited from PartialFunction
orElse, andThen
Methods inherited from Function1
compose
Methods inherited from AnyRef
getClass, clone, notify, notifyAll, wait, wait, wait, finalize, ==, !=, eq, ne, synchronized
Methods inherited from Any
==, !=, isInstanceOf, asInstanceOf
Value Details
override lazy val size : Int
Compute the number of key-to-value mappings.
Returns
the number of mappings

Method Details
def elements : Iterator[(Key, Value)]
Creates a new iterator over all elements contained in this object.
Returns
the new iterator

def empty[V] : TreeHashMap[Key, V]
This method returns a new map instance of the same class mapping keys of the same type to values of type C.
Overrides
Map.empty

override def stringPrefix : java.lang.String
Defines the prefix of this object's toString representation.

override def equals(that : Any) : Boolean
Compares two maps structurally; i.e. checks if all mappings contained in this map are also contained in the other map, and vice versa.
Parameters
that - the other map
Returns
true iff both maps contain exactly the same mappings.

override def hashCode : Int
A hash method compatible with equals

override def foreach(f : ((Key, Value)) => Unit) : Unit
Apply a function f to all elements of this iterable object.
Notes
Will not terminate for infinite-sized collections.
Parameters
f - a function that is applied to every element.

override def toList : List[(Key, Value)]
Returns a list containing all of the elements in this iterable object.
Notes
Will not terminate for infinite-sized collections.

override def apply(key : Key) : Value
Retrieve the value which is associated with the given key. This method throws an exception if there is no mapping from the given key to a value.
Parameters
key - the key
Returns
the value associated with the given key.

override def isEmpty : Boolean
Is this an empty map?
Returns
true iff the map is empty.

override def filter(f : ((Key, Value)) => Boolean) : TreeHashMap[Key, Value]
This method removes all the mappings for which the predicate p returns false.
Parameters
p - A prediacte over key-value pairs
Returns
the updated map
Overrides
Map.filter

override def transform[C](f : (Key, Value) => C) : TreeHashMap[Key, C]
This function transforms all the values of mappings contained in this map with function f.
Parameters
f - A function over keys and values
Returns
the updated map
Overrides
Map.transform

def get(key : Key) : Option[Value]
Check if this map maps key to a value and return the value if it exists.
Parameters
key - the key of the mapping of interest
Returns
the value of the mapping, if it exists

def update[S >: Value](key : Key, value : S) : TreeHashMap[Key, S]
This method allows one to create a new map with an additional mapping from key to value. If the map contains already a mapping for key, it will be overridden by this function.
Parameters
key - ...
value - ...
Returns
the created map
Deprecated
use +({A, B}) instead
Overrides
Map.update

def -(key : Key) : TreeHashMap[Key, Value]
Remove a key from this map
Parameters
key - the key to be removed
Returns
If the map does not contain a binding for key it is returned unchanged. Otherwise, return a new map without a binding for key
Overrides
Map.-

override def ++[V >: Value](that : Iterable[(Key, V)]) : TreeHashMap[Key, V]
Add a sequence of key/value pairs to this map.
Parameters
kvs - the iterable object containing all key/value pairs.
Returns
A new map with the new bindings added
Overrides
Map.++

def ++[V >: Value](that : TreeHashMap[Key, V]) : TreeHashMap[Key, V]