summaryrefslogtreecommitdiff
path: root/src/library/scala/collection/mutable/SortedMap.scala
blob: 806b30e79a5266954c8a0e7b29b132a5d44e0e1e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package scala
package collection
package mutable

import generic._

/**
 * A mutable map whose keys are sorted.
 *
 * @tparam A the type of the keys contained in this sorted map.
 * @tparam B the type of the values associated with the keys.
 *
 * @author Rui Gonçalves
 * @version 2.12
 * @since 2.12
 *
 * @define Coll mutable.SortedMap
 * @define coll mutable sorted map
 */
trait SortedMap[A, B]
  extends Map[A, B]
  with collection.SortedMap[A, B]
  with MapLike[A, B, SortedMap[A, B]]
  with SortedMapLike[A, B, SortedMap[A, B]] {

  override protected[this] def newBuilder: Builder[(A, B), SortedMap[A, B]] = SortedMap.newBuilder[A, B]

  override def empty: SortedMap[A, B] = SortedMap.empty

  override def updated[B1 >: B](key: A, value: B1): SortedMap[A, B1] = this + ((key, value))

  override def +[B1 >: B](kv: (A, B1)): SortedMap[A, B1] = clone().asInstanceOf[SortedMap[A, B1]] += kv

  override def +[B1 >: B](elem1: (A, B1), elem2: (A, B1), elems: (A, B1)*): SortedMap[A, B1] =
    clone().asInstanceOf[SortedMap[A, B1]] += elem1 += elem2 ++= elems

  override def ++[B1 >: B](xs: GenTraversableOnce[(A, B1)]): SortedMap[A, B1] =
    clone().asInstanceOf[SortedMap[A, B1]] ++= xs.seq
}

/**
 * $factoryInfo
 *
 * @define Coll mutable.SortedMap
 * @define coll mutable sorted map
 */
object SortedMap extends MutableSortedMapFactory[SortedMap] {

  def empty[A, B](implicit ord: Ordering[A]): SortedMap[A, B] = TreeMap.empty[A, B]

  /** $sortedMapCanBuildFromInfo */
  implicit def canBuildFrom[A, B](implicit ord: Ordering[A]): CanBuildFrom[Coll, (A, B), SortedMap[A, B]] =
    new SortedMapCanBuildFrom[A, B]
}

/** Explicit instantiation of the `SortedMap` trait to reduce class file size in subclasses. */
abstract class AbstractSortedMap[A, B] extends scala.collection.mutable.AbstractMap[A, B] with SortedMap[A, B]