blob: d4a2434b43ba0d7a5920e56e42f984142b4372da (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
/* __ *\
** ________ ___ / / ___ Scala API **
** / __/ __// _ | / / / _ | (c) 2003-2009, LAMP/EPFL **
** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ **
** /____/\___/_/ |_/____/_/ | | **
** |/ **
\* */
// $Id$
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
*/
@serializable
class HashSet[A] extends Set[A] with SetTemplate[A, HashSet[A]] with FlatHashTable[A] {
override def empty = HashSet.empty
override def traversableBuilder[B]: Builder[B, HashSet[B]] = HashSet.newBuilder[B]
override def size = super.size
def contains(elem: A): Boolean = containsEntry(elem)
def +=(elem: A) { addEntry(elem) }
def -=(elem: A) { removeEntry(elem) }
override def clear() = super.clear()
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.traversableBuilder[A] }
def empty[A]: HashSet[A] = new HashSet[A]
}
|