forgotten files
authorAlexandre Bertails <bertails@w3.org>
Fri, 11 Dec 2009 20:13:27 -0500
changeset 22 b7ea961d348a
parent 21 30db5ead67b3
child 23 86ed34331caa
forgotten files
src/main/scala/QuotientSet.scala
src/test/scala/QuotientSetTest.scala
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/main/scala/QuotientSet.scala	Fri Dec 11 20:13:27 2009 -0500
@@ -0,0 +1,28 @@
+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")
+    }
+  }
+
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/test/scala/QuotientSetTest.scala	Fri Dec 11 20:13:27 2009 -0500
@@ -0,0 +1,12 @@
+package w3c.sw
+
+import org.scalatest.FunSuite
+
+class QuotientSetTest extends FunSuite {
+
+  test("1") {
+    val q = QuotientSet()
+    
+  }
+
+}