From c63e2720b089ced80a083102d3efca4222fc592d Mon Sep 17 00:00:00 2001 From: Francis Russell Date: Sat, 7 Apr 2012 20:16:24 +0100 Subject: [PATCH] Add priority queue wrapper. --- src/ofc/util/DirectedGraph.scala | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/ofc/util/DirectedGraph.scala b/src/ofc/util/DirectedGraph.scala index 3cc7626..4c2e1af 100644 --- a/src/ofc/util/DirectedGraph.scala +++ b/src/ofc/util/DirectedGraph.scala @@ -30,6 +30,19 @@ object DirectedGraph { } } + 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 val degrees = scala.collection.mutable.Map[Vertex, Int]() -- 2.47.3