home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / modu1096.zip / GPMsym / gensequencesupport.def < prev    next >
Text File  |  1996-08-29  |  3KB  |  64 lines

  1. (****************************************************************)
  2. (*                                                              *)
  3. (*         Gardens Point Modula-2 Library Definition            *)
  4. (*                                                              *)
  5. (*                                                              *)
  6. (*     (c) Copyright 1996 Faculty of Information Technology     *)
  7. (*              Queensland University of Technology             *)
  8. (*                                                              *)
  9. (*     Permission is granted to use, copy and change this       *)
  10. (*     program as long as the copyright message is left intact  *)
  11. (*                                                              *)
  12. (****************************************************************)
  13.  
  14. (*******************************************************************)
  15. (******** General support for sequences...no random access *********)
  16. (*******************************************************************)
  17.  
  18. (* !NONREC *) DEFINITION MODULE GenSequenceSupport; (* kjg nov '84 *)
  19.  
  20. FROM SYSTEM IMPORT ADDRESS;
  21.  
  22. TYPE ElemPtr;
  23. TYPE Sequence = RECORD
  24.                   first : ElemPtr; (* ptr to first element *)
  25.                   last  : ElemPtr  (* ptr to last element  *)
  26.                 END;
  27.  
  28. PROCEDURE InitSequence(VAR seq : Sequence);
  29.           (* sets all fields NIL *)
  30.  
  31. PROCEDURE LinkLeft (VAR seq : Sequence; Element : ADDRESS);
  32. PROCEDURE LinkRight(VAR seq : Sequence; Element : ADDRESS);
  33.  
  34. PROCEDURE InitCursor(seq : Sequence; VAR cursor : ElemPtr);
  35. (* postcondition: cursor is attached. GetNext will get first. *)
  36.  
  37. PROCEDURE GetFirst(       seq : Sequence;
  38.                    VAR cursor : ElemPtr;
  39.                    VAR result : ADDRESS );
  40. (* returns the first element. GetFirst on empty sequence rtns NIL *)
  41. (* postcondition: cursor is attached, next GetNext will fetch 2nd *)
  42.  
  43. PROCEDURE GetNext( VAR cursor : ElemPtr;
  44.                    VAR result : ADDRESS );
  45. (* precondition: cursor is already attached. Returns element and- *)
  46. (* "increments" cursor. Returns NIL if sequence is already ended. *)
  47.  
  48. PROCEDURE Ended(cursor : ElemPtr) : BOOLEAN;
  49. (* precondition: cursor is attached. Returns "cursor = NIL" *)
  50.  
  51. PROCEDURE NextIsLast(cursor : ElemPtr) : BOOLEAN;
  52. (* precondition: cursor is attached. Returns "cursor = seq.last" *)
  53.  
  54. PROCEDURE IsEmpty(seq : Sequence) : BOOLEAN;
  55. (* postcondition : returns "seq is the empty sequence" *)
  56.  
  57. PROCEDURE LengthOf(seq : Sequence) : CARDINAL;
  58.  
  59. PROCEDURE DisposeList(VAR seq : Sequence);
  60.       (* returns list but not the linked nodes,
  61.          also reinitializes the sequence header *)
  62.  
  63. END GenSequenceSupport.
  64.