summaryrefslogblamecommitdiff
path: root/src/library/scala/collection/mutable/HashSet.scala
blob: 7f71b037b4fb0e0909c22abb8e5fe872547b1ae0 (plain) (tree)
1
2
3
4
5
6
7
8
9








                                                                          
                                 
 




                                                         
   
              
                                                                            





                                                            
                                                   



                                    

                                              

                           
                 
                         





                                         

                                        


                                 
     
 
/*                     __                                               *\
**     ________ ___   / /  ___     Scala API                            **
**    / __/ __// _ | / /  / _ |    (c) 2003, LAMP/EPFL                  **
**  __\ \/ /__/ __ |/ /__/ __ |                                         **
** /____/\___/_/ |_/____/_/ | |                                         **
**                          |/                                          **
** $Id$
\*                                                                      */

package scala.collection.mutable;


/** This class implements mutable sets using a hashtable.
 *
 *  @author  Matthias Zenger
 *  @version 1.0, 08/07/2003
 */
[serializable]
class HashSet[A] extends scala.collection.mutable.Set[A] with HashTable[A] {

    def contains(elem: A): Boolean = findEntry(elem) match {
        case None => false
        case Some(_) => true
    }

    def +=(elem: A): Unit = findEntry(elem) match {
        case None => addEntry(elem);
        case Some(_) =>
    }

    def -=(elem: A): Unit = removeEntry(elem);

    def elements = entries;

    def clear = {
        initTable(table);
        tableSize = 0;
    }

    protected type Entry = A;

    protected def entryKey(e: Entry) = e;

    override def clone(): HashSet[A] = {
        val res = new HashSet[A];
        res ++= this;
        res
    }
}