blob: 20e5a1e6b5459c6d2a776a43dab1c3c4c58d73d5 (
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
58
59
|
/* __ *\
** ________ ___ / / ___ 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 SetClass[A, HashSet]
with MutableSetTemplate[A, HashSet[A]]
with FlatHashTable[A] {
override def companion: Companion[HashSet] = HashSet
override def size = super.size
def contains(elem: A): Boolean = containsEntry(elem)
def += (elem: A): this.type = { addEntry(elem); this }
def -= (elem: A): this.type = { removeEntry(elem); this }
override def add(elem: A): Boolean = addEntry(elem)
override def remove(elem: A): Boolean = removeEntry(elem).isDefined
override def clear() = super.clear()
override def foreach[U](f: A => U) {
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] {
implicit def builderFactory[A]: BuilderFactory[A, HashSet[A], Coll] = setBuilderFactory[A]
override def empty[A]: HashSet[A] = new HashSet[A]
}
|