summaryrefslogtreecommitdiff
path: root/src/library/scala/collection/mutable/HashSet.scala
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2009-05-08 16:33:15 +0000
committerMartin Odersky <odersky@gmail.com>2009-05-08 16:33:15 +0000
commit14a631a5fec42d04d0723355a0b93e482b5e4662 (patch)
treef639c2a22e89e193b9abea391993ecfd4d5326ee /src/library/scala/collection/mutable/HashSet.scala
parent2379eb4ebbd28c8892b50a1d9fa8a687099eea4d (diff)
downloadscala-14a631a5fec42d04d0723355a0b93e482b5e4662.tar.gz
scala-14a631a5fec42d04d0723355a0b93e482b5e4662.tar.bz2
scala-14a631a5fec42d04d0723355a0b93e482b5e4662.zip
massive new collections checkin.
Diffstat (limited to 'src/library/scala/collection/mutable/HashSet.scala')
-rw-r--r--src/library/scala/collection/mutable/HashSet.scala36
1 files changed, 25 insertions, 11 deletions
diff --git a/src/library/scala/collection/mutable/HashSet.scala b/src/library/scala/collection/mutable/HashSet.scala
index 019d79ed09..14f2d00013 100644
--- a/src/library/scala/collection/mutable/HashSet.scala
+++ b/src/library/scala/collection/mutable/HashSet.scala
@@ -11,24 +11,21 @@
package scala.collection.mutable
+import generic._
+
/** This class implements mutable sets using a hashtable.
*
* @author Matthias Zenger
* @author Martin Odersky
* @version 2.0, 31/12/2006
*/
-object HashSet {
+@serializable
+class HashSet[A] extends Set[A] with SetTemplate[A, HashSet[A]] with FlatHashTable[A] {
- /** The empty map of this type */
- def empty[A] = new HashSet[A]
+ override def empty = HashSet.empty
+ override def traversibleBuilder[B]: Builder[B, HashSet[B], Any] = HashSet.newBuilder[B]
- /** The canonical factory for this type
- */
- def apply[A](elems: A*) = empty[A] ++ elems
-}
-
-@serializable
-class HashSet[A] extends Set[A] with FlatHashTable[A] {
+ override def size = super.size
def contains(elem: A): Boolean = containsEntry(elem)
@@ -38,6 +35,23 @@ class HashSet[A] extends Set[A] with FlatHashTable[A] {
override def clear() = super.clear()
- override def clone(): Set[A] = new HashSet[A] ++ this
+ override def foreach(f: A => Unit) {
+ var i = 0
+ val len = table.length
+ while (i < len) {
+ val elem = table(i)
+ if (elem ne null) f(elem.asInstanceOf[A])
+ i += 1
+ }
+ }
+
+ override def clone(): HashSet[A] = new HashSet[A] ++ this
+}
+
+/** Factory object for `HashSet` class */
+object HashSet extends SetFactory[HashSet] {
+ type Coll = HashSet[_]
+ implicit def builderFactory[A]: BuilderFactory[A, HashSet[A], Coll] = new BuilderFactory[A, HashSet[A], Coll] { def apply(from: Coll) = from.traversibleBuilder[A] }
+ def empty[A]: HashSet[A] = new HashSet[A]
}