Path: utzoo!attcan!uunet!zephyr.ens.tek.com!tektronix!nosun!qiclab!m2xenix!puddle!f101.n273.z1.fidonet.org!Peter.M..Perchansky From: Peter.M..Perchansky@f101.n273.z1.fidonet.org (Peter M. Perchansky) Newsgroups: comp.lang.modula2 Subject: Generic Lists in Modula-2 Message-ID: <462.26C2767E@puddle.fidonet.org> Date: 9 Aug 90 03:42:22 GMT Sender: ufgate@puddle.fidonet.org (newsout1.26) Organization: FidoNet node 1:273/101 - Schizophrenia, Fleetwood PA Lines: 108 DEFINITION MODULE PMPDeque; (*---------- Procedures from JPI's TopSpeed Modula II -------------*) FROM SYSTEM IMPORT BYTE; (*-----------------------------------------------------------------*) TYPE Deques; (* opaque type defined in implementation module *) DequesStatus = (empty, full, mismatchedSize, noSuchNode, none); ErrorHandler = PROCEDURE (DequesStatus); (* DequesStatus code explainations: *) (* empty: An operation tried to remove/show data from *) (* an empty deque. *) (* full: An operation tried to add data to a full *) (* deque; no more memory available. *) (* mismatchedSize: An operation tried to remove/show data to a *) (* variable whose size (in bytes) did not match *) (* the size of the variable stored in the deque. *) (* noSuchNode: An operation tried to process a node that does *) (* not exist in the deque. *) (* none: No error occured during processing. *) PROCEDURE CreateDeque (VAR deque: Deques); (* Creates the deque by making it NIL *) (* This procedure must be called prior to performing operations on *) (* the deque. *) PROCEDURE Empty (deque: Deques): BOOLEAN; (* Return TRUE if the deque is NIL (empty). *) PROCEDURE DestroyDeque (VAR deque: Deques); (* Destroys the deque by deallocating deque nodes and contents *) (* DestroyDeque should be called when the deque is no longer needed *) (* in memory. *) PROCEDURE Full (size: CARDINAL): BOOLEAN; (* Return TRUE if there is no Available memory for another deque node *) PROCEDURE DequeLength (deque: Deques): CARDINAL; (* Returns the number of nodes in the deque *) PROCEDURE DequePos (data: ARRAY OF BYTE; deque: Deques): CARDINAL; (* Returns the number of the node containing the data (if found). *) (* Returns 0 if not found. The front of the deque is treated as node *) (* number one. *) PROCEDURE InDeque (data: ARRAY OF BYTE; deque: Deques): BOOLEAN; (* Returns TRUE if data is found in deque. *) PROCEDURE LastError (): DequesStatus; (* Returns the status code containing the last error (if any) from a *) (* previous operation. *) PROCEDURE InstallErrorHandler (handler: ErrorHandler); (* Installs client-module error procedure to handle errors that occur *) (* during deque operations. Until an error-handler is installed, all *) (* errors will be ignored. *) PROCEDURE Enqueue (data: ARRAY OF BYTE; VAR deque: Deques); (* Place data in node at the back of the deque. status is set to *) (* full or none. *) PROCEDURE Push (data: ARRAY OF BYTE; VAR deque: Deques); (* Place data in node at the back of the deque. status is set to *) (* full or none. *) PROCEDURE Dequeue (VAR data: ARRAY OF BYTE; VAR deque: Deques); (* Place contents from node at the front of the deque into data. *) (* Remove the front node of the deque. status is set to empty, *) (* mismatchedSize, or none. *) PROCEDURE Pop (VAR data: ARRAY OF BYTE; VAR deque: Deques); (* Place contents from node at the back of the deque into data. *) (* Remove the back node of the deque. status is set to empty, *) (* mismatchedSize, or none. *) PROCEDURE Update (data: ARRAY OF BYTE; nthItem: CARDINAL; VAR deque: Deques); (* Update contents of nth node of the deque from data. status is set *) (* to empty, mismatchedSize, noSuchNode, or none. *) PROCEDURE Serve (VAR data: ARRAY OF BYTE; nthItem: CARDINAL; VAR deque: Deques); (* Place contents from nth node of the deque into data. Remove the *) (* nth node of the deque. status is set to empty, mismatchedSize, *) (* noSuchNode, or none. *) PROCEDURE Front (VAR data: ARRAY OF BYTE; deque: Deques); (* Place contents from node at the front of the deque into data. *) (* status is set to empty, mismatchedSize, or none. *) PROCEDURE Back (VAR data: ARRAY OF BYTE; deque: Deques); (* Place contents from node at the back of the deque into data. *) (* status is set to empty, mismatchedSize, or none. *) PROCEDURE Top (VAR data: ARRAY OF BYTE; deque: Deques); (* Place contents from node at the back (top) of the deque into data. *) (* status is set to empty, mismatchedSize, or none. *) PROCEDURE Retrieve (VAR data: ARRAY OF BYTE; nthItem: CARDINAL; deque: Deques); (* Place contents from nth node of the deque into data. status is *) (* set to empty, mismatchedSize, noSuchNode, or none. *) END PMPDeque. -- uucp: uunet!m2xenix!puddle!273!101!Peter.M..Perchansky Internet: Peter.M..Perchansky@f101.n273.z1.fidonet.org