Skip to content

Commit 11009b4

Browse files
committed
Make remove operation of mutable.Set return a Boolean
Fix scala/collection-strawman#551
1 parent b784d65 commit 11009b4

File tree

6 files changed

+11
-15
lines changed

6 files changed

+11
-15
lines changed

src/compiler/scala/tools/nsc/typechecker/Typers.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2502,7 +2502,7 @@ trait Typers extends Adaptations with Tags with TypersTracking with PatternTyper
25022502

25032503
// Remove ValDef for right-associative by-value operator desugaring which has been inlined into expr1
25042504
val statsTyped2 = statsTyped match {
2505-
case (vd: ValDef) :: Nil if inlinedRightAssocValDefs.remove(vd.symbol).isDefined => Nil
2505+
case (vd: ValDef) :: Nil if inlinedRightAssocValDefs.remove(vd.symbol) => Nil
25062506
case _ => statsTyped
25072507
}
25082508

src/library/scala/collection/convert/Wrappers.scala

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ private[collection] trait Wrappers {
178178
sz < underlying.size
179179
}
180180
override def remove(elem: AnyRef) =
181-
try underlying.remove(elem.asInstanceOf[A]).isDefined
181+
try underlying.remove(elem.asInstanceOf[A])
182182
catch { case ex: ClassCastException => false }
183183
override def clear() = underlying.clear()
184184
}
@@ -195,8 +195,7 @@ private[collection] trait Wrappers {
195195
def addOne(elem: A): this.type = { underlying add elem; this }
196196
def subtractOne(elem: A): this.type = { underlying remove elem; this }
197197

198-
//TODO Should Set.remove return the canonical element? There is no efficient way to support this for wrapped Java Sets
199-
override def remove(elem: A): Option[A] = if(underlying remove elem) Some(elem) else None
198+
override def remove(elem: A): Boolean = underlying remove elem
200199
override def clear() = underlying.clear()
201200

202201
//TODO Should Set.get be supported? There is no efficient way to return the canonical element from a Java Set

src/library/scala/collection/immutable/List.scala

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,6 @@ import java.io.{ObjectInputStream, ObjectOutputStream}
77
import scala.annotation.unchecked.uncheckedVariance
88
import scala.annotation.tailrec
99
import mutable.{Builder, ListBuffer, ReusableBuilder}
10-
import scala.collection.{LinearSeq, Seq}
11-
12-
1310

1411
/** A class for immutable linked lists representing ordered collections
1512
* of elements of type `A`.

src/library/scala/collection/mutable/LinkedHashSet.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,17 +72,17 @@ class LinkedHashSet[A]
7272
this
7373
}
7474

75-
override def remove(elem: A): Option[A] = {
75+
override def remove(elem: A): Boolean = {
7676
val e = table.removeEntry(elem)
77-
if (e eq null) None
77+
if (e eq null) false
7878
else {
7979
if (e.earlier eq null) firstEntry = e.later
8080
else e.earlier.later = e.later
8181
if (e.later eq null) lastEntry = e.earlier
8282
else e.later.earlier = e.earlier
8383
e.earlier = null // Null references to prevent nepotism
8484
e.later = null
85-
Some(e.key)
85+
true
8686
}
8787
}
8888

src/library/scala/collection/mutable/Set.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,8 @@ trait SetOps[A, +CC[X], +C <: SetOps[A, CC, C]]
6262
else remove(elem)
6363
}
6464

65-
def remove(elem: A): Option[A] = {
66-
val res = get(elem)
65+
def remove(elem: A): Boolean = {
66+
val res = contains(elem)
6767
coll -= elem
6868
res
6969
}

test/files/run/hashsetremove.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ import scala.collection.mutable.HashSet
44
object Test extends App {
55
val h = new HashSet[Int]
66
h += 1
7-
assert(h.remove(0) == None)
7+
assert(!h.remove(0))
88
assert(h(1))
9-
assert(h.remove(1) == Some(1))
9+
assert(h.remove(1))
1010
assert(!h(1))
11-
assert(h.remove(1) == None)
11+
assert(!h.remove(1))
1212
assert(!h(1))
1313
}

0 commit comments

Comments
 (0)