diff options
author | Paul Phillips <paulp@improving.org> | 2013-01-06 14:37:21 -0800 |
---|---|---|
committer | Paul Phillips <paulp@improving.org> | 2013-01-06 14:37:21 -0800 |
commit | 2d0fb869fc7b813f562417372120bb25cb636642 (patch) | |
tree | b89dc6023957b61c0566ede654c9ee305fc5e650 | |
parent | 38ff53cc80de5792247d2aac5fb6e4fc2f59600d (diff) | |
parent | affa98fa54893830b88a9ebebd5d29740f10114c (diff) | |
download | scala-2d0fb869fc7b813f562417372120bb25cb636642.tar.gz scala-2d0fb869fc7b813f562417372120bb25cb636642.tar.bz2 scala-2d0fb869fc7b813f562417372120bb25cb636642.zip |
Merge pull request #1847 from JamesIry/SI-6916_master
SI-6916 makes FlatHashTable#remove a Boolean not Option[A]
-rw-r--r-- | src/library/scala/collection/mutable/FlatHashTable.scala | 11 | ||||
-rw-r--r-- | src/library/scala/collection/mutable/HashSet.scala | 2 | ||||
-rw-r--r-- | test/files/run/hashsetremove.check | 6 | ||||
-rw-r--r-- | test/files/run/hashsetremove.scala | 13 |
4 files changed, 27 insertions, 5 deletions
diff --git a/src/library/scala/collection/mutable/FlatHashTable.scala b/src/library/scala/collection/mutable/FlatHashTable.scala index 9f7193495d..7f4a8d1cbd 100644 --- a/src/library/scala/collection/mutable/FlatHashTable.scala +++ b/src/library/scala/collection/mutable/FlatHashTable.scala @@ -160,8 +160,11 @@ trait FlatHashTable[A] extends FlatHashTable.HashUtils[A] { } - /** Removes an elem from the hash table, returning an option value with the element, or `None` if it didn't exist. */ - protected def removeElem(elem: A) : Option[A] = { + /** + * Removes an elem from the hash table returning true if the element was found (and thus removed) + * or false if it didn't exist. + */ + protected def removeElem(elem: A) : Boolean = { if (tableDebug) checkConsistent() def precedes(i: Int, j: Int) = { val d = table.length >> 1 @@ -189,12 +192,12 @@ trait FlatHashTable[A] extends FlatHashTable.HashUtils[A] { tableSize -= 1 nnSizeMapRemove(h0) if (tableDebug) checkConsistent() - return Some(entryToElem(curEntry)) + return true } h = (h + 1) % table.length curEntry = table(h) } - None + false } protected def iterator: Iterator[A] = new AbstractIterator[A] { diff --git a/src/library/scala/collection/mutable/HashSet.scala b/src/library/scala/collection/mutable/HashSet.scala index cbbb4aaa5a..b5fa557687 100644 --- a/src/library/scala/collection/mutable/HashSet.scala +++ b/src/library/scala/collection/mutable/HashSet.scala @@ -63,7 +63,7 @@ extends AbstractSet[A] override def add(elem: A): Boolean = addElem(elem) - override def remove(elem: A): Boolean = removeElem(elem).isDefined + override def remove(elem: A): Boolean = removeElem(elem) override def clear() { clearTable() } diff --git a/test/files/run/hashsetremove.check b/test/files/run/hashsetremove.check new file mode 100644 index 0000000000..8de9826895 --- /dev/null +++ b/test/files/run/hashsetremove.check @@ -0,0 +1,6 @@ +remove 0 should be false, was false +contains 1 should be true, was true +remove 1 should be true, was true +contains 1 should be false, was false +remove 1 should be false, was false +contains 1 should be false, was false diff --git a/test/files/run/hashsetremove.scala b/test/files/run/hashsetremove.scala new file mode 100644 index 0000000000..7b82a9909b --- /dev/null +++ b/test/files/run/hashsetremove.scala @@ -0,0 +1,13 @@ +import scala.collection.mutable.HashSet + + +object Test extends App { + val h = new HashSet[Int] + h += 1 + println(s"remove 0 should be false, was ${h remove 0}") + println(s"contains 1 should be true, was ${h contains 1}") + println(s"remove 1 should be true, was ${h remove 1}") + println(s"contains 1 should be false, was ${h contains 1}") + println(s"remove 1 should be false, was ${h remove 1}") + println(s"contains 1 should be false, was ${h contains 1}") + }
\ No newline at end of file |