- QuotientSet
authorAlexandre Bertails <alexandre@bertails.org>
Sun, 31 Oct 2010 17:22:46 -0400
changeset 246 417d33e9fa36
parent 245 d3ea604683ee
child 247 5fcc34ecf4d0
child 249 855ab0c30782
- QuotientSet
src/main/scala/QuotientSet.scala
src/test/scala/QuotientSetTest.scala
--- a/src/main/scala/QuotientSet.scala	Sun Oct 31 17:22:21 2010 -0400
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,28 +0,0 @@
-package w3c.sw
-
-object QuotientSet {
-  def apply[A]():QuotientSet[A] = QuotientSet(Map[A,Set[A]]())
-}
-
-case class QuotientSet[A](quotient:Map[A,Set[A]]) {
-
-  def +(x:A, y:A):QuotientSet[A] = {
-    val newQ = (this(x), this(y)) match {
-      case (Some((xx, eqX)), Some((yy, eqY))) => quotient - yy + (xx -> (eqX ++ eqY))
-      case (None, None) => quotient + (x -> Set(x, y))
-      case (Some((xx, eqX)), None) => quotient + (xx -> (eqX + y))
-      case (None, Some((yy, eqY))) => quotient + (yy -> (eqY + x))
-    }
-    QuotientSet(newQ)
-  }
-
-  def apply(x:A):Option[(A,Set[A])] = {
-    val filtered = for((rep,set) <- this.quotient ; if set contains x) yield(rep,set)
-    filtered.size match {
-      case 0 => None
-      case 1 => Some(filtered.iterator.next)
-      case _ => error("you shouldn't be here")
-    }
-  }
-
-}
--- a/src/test/scala/QuotientSetTest.scala	Sun Oct 31 17:22:21 2010 -0400
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,12 +0,0 @@
-package w3c.sw
-
-import org.scalatest.FunSuite
-
-class QuotientSetTest extends FunSuite {
-
-  test("1") {
-    val q = QuotientSet()
-    
-  }
-
-}