Skip to content

Commit

Permalink
fixup! fixup! fixup! Add SeqSet and SetFromMap implementations
Browse files Browse the repository at this point in the history
all private plus a few comments
  • Loading branch information
NthPortal committed Nov 4, 2020
1 parent 0164aea commit 463b1c7
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 13 deletions.
25 changes: 16 additions & 9 deletions src/main/scala/scala/collection/SetFromMapOps.scala
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,13 @@ import scala.annotation.implicitNotFound
import scala.collection.SetFromMapOps.WrappedMap
import scala.reflect.ClassTag

trait SetFromMapOps[
// Implementation note: The `concurrent.Set` implementation
// inherits from this, so we have to be careful about
// making changes that do more than forward to the
// underlying `Map`. If we have a method implementation
// that is not atomic, we MUST override that method in
// `concurrent.SetFromMap`.
private trait SetFromMapOps[
A,
+MM[K, V] <: MapOps[K, V, MM, _],
+M <: MapOps[A, Unit, MM, M],
Expand Down Expand Up @@ -170,17 +176,18 @@ trait SetFromMapOps[
override def view: View[A] = underlying.keySet.view
}

object SetFromMapOps {
private object SetFromMapOps {

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

trait DynamicClassName { self: Iterable[_] =>
trait DynamicClassName {
self: Iterable[_] =>
protected[collection] val underlying: Iterable[_]

override protected[this] def className: String = s"SetFrom_${underlying.collectionClassName}"
override protected[this] def className: String = s"SetFrom_${ underlying.collectionClassName }"
}

// unknown whether mutable or immutable
Expand Down Expand Up @@ -281,7 +288,7 @@ object SetFromMapOps {

}

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

}

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

}

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

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

abstract class SortedSetFromMapMetaFactory[MM[K, V] <: SortedMap[K, V], +CC[A] <: SortedSet[A]]
private abstract class SortedSetFromMapMetaFactory[MM[K, V] <: SortedMap[K, V], +CC[A] <: SortedSet[A]]
extends SetFromMapMetaFactoryBase[MM, CC] {
def apply(factory: SortedMapFactory[MM]): SortedIterableFactory[CC]
}
4 changes: 2 additions & 2 deletions src/main/scala/scala/collection/immutable/SetFromMap.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ package immutable

import scala.collection.generic.DefaultSerializable

trait SetFromMapOps[
private trait SetFromMapOps[
A,
+MM[K, +V] <: MapOps[K, V, MM, _],
+M <: MapOps[A, Unit, MM, M],
Expand All @@ -30,7 +30,7 @@ trait SetFromMapOps[
override def removedAll(that: IterableOnce[A]): C = fromSpecificMap(underlying removedAll that)
}

object SetFromMapOps {
private object SetFromMapOps {

trait Unsorted[
A,
Expand Down
11 changes: 9 additions & 2 deletions src/main/scala/scala/collection/mutable/SetFromMap.scala
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,13 @@ package mutable
import scala.collection.SetFromMapOps.WrappedMap
import scala.collection.generic.DefaultSerializable

trait SetFromMapOps[
// Implementation note: The `concurrent.Set` implementation
// inherits from this, so we have to be careful about
// making changes that do more than forward to the
// underlying `Map`. If we have a method implementation
// that is not atomic, we MUST override that method in
// `concurrent.SetFromMap`.
private[collection] trait SetFromMapOps[
A,
+MM[K, V] <: MapOps[K, V, MM, _],
+M <: MapOps[A, Unit, MM, M],
Expand Down Expand Up @@ -46,7 +52,8 @@ trait SetFromMapOps[

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

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

@SerialVersionUID(3L)
Expand Down

0 comments on commit 463b1c7

Please sign in to comment.