summaryrefslogtreecommitdiff
path: root/src/library/scalax/collection/immutable/Set.scala
blob: 9462cd3c5f044e2e62eb05aefd20d0353e469655 (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
/*                     __                                               *\
**     ________ ___   / /  ___     Scala API                            **
**    / __/ __// _ | / /  / _ |    (c) 2003-2009, LAMP/EPFL             **
**  __\ \/ /__/ __ |/ /__/ __ |    http://scala-lang.org/               **
** /____/\___/_/ |_/____/_/ | |                                         **
**                          |/                                          **
\*                                                                      */

// $Id: Set.scala 16893 2009-01-13 13:09:22Z cunei $


package scalax.collection.immutable

import generic._

object Set extends generic.SetFactory[Set] {
  private val hashSeed = "Set".hashCode
  def empty[A]: Set[A] = new EmptySet[A]
}

trait Set[A] extends OrderedIterable[A]
                with collection.Set[A]
                with SetTemplate[Set, A] {

  override def newBuilder[B]: Builder[Set, B] = Set.newBuilder[B]

  /** Compares this set with another object and returns true, iff the
   *  other object is also a set which contains the same elements as
   *  this set.
   *
   *  @param that the other object
   *  @note not necessarily run-time type safe.
   *  @return     <code>true</code> iff this set and the other set
   *              contain the same elements.
   */
  override def equals(that: Any): Boolean = that match {
    case other: Set[_] =>
      this.size == other.size && subsetOf(other.asInstanceOf[Set[A]])
    case _ =>
      false
  }

  override def hashCode = (Set.hashSeed /: this)(_ * 41 + _.hashCode)

}