Fifo
structure
signature FIFO
structure Fifo
: FIFO
The Fifo structure provides an applicative implementation of queues, in one of the greater abuses of notation.
As the implementation uses a pair of lists, the amortized cost for calling enqueue
, dequeue
or head
is constant time.
type 'a fifo
exception Dequeue
val empty : 'a fifo
val isEmpty : 'a fifo -> bool
val enqueue : ('a fifo * 'a) -> 'a fifo
val dequeue : 'a fifo -> ('a fifo * 'a)
val delete : ('a fifo * ('a -> bool)) -> 'a fifo
val head : 'a fifo -> 'a
val peek : 'a fifo -> 'a option
val length : 'a fifo -> int
val contents : 'a fifo -> 'a list
val app : ('a -> unit) -> 'a fifo -> unit
val map : ('a -> 'b) -> 'a fifo -> 'b fifo
val foldl : (('a * 'b) -> 'b) -> 'b -> 'a fifo -> 'b
val foldr : (('a * 'b) -> 'b) -> 'b -> 'a fifo -> 'b
type 'a fifo
exception Dequeue
empty
isEmpty fi
enqueue (fi, a)
dequeue fi
delete (fi, f)
head fi
peek fi
length fi
contents fi
app f fi
List.app f (contents fi)
map f fi
List.foldl (fn (v,q) => enqueue(q,v)) empty (List.map f (contents fi))
foldl f a fi
List.foldl f a (contents fi))
foldr f a fi
List.foldr f a (contents fi))
Queue
Last Modified May 14, 1998
Comments to John Reppy
Copyright © 1998 Bell Labs, Lucent Technologies