PreviousUpNext

15.4.948  src/lib/src/queue.pkg

## queue.pkg

# Compiled by:
#     src/lib/std/standard.lib

# Imperative fifos

# See also:
#     src/lib/src/fifo.pkg


package queue : Queue  {                # Queue is from   src/lib/src/queue.api

    Queue(X) = Ref( fifo::Fifo(X) );

    exception DEQUEUE = fifo::DEQUEUE;

    fun make_queue () = REF fifo::empty;

    fun clear q = (q := fifo::empty);

    fun enqueue (q, x) = q := (fifo::enqueue (*q, x));

    fun dequeue q = { 
          my (newq, x) = fifo::dequeue *q; 
          
            q := newq;
            x;
          };
  
    fun delete (q, prior) = (q := fifo::delete (*q, prior));
    fun head q = fifo::head *q;
    fun peek q = fifo::peek *q;
    fun is_empty q = fifo::is_empty *q;
    fun length q = fifo::length *q;
    fun contents q = fifo::contents *q;
    fun apply f q = fifo::apply f *q;
    fun map f q = REF (fifo::map f *q);
    fun fold_left  f b q = fifo::fold_left  f b *q;
    fun fold_right f b q = fifo::fold_right f b *q;

};


## COPYRIGHT (c) 1993 by AT&T Bell Laboratories.  See COPYRIGHT file for details.
## Subsequent changes by Jeff Prothero Copyright (c) 2010-2012,
## released under Gnu Public Licence version 3.


Comments and suggestions to: bugs@mythryl.org

PreviousUpNext