]> git.unchartedbackwaters.co.uk Git - francis/ofc.git/commitdiff
Move queue implementations into new file.
authorFrancis Russell <francis@unchartedbackwaters.co.uk>
Sat, 7 Apr 2012 19:18:35 +0000 (20:18 +0100)
committerFrancis Russell <francis@unchartedbackwaters.co.uk>
Sat, 7 Apr 2012 19:18:35 +0000 (20:18 +0100)
src/ofc/util/DirectedGraph.scala
src/ofc/util/Queue.scala [new file with mode: 0644]

index 4c2e1afebf1c8cfd393a2986ebb9e8db9feefd68..56f814688cb199186b60b9045e1597a055bdbcc6 100644 (file)
@@ -2,46 +2,6 @@ package ofc.util
 import ofc.LogicError
 
 object DirectedGraph {
-  import scala.collection.generic.Growable
-
-  private trait Queue[A] extends Growable[A] {
-    def pop() : A
-    def nonEmpty : Boolean
-  }
-
-  private class StackQueue[A] extends Queue[A] {
-    private var stack = List[A]()
-
-    def nonEmpty = stack.nonEmpty
-
-    def +=(e: A) = {
-      stack = (e :: stack)
-      this
-    }
-
-    def pop() = {
-      val (head, tail) = (stack.head, stack.tail)
-      stack = tail
-      head
-    }
-
-    def clear() { 
-      stack = Nil 
-    }
-  }
-
-  private class PriorityQueue[A](ordering: Ordering[A]) extends Queue[A] {
-    val queue = new scala.collection.mutable.PriorityQueue[A]()(ordering)
-
-    def nonEmpty = queue.nonEmpty
-    def pop() = queue.dequeue()
-    def clear() = queue.clear()
-
-    def +=(e: A) = {
-      queue += e
-      this
-    }
-  }
 
   def topoSort(graph: DirectedGraph) : Seq[DirectedGraph#Vertex] = {
     type Vertex = DirectedGraph#Vertex
diff --git a/src/ofc/util/Queue.scala b/src/ofc/util/Queue.scala
new file mode 100644 (file)
index 0000000..fea4559
--- /dev/null
@@ -0,0 +1,42 @@
+package ofc.util
+import scala.collection.generic.Growable
+
+private trait Queue[A] extends Growable[A] {
+  def pop() : A
+  def nonEmpty : Boolean
+}
+
+private class StackQueue[A] extends Queue[A] {
+  private var stack = List[A]()
+
+  def nonEmpty = stack.nonEmpty
+
+  def +=(e: A) = {
+    stack = (e :: stack)
+    this
+  }
+
+  def pop() = {
+    val (head, tail) = (stack.head, stack.tail)
+    stack = tail
+    head
+  }
+
+  def clear() { 
+    stack = Nil 
+  }
+}
+
+private class PriorityQueue[A](ordering: Ordering[A]) extends Queue[A] {
+  val queue = new scala.collection.mutable.PriorityQueue[A]()(ordering)
+
+  def nonEmpty = queue.nonEmpty
+  def pop() = queue.dequeue()
+  def clear() = queue.clear()
+
+  def +=(e: A) = {
+    queue += e
+    this
+  }
+}
+