2 * 2004 Matthew Fluet (mfluet@acm.org)
3 * Ported to MLton threads.
6 functor FunPriorityQueue(S: FUN_PRIORITY_QUEUE_ARG) :
7 FUN_PRIORITY_QUEUE where type Key.t = S.Key.t =
13 datatype 'a t = T of Key.t * 'a
14 fun key (T (k, _)) = k
15 fun value (T (_, v)) = v
18 datatype 'a t = T of 'a Elt.t list
21 fun filterPrefix (xs, p) =
25 then filterPrefix (ys, p)
27 fun filter (xs, p) = List.filter (not o p) xs
29 fun cleanPrefix (T xs, p) = T (filterPrefix (xs, p))
30 fun clean (T xs, p) = T (filter (xs, p))
36 | x::xs => SOME (x, T xs))
38 fun cleanAndDeque (q, p) =
44 | SOME (x, q) => (SOME x, q)
52 fun enque (T xs, k', v') =
54 val x' = Elt.T (k', v')
57 [] => List.revAppend(ys, [x'])
58 | (z as Elt.T (k, _))::zs =>
59 (case Key.compare (k, k') of
60 GREATER => List.revAppend(ys, x'::xs)
61 | _ => loop(zs, z::ys))
66 fun enqueAndClean (q, k, v, p) =
67 clean (enque (q, k, v), p)