TABLE.DEF 3.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. (* ========================================== *)
  2. (* (c) 1990-1992 Clarion Software Corporation *)
  3. (* ========================================== *)
  4. DEFINITION MODULE Table;
  5. (*
  6. This module implements classes that allow the creation and maintenance
  7. of homogeneous tables of ordered objects. The internal structure of the
  8. table is an AVL Balanced Tree. The algorithms are based on an example
  9. given in Niklaus Wirth's "Algorithms + Data Structures = Programs". That
  10. book also gives a detailed description of AVL Balanced Trees.
  11. *)
  12. TYPE
  13. BalanceFlag = SHORTINT [-1..1];
  14. ElementPtr = POINTER TO Element;
  15. CLASS Element;
  16. Right : ElementPtr; (* Pointer to right sub-tree *)
  17. Left : ElementPtr; (* Pointer to left sub-tree *)
  18. Bal : BalanceFlag; (* Tree balance flag *)
  19. VIRTUAL PROCEDURE Compare( p : ElementPtr ) : INTEGER;
  20. (*
  21. Must be implemented by the client. This
  22. procedure should return one of the
  23. following integer values:
  24. <0 if 'THIS' is less than 'p'
  25. 0 if 'THIS' is equal to 'p'
  26. >0 if 'THIS' is greater than 'p'
  27. *)
  28. END Element ;
  29. TYPE
  30. Action = PROCEDURE ( ElementPtr );
  31. (* This procedure type is used by 'Apply' *)
  32. CLASS TABLE;
  33. Root : ElementPtr; (* The root of this tree *)
  34. PROCEDURE Insert( VAR x : Element );
  35. (* Insert the element 'x' into this table *)
  36. PROCEDURE Find( VAR p : Element ) : BOOLEAN;
  37. (* Search table for a element matching 'p'.
  38. Returns 'TRUE' and sets all fields of 'p' if
  39. found; otherwise returns 'FALSE'
  40. *)
  41. PROCEDURE Delete( VAR x : Element );
  42. (* Delete the element matching 'p' from table *)
  43. PROCEDURE Apply( p : Action );
  44. (* Apply procedure 'p' to all elements in order *)
  45. PROCEDURE Init;
  46. (* Initialize the table *)
  47. PROCEDURE Eq( t2 : TABLE ) : INTEGER;
  48. (* Compare 'THIS' with 't2'. The return values
  49. are:
  50. <0 'THIS' is less than 't2'
  51. 0 'THIS' is equal to 't2'
  52. >0 'THIS' is greater than 't2'
  53. ** RESTRICTION : Table must not generate a
  54. tree greater than 32 levels deep (around
  55. 2^32 elements
  56. *)
  57. PROCEDURE SubSet( t2 : TABLE ) : BOOLEAN;
  58. (* Are the elements in this table a subset of
  59. the elememts in table 't2'? *)
  60. PROCEDURE Copy() : TABLE;
  61. (* Make a copy this table *)
  62. PROCEDURE Incl( t2 : TABLE );
  63. (* Include elements from table 't2' in this
  64. table *)
  65. PROCEDURE Excl( t2 : TABLE );
  66. (* Exclude elements from table 't2' from this
  67. table *)
  68. PROCEDURE Empty() : BOOLEAN;
  69. (* Is this table empty? *)
  70. PROCEDURE Dispose;
  71. (* Dispose of all elements of this table *)
  72. END TABLE ;
  73. END Table.