scala.collection.immutable

class TreeMap

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

@serializable

class TreeMap[A, +B](val override size : Int, t : Tree[B], val implicit ordering : Ordering[A])
extends RedBlack[A] with SortedMap[A, B] with SortedMapLike[A, B, TreeMap[A, B]] with MapLike[A, B, TreeMap[A, B]]
This class implements immutable maps using a tree.
Author
Erik Stenman
Matthias Zenger
Version
1.1, 03/05/2004
Since
1
Additional Constructor Summary
def this ()(implicit ordering : Ordering[A]) : TreeMap[A, B]
Value Summary
protected val tree : Tree[B]
Method Summary
override def + [B1 >: B](elem1 : (A, B1), elem2 : (A, B1), elems : (A, B1)*) : TreeMap[A, B1]
Adds two or more elements to this collection and returns either the collection itself (if it is mutable), or a new collection with the added elements.
override def + [B1 >: B](kv : (A, B1)) : TreeMap[A, B1]
Add a key/value pair to this map.
def - (key : A) : TreeMap[A, B]
Removes a key from this map, returning a new map
override def compare (k0 : A, k1 : A) : Int
Comparison function that orders keys.
override def empty : TreeMap[A, B]
A factory to create empty maps of the same type of keys.
override def firstKey : A
Returns the first key of the collection.
override def foreach [U](f : ((A, B)) => U) : Unit
Apply a function f to all elements of this iterable object.
override def get (key : A) : Option[B]
Check if this map maps key to a value and return the value if it exists.
def insert [B1 >: B](key : A, value : B1) : TreeMap[A, B1]
A new TreeMap with the entry added is returned, assuming that key is not in the TreeMap.
def isSmaller (x : A, y : A) : Boolean
def iterator : Iterator[(A, B)]
Creates a new iterator over all elements contained in this object.
override def lastKey : A
Returns the last key of the collection.
protected[this] override def newBuilder : Builder[(A, B), TreeMap[A, B]]
A common implementation of `newBuilder` for all maps in terms of `empty`. Overridden for mutable maps in `mutable.MapLike`.
override def rangeImpl (from : Option[A], until : Option[A]) : TreeMap[A, B]
Creates a ranged projection of this collection. Any mutations in the ranged projection will update this collection and vice versa. Note: keys are not garuanteed to be consistent between this collection and the projection. This is the case for buffers where indexing is relative to the projection.
override def toStream : Stream[(A, B)]
Returns a stream with all elements in this iterable object.
override def updated [B1 >: B](key : A, value : B1) : TreeMap[A, B1]
A new TreeMap with the entry added is returned, if key is not in the TreeMap, otherwise the key is updated with the new entry.
Methods inherited from SortedMap
++, ++
Methods inherited from SortedMapLike
keySet
Methods inherited from Sorted
from, until, range, to, hasAll
Methods inherited from Map
withDefault, withDefaultValue
Methods inherited from MapLike
transform, filterNot, update
Methods inherited from MapLike
isEmpty, getOrElse, apply, contains, isDefinedAt, keysIterator, keys, valuesIterable, valuesIterator, values, default, filterKeys, mapValues, mapElements, addString, stringPrefix, toString, hashCode, equals
Methods inherited from Subtractable
-, --, --
Methods inherited from PartialFunction
orElse, andThen
Methods inherited from Function1
compose
Methods inherited from Iterable
companion
Methods inherited from IterableLike
thisCollection, toCollection, elements, forall, exists, find, foldRight, reduceRight, toIterable, head, take, slice, takeWhile, takeRight, dropRight, copyToArray, zip, zipAll, zipWithIndex, sameElements, canEqual, view, view, first, firstOption, projection
Methods inherited from GenericTraversableTemplate
genericBuilder, unzip, flatten, transpose
Methods inherited from TraversableLike
repr, nonEmpty, hasDefiniteSize, ++, ++, map, flatMap, filter, partialMap, remove, partition, groupBy, count, foldLeft, /:, :\, reduceLeft, reduceLeftOption, reduceRightOption, sum, product, min, max, headOption, tail, last, lastOption, init, drop, dropWhile, span, splitAt, copyToBuffer, copyToArray, toArray, toList, toSeq, toIndexedSeq, toSet, mkString, mkString, mkString, addString, addString, withFilter
Methods inherited from AnyRef
getClass, clone, notify, notifyAll, wait, wait, wait, finalize, ==, !=, eq, ne, synchronized
Methods inherited from Any
==, !=, isInstanceOf, asInstanceOf
Additional Constructor Details
def this()(implicit ordering : Ordering[A]) : TreeMap[A, B]

Value Details
protected val tree : Tree[B]

Method Details
def isSmaller(x : A, y : A) : Boolean
Overrides
RedBlack.isSmaller

protected[this] override def newBuilder : Builder[(A, B), TreeMap[A, B]]
A common implementation of `newBuilder` for all maps in terms of `empty`. Overridden for mutable maps in `mutable.MapLike`.
Overrides
SortedMap.newBuilder

override def rangeImpl(from : Option[A], until : Option[A]) : TreeMap[A, B]
Creates a ranged projection of this collection. Any mutations in the ranged projection will update this collection and vice versa. Note: keys are not garuanteed to be consistent between this collection and the projection. This is the case for buffers where indexing is relative to the projection.
Parameters
from - The lower-bound (inclusive) of the ranged projection. None if there is no lower bound.
until - The upper-bound (exclusive) of the ranged projection. None if there is no upper bound.
Overrides
SortedMapLike.rangeImpl

override def firstKey : A
Returns the first key of the collection.
Overrides
SortedMapLike.firstKey

override def lastKey : A
Returns the last key of the collection.
Overrides
SortedMapLike.lastKey

override def compare(k0 : A, k1 : A) : Int
Comparison function that orders keys.

override def empty : TreeMap[A, B]
A factory to create empty maps of the same type of keys.

override def updated[B1 >: B](key : A, value : B1) : TreeMap[A, B1]
A new TreeMap with the entry added is returned, if key is not in the TreeMap, otherwise the key is updated with the new entry.
Parameters
key - ...
value - ...
Returns
...
Overrides
SortedMap.updated, SortedMapLike.updated, MapLike.updated

override def +[B1 >: B](kv : (A, B1)) : TreeMap[A, B1]
Add a key/value pair to this map.
Parameters
kv - the key/value pair
Returns
A new map with the new binding added to this map
Overrides
SortedMap.+, SortedMapLike.+, MapLike.+

override def +[B1 >: B](elem1 : (A, B1), elem2 : (A, B1), elems : (A, B1)*) : TreeMap[A, B1]
Adds two or more elements to this collection and returns either the collection itself (if it is mutable), or a new collection with the added elements.
Parameters
elem1 - the first element to add.
elem2 - the second element to add.
elems - the remaining elements to add.
Overrides
SortedMap.+, SortedMapLike.+, MapLike.+

def insert[B1 >: B](key : A, value : B1) : TreeMap[A, B1]
A new TreeMap with the entry added is returned, assuming that key is not in the TreeMap.

def -(key : A) : TreeMap[A, B]
Removes a key from this map, returning a new map
Parameters
key - the key to be removed
Returns
A new map without a binding for key

override def get(key : A) : Option[B]
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 iterator : Iterator[(A, B)]
Creates a new iterator over all elements contained in this object.
Returns
the new iterator

override def toStream : Stream[(A, B)]
Returns a stream with all elements in this iterable object.

override def foreach[U](f : ((A, B)) => U) : Unit
Apply a function f to all elements of this iterable object.
Parameters
f - A function that is applied for its side-effect to every element. The result (of arbitrary type U) of function `f` is discarded.
Notes
This method underlies the implementation of most other bulk operations. Implementing `foreach` with `iterator` is often suboptimal. So `foreach` should be overridden in concrete collection classes if a more efficient implementation is available.