The SML/NJ Library Reference Manual


The QUEUE signature

The Queue structure provides imperative first-in/first-out queues.


Synopsis

signature QUEUE
structure Queue : QUEUE

Interface

type 'a queue
exception Dequeue
val mkQueue : unit -> 'a queue
val isEmpty : 'a queue -> bool
val enqueue : ('a queue * 'a) -> unit
val dequeue : 'a queue -> 'a
val delete : ('a queue * ('a -> bool)) -> unit
val head : 'a queue -> 'a
val peek : 'a queue -> 'a option
val length : 'a queue -> int
val contents : 'a queue -> 'a list
val app : ('a -> unit) -> 'a queue -> unit
val map : ('a -> 'b) -> 'a queue -> 'b queue
val foldl : (('a * 'b) -> 'b) -> 'b -> 'a queue -> 'b
val foldr : (('a * 'b) -> 'b) -> 'b -> 'a queue -> 'b

Description

type 'a queue
Imperative first-in/first-out queues.

exception Dequeue
This exception is raised when attempting to remove an element from and empty queue. It is the same exception as Dequeue.

mkQueue ()
creates a new, empty, queue.

isEmpty q
returns true, if the queue q is empty.

enqueue (q, a)
adds the element a to the end of the queue.

dequeue q
removes and returns the first element of the queue q. If q is empty, then the exception Dequeue is raised.

delete (q, pred)
deletes the first element in q that satisfies the predicate pred.

head q
returns the first element of the queue q (without removing it). If q is empty, then the exception Dequeue is raised.

peek q
returns the first element of the queue q, or NONE if q is empty.

length q
returns the number of elements in the queue q.

contents q
returns the list of elements in the queue q in the order that they were inserted.

app f q
explain the use and semantics of app HERE. This is equivalent to the expression:
     List.app f (contents q)    


map f q
explain the use and semantics of map HERE. This is equivalent to the expression:
     List.map f (contents q)    


foldl f init q
explain the use and semantics of foldl HERE. This is equivalent to the expression:
     List.foldl f init (contents q)    


foldr f init q
explain the use and semantics of foldr HERE. This is equivalent to the expression:
     List.foldr f init (contents q)    



See Also

Fifo

[ INDEX | TOP | Parent | Root ]

Last Modified May 29, 1996
Copyright © 1996 AT&T Research