home *** CD-ROM | disk | FTP | other *** search
/ CP/M / CPM_CDROM.iso / simtel / sigm / vols000 / vol072 / circque.pas < prev    next >
Pascal/Delphi Source File  |  1984-04-29  |  1KB  |  58 lines

  1. { Donated by Warren Smith, Feb 1982 }
  2.  
  3. Module Circular_Queue ;
  4.  
  5. { This set of routines is intended only as a guide for handling    }
  6. { circular buffers or queues.  Normally, I/O buffering would    }
  7. { be handled through this type of data structure and operations.}
  8.  
  9. Type
  10.     Q_range          = Min_Q..Max_Q ;
  11.     Q_Type          = byte ;
  12.     Queue          = record
  13.             Q_not_empty,
  14.             Q_not_full    : boolean ;
  15.             Q_head,
  16.             Q_tail        : Q_Range ;
  17.             Q        : array [Q_Range] of Q_Type ;
  18.             end ;
  19.  
  20. Function Put_Q (Var Cur_Q : Queue ; Var Cur_Entry : Q_Type) : boolean ;
  21.  
  22.   begin { Put_Q }
  23.   With Cur_Q do
  24.     If Q_not_full then
  25.       begin
  26.       Q[Q_head] := Cur_Entry ;
  27.       If Q_head = Max_Q then
  28.         Q_head := Min_Q
  29.       else
  30.         Q_head := Q_head + 1 ;
  31.       Q_not_full := Q_head <> Q_tail ;
  32.       Q_not_empty := TRUE ;
  33.       Put_Q := TRUE
  34.       end
  35.     else
  36.       Put_Q := FALSE
  37.   end ; { Put_Q }
  38.  
  39. Function Get_Q (Var Cur_Q : Queue ; Var Cur_Entry : Q_Type) : boolean ;
  40.  
  41.   begin { Get_Q }
  42.   With Cur_Q do
  43.     If Q_not_empty then
  44.       begin
  45.       Cur_Entry := Q[Q_tail] ;
  46.       If Q_tail = Max_Q then
  47.         Q_tail := Min_Q
  48.       else
  49.         Q_tail := Q_tail + 1 ;
  50.       Q_not_full := TRUE ;
  51.       Q_not_empty := Q_head <> Q_tail ;
  52.       Get_Q := TRUE
  53.       end
  54.     else
  55.       Get_Q := FALSE
  56.   end ; { Get_Q }
  57.  
  58. ModEnd.