@@ -23,24 +23,24 @@ import scala.collection.immutable.Map.useBaseline
23
23
* @define Coll `immutable.VectorMap`
24
24
*/
25
25
final class VectorMap [K , + V ] private [immutable] (
26
- val fields : Vector [K ],
27
- val underlying : Map [K , (Int , V )])
26
+ private val fields : Vector [K ],
27
+ private val underlying : Map [K , (Int , V )])
28
28
extends AbstractMap [K , V ]
29
29
with LinkedMap [K , V ]
30
30
with MapOps [K , V , VectorMap , VectorMap [K , V ]]
31
31
with StrictOptimizedIterableOps [(K , V ), Iterable , VectorMap [K , V ]] {
32
32
33
33
override protected [this ] def className : String = " VectorMap"
34
34
35
- override def updated [V1 >: V ](key : K , value : V1 ): VectorMap [K , V1 ] = {
36
- if ( underlying.get(key).isDefined) {
37
- val oldKey = underlying(key)._1
38
- new VectorMap (fields,
39
- underlying.updated(key, (oldKey , value. asInstanceOf [ V ] )))
40
- } else {
41
- new VectorMap (
42
- fields :+ key,
43
- underlying.updated(key, (fields.length + 1 , value. asInstanceOf [ V ] )))
35
+ def updated [V1 >: V ](key : K , value : V1 ): VectorMap [K , V1 ] = {
36
+ underlying.get(key) match {
37
+ case Some (oldIndexWithValue) =>
38
+ new VectorMap (fields,
39
+ underlying.updated(key, (oldIndexWithValue._1 , value)))
40
+ case None =>
41
+ new VectorMap (
42
+ fields :+ key,
43
+ underlying.updated(key, (fields.length + 1 , value)))
44
44
}
45
45
}
46
46
@@ -49,7 +49,7 @@ final class VectorMap[K, +V] private[immutable] (
49
49
50
50
override def withDefaultValue [V1 >: V ](d : V1 ): Map .WithDefault [K , V1 ] = new Map .WithDefault [K , V1 ](this , _ => d)
51
51
52
- override def iterator : Iterator [(K , V )] = new Iterator [(K , V )] {
52
+ def iterator : Iterator [(K , V )] = new Iterator [(K , V )] {
53
53
private val fieldsIterator = fields.iterator
54
54
55
55
override def hasNext : Boolean = fieldsIterator.hasNext
@@ -60,12 +60,12 @@ final class VectorMap[K, +V] private[immutable] (
60
60
}
61
61
}
62
62
63
- override def get (key : K ): Option [V ] = underlying.get(key) match {
63
+ def get (key : K ): Option [V ] = underlying.get(key) match {
64
64
case Some (v) => Some (v._2)
65
65
case None => None
66
66
}
67
67
68
- override def remove (key : K ): VectorMap [K , V ] = {
68
+ def remove (key : K ): VectorMap [K , V ] = {
69
69
underlying.get(key) match {
70
70
case Some ((index, _)) =>
71
71
new VectorMap (fields.patch(index, Nil , 1 ), underlying - key)
@@ -99,22 +99,17 @@ final class VectorMap[K, +V] private[immutable] (
99
99
}
100
100
101
101
override def tail : VectorMap [K , V ] = {
102
- val tail = fields.last
103
-
104
- new VectorMap (fields.slice(1 , fields.size), underlying.remove(tail))
102
+ new VectorMap (fields.tail, underlying.remove(fields.last))
105
103
}
106
104
107
105
override def init : VectorMap [K , V ] = {
108
- val head = fields.head
109
-
110
- new VectorMap (fields.slice(1 , fields.size - 0 ), underlying.remove(head))
106
+ new VectorMap (fields.init, underlying.remove(fields.head))
111
107
}
112
108
113
109
// Only care about content, not ordering for equality
114
110
override def equals (that : Any ): Boolean =
115
111
that match {
116
- case vmap : VectorMap [K , V ] =>
117
- underlying == vmap.underlying
112
+ case vmap : VectorMap [_, _] => underlying == vmap.underlying
118
113
case _ => super .equals(that)
119
114
}
120
115
0 commit comments