Skip to content

Commit 7edb842

Browse files
committed
fixup! fixup! fixup! Add SeqSet and SetFromMap implementations
all private plus a few comments
1 parent 2fd665d commit 7edb842

File tree

3 files changed

+31
-15
lines changed

3 files changed

+31
-15
lines changed

src/main/scala/scala/collection/SetFromMapOps.scala

+20-11
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,13 @@ import scala.annotation.implicitNotFound
1717
import scala.collection.SetFromMapOps.WrappedMap
1818
import scala.reflect.ClassTag
1919

20-
trait SetFromMapOps[
20+
// Implementation note: The `concurrent.Set` implementation
21+
// inherits from this, so we have to be careful about
22+
// making changes that do more than forward to the
23+
// underlying `Map`. If we have a method implementation
24+
// that is not atomic, we MUST override that method in
25+
// `concurrent.SetFromMap`.
26+
private trait SetFromMapOps[
2127
A,
2228
+MM[K, V] <: MapOps[K, V, MM, _],
2329
+M <: MapOps[A, Unit, MM, M],
@@ -189,14 +195,15 @@ trait SetFromMapOps[
189195
override def view: View[A] = underlying.keySet.view
190196
}
191197

192-
object SetFromMapOps {
198+
private object SetFromMapOps {
193199

194200
// top type to make pattern matching easier
195201
sealed trait WrappedMap[A] extends IterableOnce[A] {
196202
protected[collection] val underlying: IterableOnce[(A, Unit)]
197203
}
198204

199-
trait DynamicClassName { self: Iterable[_] =>
205+
trait DynamicClassName {
206+
self: Iterable[_] =>
200207
protected[collection] val underlying: Iterable[_]
201208

202209
override protected[this] def className: String = s"SetFrom_${underlying.collectionClassName}"
@@ -302,7 +309,7 @@ object SetFromMapOps {
302309

303310
}
304311

305-
abstract class SetFromMapFactory[+MM[K, V] <: Map[K, V], +CC[A] <: WrappedMap[A]](
312+
private abstract class SetFromMapFactory[+MM[K, V] <: Map[K, V], +CC[A] <: WrappedMap[A]](
306313
mf: MapFactory[MM]
307314
) extends IterableFactory[CC]
308315
with Serializable {
@@ -339,9 +346,10 @@ abstract class SetFromMapFactory[+MM[K, V] <: Map[K, V], +CC[A] <: WrappedMap[A]
339346

340347
}
341348

342-
abstract class SortedSetFromMapFactory[+MM[K, V] <: SortedMap[K, V], +CC[A] <: WrappedMap[A]](
343-
mf: SortedMapFactory[MM]
344-
) extends SortedIterableFactory[CC]
349+
private abstract class SortedSetFromMapFactory[+MM[K, V] <: SortedMap[K, V], +CC[A] <: WrappedMap[
350+
A
351+
]](mf: SortedMapFactory[MM])
352+
extends SortedIterableFactory[CC]
345353
with Serializable {
346354
protected[this] def fromMap[A: Ordering](map: MM[A, Unit]): CC[A]
347355

@@ -376,16 +384,17 @@ abstract class SortedSetFromMapFactory[+MM[K, V] <: SortedMap[K, V], +CC[A] <: W
376384

377385
}
378386

379-
sealed abstract class SetFromMapMetaFactoryBase[MM[K, V] <: Map[K, V], +CC[A] <: Set[A]] {
387+
private sealed abstract class SetFromMapMetaFactoryBase[MM[K, V] <: Map[K, V], +CC[A] <: Set[A]] {
380388
def apply[A](map: MM[A, Unit]): CC[A]
381389
}
382390

383-
abstract class SetFromMapMetaFactory[MM[K, V] <: Map[K, V], +CC[A] <: Set[A]]
391+
private abstract class SetFromMapMetaFactory[MM[K, V] <: Map[K, V], +CC[A] <: Set[A]]
384392
extends SetFromMapMetaFactoryBase[MM, CC] {
385393
def apply(factory: MapFactory[MM]): IterableFactory[CC]
386394
}
387395

388-
abstract class SortedSetFromMapMetaFactory[MM[K, V] <: SortedMap[K, V], +CC[A] <: SortedSet[A]]
389-
extends SetFromMapMetaFactoryBase[MM, CC] {
396+
private abstract class SortedSetFromMapMetaFactory[MM[K, V] <: SortedMap[K, V], +CC[A] <: SortedSet[
397+
A
398+
]] extends SetFromMapMetaFactoryBase[MM, CC] {
390399
def apply(factory: SortedMapFactory[MM]): SortedIterableFactory[CC]
391400
}

src/main/scala/scala/collection/immutable/SetFromMap.scala

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ package immutable
1616

1717
import scala.collection.generic.DefaultSerializable
1818

19-
trait SetFromMapOps[
19+
private trait SetFromMapOps[
2020
A,
2121
+MM[K, +V] <: MapOps[K, V, MM, _],
2222
+M <: MapOps[A, Unit, MM, M],
@@ -29,7 +29,7 @@ trait SetFromMapOps[
2929
override def removedAll(that: IterableOnce[A]): C = fromSpecificMap(underlying removedAll that)
3030
}
3131

32-
object SetFromMapOps {
32+
private object SetFromMapOps {
3333

3434
trait Unsorted[
3535
A,

src/main/scala/scala/collection/mutable/SetFromMap.scala

+9-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,13 @@ package mutable
1717
import scala.collection.SetFromMapOps.WrappedMap
1818
import scala.collection.generic.DefaultSerializable
1919

20-
trait SetFromMapOps[
20+
// Implementation note: The `concurrent.Set` implementation
21+
// inherits from this, so we have to be careful about
22+
// making changes that do more than forward to the
23+
// underlying `Map`. If we have a method implementation
24+
// that is not atomic, we MUST override that method in
25+
// `concurrent.SetFromMap`.
26+
private[collection] trait SetFromMapOps[
2127
A,
2228
+MM[K, V] <: MapOps[K, V, MM, _],
2329
+M <: MapOps[A, Unit, MM, M],
@@ -45,7 +51,8 @@ trait SetFromMapOps[
4551

4652
override def subtractAll(xs: IterableOnce[A]): this.type = { underlying.subtractAll(xs); this }
4753

48-
override def knownSize: Int = underlying.knownSize
54+
// We need to define this explicitly because there's a multiple inheritance diamond
55+
override def knownSize: Int = super[SetFromMapOps].knownSize
4956
}
5057

5158
@SerialVersionUID(3L)

0 commit comments

Comments
 (0)