@@ -3,25 +3,25 @@ package scala.collection
3
3
import scala .annotation .unchecked .uncheckedVariance
4
4
5
5
/**
6
- * Multiset whose elements are sorted
6
+ * Bag whose elements are sorted
7
7
* @tparam A Type of elements
8
8
*/
9
- trait SortedMultiSet [A ]
10
- extends MultiSet [A ]
11
- with SortedMultiSetOps [A , SortedMultiSet , SortedMultiSet [A ]] {
9
+ trait SortedBag [A ]
10
+ extends Bag [A ]
11
+ with SortedBagOps [A , SortedBag , SortedBag [A ]] {
12
12
13
- def unsorted : MultiSet [A ] = this
13
+ def unsorted : Bag [A ] = this
14
14
15
- def sortedIterableFactory : SortedIterableFactory [SortedMultiSet ] = SortedMultiSet
16
- override protected def fromSpecific (coll : IterableOnce [A ]): SortedMultiSet [A ] = sortedIterableFactory.from(coll)(ordering)
17
- override protected def newSpecificBuilder : mutable.Builder [A , SortedMultiSet [A ]] = sortedIterableFactory.newBuilder(ordering)
18
- override def empty : SortedMultiSet [A ] = sortedIterableFactory.empty(ordering)
19
- override def withFilter (p : A => Boolean ): SortedMultiSetOps .WithFilter [A , MultiSet , SortedMultiSet ] = new SortedMultiSetOps .WithFilter (this , p)
15
+ def sortedIterableFactory : SortedIterableFactory [SortedBag ] = SortedBag
16
+ override protected def fromSpecific (coll : IterableOnce [A ]): SortedBag [A ] = sortedIterableFactory.from(coll)(ordering)
17
+ override protected def newSpecificBuilder : mutable.Builder [A , SortedBag [A ]] = sortedIterableFactory.newBuilder(ordering)
18
+ override def empty : SortedBag [A ] = sortedIterableFactory.empty(ordering)
19
+ override def withFilter (p : A => Boolean ): SortedBagOps .WithFilter [A , Bag , SortedBag ] = new SortedBagOps .WithFilter (this , p)
20
20
21
21
}
22
22
23
- trait SortedMultiSetOps [A , + CC [X ] <: MultiSet [X ], + C <: MultiSet [A ]]
24
- extends MultiSetOps [A , MultiSet , C ]
23
+ trait SortedBagOps [A , + CC [X ] <: Bag [X ], + C <: Bag [A ]]
24
+ extends BagOps [A , Bag , C ]
25
25
with SortedOps [A , C ] {
26
26
27
27
def sortedIterableFactory : SortedIterableFactory [CC ]
@@ -30,8 +30,8 @@ trait SortedMultiSetOps[A, +CC[X] <: MultiSet[X], +C <: MultiSet[A]]
30
30
protected def sortedFromOccurrences [B : Ordering ](it : Iterable [(B , Int )]): CC [B ] =
31
31
sortedFromIterable(it.view.flatMap { case (b, n) => new View .Fill (n)(b) })
32
32
33
- /** `this` sorted multiset upcasted to an unsorted multiset */
34
- def unsorted : MultiSet [A ]
33
+ /** `this` sorted bag upcasted to an unsorted bag */
34
+ def unsorted : Bag [A ]
35
35
36
36
def occurrences : SortedMap [A , Int ]
37
37
@@ -60,61 +60,61 @@ trait SortedMultiSetOps[A, +CC[X] <: MultiSet[X], +C <: MultiSet[A]]
60
60
rangeUntil(next)
61
61
}
62
62
63
- /** Builds a new sorted multiset by applying a function to all elements of this sorted multiset .
63
+ /** Builds a new sorted bag by applying a function to all elements of this sorted bag .
64
64
*
65
65
* @param f the function to apply to each element.
66
66
* @tparam B the element type of the returned collection.
67
67
* @return a new collection resulting from applying the given function
68
- * `f` to each element of this sorted multiset and collecting the results.
68
+ * `f` to each element of this sorted bag and collecting the results.
69
69
*/
70
70
def map [B : Ordering ](f : A => B ): CC [B ] = sortedFromIterable(new View .Map (toIterable, f))
71
71
72
72
/**
73
- * Builds a new sorted multiset by applying a function to all pairs of element and its
73
+ * Builds a new sorted bag by applying a function to all pairs of element and its
74
74
* number of occurrences.
75
75
*
76
76
* @param f the function to apply
77
77
* @tparam B the element type of the returned collection
78
78
* @return a new collection resulting from applying the given function
79
79
* `f` to each pair of element and its number of occurrences of this
80
- * sorted multiset and collecting the results.
80
+ * sorted bag and collecting the results.
81
81
*/
82
82
def mapOccurrences [B : Ordering ](f : ((A , Int )) => (B , Int )): CC [B ] =
83
83
sortedFromOccurrences(new View .Map (occurrences, f))
84
84
85
85
/**
86
86
* Builds a new collection by applying a function to all elements of this sorted
87
- * multiset and using the elements of the resulting collections.
87
+ * bag and using the elements of the resulting collections.
88
88
*
89
89
* @param f the function to apply to each element.
90
90
* @tparam B the element type of the returned collection.
91
91
* @return a new collection resulting from applying the given function `f` to
92
- * each element of this sorted multiset and concatenating the results.
92
+ * each element of this sorted bag and concatenating the results.
93
93
*/
94
94
def flatMap [B : Ordering ](f : A => IterableOnce [B ]): CC [B ] = sortedFromIterable(new View .FlatMap (toIterable, f))
95
95
96
96
/**
97
97
* Builds a new collection by applying a function to all pairs of element and
98
- * its number of occurrences of this sorted multiset and using the elements of
98
+ * its number of occurrences of this sorted bag and using the elements of
99
99
* the resulting collections.
100
100
*
101
101
* @param f the function to apply to each element.
102
102
* @tparam B the element type of the returned collection.
103
103
* @return a new collection resulting from applying the given function `f` to
104
104
* each pair of element and its number of occurrences of this sorted
105
- * multiset and concatenating the results.
105
+ * bag and concatenating the results.
106
106
*/
107
107
def flatMapOccurrences [B : Ordering ](f : ((A , Int )) => IterableOnce [(B , Int )]): CC [B ] =
108
108
sortedFromOccurrences(new View .FlatMap (occurrences, f))
109
109
110
110
/**
111
- * Returns a sorted multiset formed from this sorted multiset and another iterable
111
+ * Returns a sorted bag formed from this sorted bag and another iterable
112
112
* collection, by combining corresponding elements in pairs.
113
113
* @param that The iterable providing the second half of each result pair
114
114
* @param ev The ordering instance for type `B`
115
115
* @tparam B the type of the second half of the returned pairs
116
- * @return a new sorted multiset containing pairs consisting of corresponding elements
117
- * of this sorted multiset and `that`. The length of the returned collection
116
+ * @return a new sorted bag containing pairs consisting of corresponding elements
117
+ * of this sorted bag and `that`. The length of the returned collection
118
118
* is the minimum of the lengths of `this` and `that`
119
119
*/
120
120
def zip [B ](that : Iterable [B ])(implicit ev : Ordering [B ]): CC [(A @ uncheckedVariance, B )] = // sound bcs of VarianceNote
@@ -124,7 +124,7 @@ trait SortedMultiSetOps[A, +CC[X] <: MultiSet[X], +C <: MultiSet[A]]
124
124
* @return a new collection resulting from applying the given partial
125
125
* function `pf` to each element on which it is defined and
126
126
* collecting the results
127
- * @param pf the partial function which filters and map this sorted multiset
127
+ * @param pf the partial function which filters and map this sorted bag
128
128
* @tparam B the element type of the returned collection
129
129
*/
130
130
def collect [B : Ordering ](pf : PartialFunction [A , B ]): CC [B ] = flatMap(a =>
@@ -136,29 +136,29 @@ trait SortedMultiSetOps[A, +CC[X] <: MultiSet[X], +C <: MultiSet[A]]
136
136
* @return a new collection resulting from applying the given partial
137
137
* function `pf` to each group of occurrences on which it is defined and
138
138
* collecting the results
139
- * @param pf the partial function which filters and map this sorted multiset
139
+ * @param pf the partial function which filters and map this sorted bag
140
140
* @tparam B the element type of the returned collection
141
141
*/
142
142
def collectOccurrences [B : Ordering ](pf : PartialFunction [(A , Int ), (B , Int )]): CC [B ] = flatMapOccurrences(a =>
143
143
if (pf.isDefinedAt(a)) new View .Single (pf(a))
144
144
else View .Empty
145
145
)
146
146
147
- // --- Override return type of methods that returned an unsorted MultiSet
147
+ // --- Override return type of methods that returned an unsorted Bag
148
148
149
149
override def zipWithIndex : CC [(A , Int )] =
150
150
sortedFromIterable(new View .ZipWithIndex (toIterable))(Ordering .Tuple2 (ordering, implicitly))
151
151
152
152
}
153
153
154
- object SortedMultiSetOps {
154
+ object SortedBagOps {
155
155
156
156
/** Specialize `WithFilter` for sorted collections
157
157
*
158
158
* @define coll sorted collection
159
159
*/
160
- class WithFilter [A , + IterableCC [_], + CC [X ] <: MultiSet [X ]](
161
- `this` : SortedMultiSetOps [A , CC , _] with IterableOps [A , IterableCC , _],
160
+ class WithFilter [A , + IterableCC [_], + CC [X ] <: Bag [X ]](
161
+ `this` : SortedBagOps [A , CC , _] with IterableOps [A , IterableCC , _],
162
162
p : A => Boolean
163
163
) extends IterableOps .WithFilter [A , IterableCC ](`this`, p) {
164
164
@@ -175,4 +175,4 @@ object SortedMultiSetOps {
175
175
176
176
}
177
177
178
- object SortedMultiSet extends SortedIterableFactory .Delegate (immutable.SortedMultiSet )
178
+ object SortedBag extends SortedIterableFactory .Delegate (immutable.SortedBag )
0 commit comments