Skip to content

Commit

Permalink
Add HashMaps to stdlib
Browse files Browse the repository at this point in the history
  • Loading branch information
odersky committed Nov 1, 2023
1 parent dfc4712 commit 45c7724
Show file tree
Hide file tree
Showing 5 changed files with 1,518 additions and 5 deletions.
6 changes: 3 additions & 3 deletions tests/pos-special/stdlib/collection/Seq.scala
Original file line number Diff line number Diff line change
Expand Up @@ -893,7 +893,7 @@ trait SeqOps[+A, +CC[_], +C] extends Any with SeqViewOps[A, CC, C] { self =>
* part of the result, but any following occurrences will.
*/
def diff[B >: A](that: Seq[B]): C = {
val occ = occCounts(that)
val occ = occCounts[B @uncheckedCaptures](that)
fromSpecific(iterator.filter { x =>
var include = false
occ.updateWith(x) {
Expand All @@ -918,7 +918,7 @@ trait SeqOps[+A, +CC[_], +C] extends Any with SeqViewOps[A, CC, C] { self =>
* in the result, but any following occurrences will be omitted.
*/
def intersect[B >: A](that: Seq[B]): C = {
val occ = occCounts(that)
val occ = occCounts[B @uncheckedCaptures](that)
fromSpecific(iterator.filter { x =>
var include = true
occ.updateWith(x) {
Expand Down Expand Up @@ -966,7 +966,7 @@ trait SeqOps[+A, +CC[_], +C] extends Any with SeqViewOps[A, CC, C] { self =>
iterableFactory.from(new View.Updated(this, index, elem))
}

protected[collection] def occCounts[B](sq: Seq[B]): mutable.Map[B, Int] = {
protected[collection] def occCounts[sealed B](sq: Seq[B]): mutable.Map[B, Int] = {
val occ = new mutable.HashMap[B, Int]()
for (y <- sq) occ.updateWith(y) {
case None => Some(1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

package scala.collection
import language.experimental.captureChecking
import scala.annotation.unchecked.uncheckedCaptures

/**
* Trait that overrides operations on sequences in order
Expand Down Expand Up @@ -79,7 +80,7 @@ trait StrictOptimizedSeqOps [+A, +CC[_], +C]
override def diff[B >: A](that: Seq[B]): C =
if (isEmpty || that.isEmpty) coll
else {
val occ = occCounts(that)
val occ = occCounts[B @uncheckedCaptures](that)
val b = newSpecificBuilder
for (x <- this) {
occ.updateWith(x) {
Expand All @@ -97,7 +98,7 @@ trait StrictOptimizedSeqOps [+A, +CC[_], +C]
override def intersect[B >: A](that: Seq[B]): C =
if (isEmpty || that.isEmpty) empty
else {
val occ = occCounts(that)
val occ = occCounts[B @uncheckedCaptures](that)
val b = newSpecificBuilder
for (x <- this) {
occ.updateWith(x) {
Expand Down
Loading

0 comments on commit 45c7724

Please sign in to comment.