home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / modula2 / library / queuem2 / queueadt.def < prev    next >
Text File  |  1989-08-30  |  6KB  |  151 lines

  1. (* source: h:\modula\defs\QueueADT.DEF    v1.0a             revised: 88.07.22
  2.    author: G.Greene, AGCS D/429 (NS/TS), 312/681-7783       created: 88.07.22
  3.  
  4.    function:
  5.     This is the interface for a package which exports an Abstract Data Type
  6.     for queues.
  7.  
  8.    history:
  9.     88.07.22  1.0a  initial release.
  10. *)
  11.  
  12.  
  13. DEFINITION MODULE  QueueADT;
  14.  
  15.  
  16. FROM  SYSTEM  IMPORT  BYTE;
  17.  
  18.  
  19. TYPE
  20.   Queues;
  21.  
  22.  
  23.  
  24. (*  Create a new (empty) queue specified by the parameter.
  25.  
  26. **  NB!!!  This procedure MUST be invoked for a queue before any other
  27.     procedure in this module can be used on that queue.  The result of
  28.     failing to do so is likely to be disasterous.  In addition, this
  29.     procedure should not be invoked with an existing queue:  the storage
  30.     associated with that queue would be lost.  To empty an existing queue,
  31.     use EmptyTheQueue;  to deallocate ("destroy") an existing queue, use
  32.     DestroyQueue.
  33. *)
  34.  
  35.   PROCEDURE  CreateQueue (
  36.             (*out*)  VAR  queue: Queues );
  37.  
  38.  
  39.  
  40. (*  Empty the queue specified by the parameter of its contents.  If the
  41.     queue has been destroyed, this procedure will do nothing.
  42. *)
  43.  
  44.   PROCEDURE  EmptyTheQueue (
  45.            (*in/out*)  VAR  queue: Queues );
  46.  
  47.  
  48.  
  49. (*  Destroy the queue specified by the parameter, deallocating all the storage
  50.     associated with it.  If invoked for a previously destroyed queue, this
  51.     procedure will do nothing.  A queue destroyed by this procedure will be
  52.     ignored by most of the other procedures.  The specific action each will
  53.     take is indicated in its description.  One exception:  CreateQueue will
  54.     reinstate a queue which has been destroyed.
  55. *)
  56.  
  57.   PROCEDURE  DestroyQueue (
  58.           (*in/out*)  VAR  queue: Queues );
  59.  
  60. (*                                                                         [2]
  61.  source: h:\modula\defs\QueueADT.DEF    v1.0a             revised: 88.07.22 *)
  62.  
  63.  
  64. (*  Return TRUE if the queue specified by the parameter is currently empty,
  65.     or if the queue has been destroyed.  Return FALSE only if the queue
  66.     exists and has at least one entry.
  67. *)
  68.  
  69.   PROCEDURE  isEmpty (
  70.               (*in*)  queue: Queues ):  BOOLEAN;
  71.  
  72.  
  73.  
  74. (*  Return the number of elements in the queue specified by the parameter.
  75.     This procedure will return zero for an empty queue, or for a queue which
  76.     has been destroyed.
  77. *)
  78.  
  79.   PROCEDURE  QueueSize (
  80.                 (*in*)  queue:  Queues ):  CARDINAL;
  81.  
  82. (*                                                                         [3]
  83.  source: h:\modula\defs\QueueADT.DEF    v1.0a             revised: 88.07.22 *)
  84.  
  85.  
  86. (*  Enqueue the data specified in the first parameter at the back of the
  87.     queue specified by the second parameter.  No action will be taken for a
  88.     destroyed queue.
  89. *)
  90.  
  91.   PROCEDURE   FIFOEnqueue (
  92.                    (*in*)  data:   ARRAY  OF BYTE;
  93.                    (*in*)  queue:  Queues );
  94.  
  95.  
  96.  
  97. (*  Enqueue the data specified in the first parameter into the priority queue
  98.     specified by the second parameter.  The entry's priority is taken to be
  99.     the first word of the data, interpreted as CARDINAL.  Zero is the highest
  100.     priority;  lower priorities have higher CARDINAL values.  Thus the queue
  101.     yields entries in increasing value of the priority.  This ordering was
  102.     chosen to accommodate time-based queues.  Entries with the same priority
  103.     are enqueued in order of receipt (FIFO).
  104. *)
  105.  
  106.   PROCEDURE   PriorityEnqueue (
  107.                        (*in*)  data:   ARRAY  OF BYTE;
  108.                        (*in*)  queue:  Queues );
  109.  
  110.  
  111.  
  112. (*  Dequeue, to the data area specified by the first parameter, the front
  113.     element of the queue specified by the second parameter.   If the queue
  114.     is empty (or has been destroyed), the third parameter will be set FALSE;
  115.     it is also set FALSE if the size of the front data element in the queue
  116.     does not match the size of the data area to receive it.  Otherwise, the
  117.     third parameter is set TRUE, indicating that the first parameter has
  118.     valid data.  If the third parameter is FALSE, the queue has not been
  119.     changed.
  120. *)
  121.  
  122.   PROCEDURE  Dequeue (
  123.          (*out*) VAR  data:    ARRAY  OF BYTE;
  124.          (*in*)       queue:   Queues;
  125.          (*out*) VAR  DataOK:  BOOLEAN );
  126.  
  127. (*                                                                         [4]
  128.  source: h:\modula\defs\QueueADT.DEF    v1.0a             revised: 88.07.22 *)
  129.  
  130.  
  131. (*  Copy, to the data area specified by the first parameter, an element of the
  132.     queue specified by the second parameter.   The element to copy is the one
  133.     specified by the third parameter (the front element is numbered zero).
  134.     If the queue is empty (or has been destroyed), the fourth parameter will
  135.     be set FALSE;  it is also set FALSE if the size of the front data element
  136.     in the queue does not match the size of the data area to receive it, or
  137.     if there is no such element.  Otherwise, the fourth parameter is set TRUE,
  138.     indicating that the first parameter has valid data.  No change is made to
  139.     to the queue in any case.  This procedure can be used as part of code to
  140.     dump the contents of a queue--for example, LOOPing using the value of the
  141.     fourth parameter as an EXIT condition.
  142. *)
  143.  
  144.   PROCEDURE  ReadElement (
  145.              (*out*) VAR  data:    ARRAY  OF BYTE;
  146.              (*in*)       queue:   Queues;
  147.              (*in*)       element: CARDINAL;
  148.              (*out*) VAR  DataOK:  BOOLEAN );
  149.  
  150. END  QueueADT.
  151.