1 (* Copyright (C) 1999-2005 Henry Cejtin, Matthew Fluet, Suresh
2 * Jagannathan, and Stephen Weeks.
4 * MLton is released under a BSD-style license.
5 * See the file MLton-LICENSE for details.
7 (*-------------------------------------------------------------------*)
9 (*-------------------------------------------------------------------*)
11 functor SinglyLinkedQueue(): UNBOUNDED_EPHEMERAL_QUEUE =
15 structure E = SimpleSinglyLinkedElement
17 datatype 'a t = T of {head: 'a E.t P.t,
20 fun empty() = T{head = P.null(), tail = P.null()}
22 fun isEmpty(T{head, ...}) = P.isNull head
24 fun enque(q as T{head, tail}, x) =
26 in if isEmpty q then P.:=(head, e) else E.setNext(P.! tail, e) ;
30 fun deque(T{head, tail}) =
31 let val (v, p) = E.destruct(P.! head)
33 if P.isNull p then P.clear tail else () ;
39 structure SinglyLinkedQueue = SinglyLinkedQueue()