Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 463b1c7

Browse files
committedNov 4, 2020
fixup! fixup! fixup! Add SeqSet and SetFromMap implementations
all private plus a few comments
1 parent 0164aea commit 463b1c7

File tree

3 files changed

+27
-13
lines changed

3 files changed

+27
-13
lines changed
 

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

+16-9
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],
@@ -170,17 +176,18 @@ trait SetFromMapOps[
170176
override def view: View[A] = underlying.keySet.view
171177
}
172178

173-
object SetFromMapOps {
179+
private object SetFromMapOps {
174180

175181
// top type to make pattern matching easier
176182
sealed trait WrappedMap[A] extends IterableOnce[A] {
177183
protected[collection] val underlying: IterableOnce[(A, Unit)]
178184
}
179185

180-
trait DynamicClassName { self: Iterable[_] =>
186+
trait DynamicClassName {
187+
self: Iterable[_] =>
181188
protected[collection] val underlying: Iterable[_]
182189

183-
override protected[this] def className: String = s"SetFrom_${underlying.collectionClassName}"
190+
override protected[this] def className: String = s"SetFrom_${ underlying.collectionClassName }"
184191
}
185192

186193
// unknown whether mutable or immutable
@@ -281,7 +288,7 @@ object SetFromMapOps {
281288

282289
}
283290

284-
abstract class SetFromMapFactory[+MM[K, V] <: Map[K, V], +CC[A] <: WrappedMap[A]](mf: MapFactory[MM])
291+
private abstract class SetFromMapFactory[+MM[K, V] <: Map[K, V], +CC[A] <: WrappedMap[A]](mf: MapFactory[MM])
285292
extends IterableFactory[CC]
286293
with Serializable {
287294
protected[this] def fromMap[A](map: MM[A, Unit]): CC[A]
@@ -317,7 +324,7 @@ abstract class SetFromMapFactory[+MM[K, V] <: Map[K, V], +CC[A] <: WrappedMap[A]
317324

318325
}
319326

320-
abstract class SortedSetFromMapFactory[+MM[K, V] <: SortedMap[K, V], +CC[A] <: WrappedMap[A]](mf: SortedMapFactory[MM])
327+
private abstract class SortedSetFromMapFactory[+MM[K, V] <: SortedMap[K, V], +CC[A] <: WrappedMap[A]](mf: SortedMapFactory[MM])
321328
extends SortedIterableFactory[CC]
322329
with Serializable {
323330
protected[this] def fromMap[A: Ordering](map: MM[A, Unit]): CC[A]
@@ -353,16 +360,16 @@ abstract class SortedSetFromMapFactory[+MM[K, V] <: SortedMap[K, V], +CC[A] <: W
353360

354361
}
355362

356-
sealed abstract class SetFromMapMetaFactoryBase[MM[K, V] <: Map[K, V], +CC[A] <: Set[A]] {
363+
private sealed abstract class SetFromMapMetaFactoryBase[MM[K, V] <: Map[K, V], +CC[A] <: Set[A]] {
357364
def apply[A](map: MM[A, Unit]): CC[A]
358365
}
359366

360-
abstract class SetFromMapMetaFactory[MM[K, V] <: Map[K, V], +CC[A] <: Set[A]]
367+
private abstract class SetFromMapMetaFactory[MM[K, V] <: Map[K, V], +CC[A] <: Set[A]]
361368
extends SetFromMapMetaFactoryBase[MM, CC] {
362369
def apply(factory: MapFactory[MM]): IterableFactory[CC]
363370
}
364371

365-
abstract class SortedSetFromMapMetaFactory[MM[K, V] <: SortedMap[K, V], +CC[A] <: SortedSet[A]]
372+
private abstract class SortedSetFromMapMetaFactory[MM[K, V] <: SortedMap[K, V], +CC[A] <: SortedSet[A]]
366373
extends SetFromMapMetaFactoryBase[MM, CC] {
367374
def apply(factory: SortedMapFactory[MM]): SortedIterableFactory[CC]
368375
}

‎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],
@@ -30,7 +30,7 @@ trait SetFromMapOps[
3030
override def removedAll(that: IterableOnce[A]): C = fromSpecificMap(underlying removedAll that)
3131
}
3232

33-
object SetFromMapOps {
33+
private object SetFromMapOps {
3434

3535
trait Unsorted[
3636
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],
@@ -46,7 +52,8 @@ trait SetFromMapOps[
4652

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

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

5259
@SerialVersionUID(3L)

0 commit comments

Comments
 (0)
Please sign in to comment.