|##########|
|#MAGIC   #|CLABLNLH
|#PROJECT #|"ImportHelp"
|#PATHS   #|"StdProject"
|#FLAGS   #|xx-x-x--x---xxx--x--------------
|#USERSW  #|--------------------------------
|#USERMASK#|--------------------------------
|#SWITCHES#|x----xxxxx------
|##########|
DEFINITION MODULE AVLTrees;

FROM System IMPORT Equation;

  DEFINITION MODULE AVLTrees(AVLNodePtr : POINTER TO AVLNode);

    TYPE
      AVLNode    = RECORD
                     left,
                     right,
                     parent : AVLNodePtr;
                     a_fact : INTEGER;
                   END;

      Comparison = PROCEDURE(a,b : AVLNodePtr):Equation;

      AVLTree    = RECORD
                     root    : AVLNodePtr;
                     compare : Comparison;
                   END;

    EXCEPTION
      AllreadyExists : "Allready exists";
      NotFound       : "Not found";
      TreeEmpty      : "Tree is empty";

    PROCEDURE Init(VAR t : AVLTree;compare : Comparison);

    PROCEDURE Insert(VAR t : AVLTree;data : AVLNodePtr);

    PROCEDURE Search(REF t : AVLTree;data : AVLNodePtr):AVLNodePtr;

    PROCEDURE Delete(VAR t : AVLTree;VAR data : AVLNodePtr);

    PROCEDURE Remove(VAR t : AVLTree;data : AVLNodePtr);

    PROCEDURE Next(REF t : AVLTree;data : AVLNodePtr):AVLNodePtr;

    PROCEDURE Prev(REF t : AVLTree;data : AVLNodePtr):AVLNodePtr;

    PROCEDURE First(REF t : AVLTree):AVLNodePtr;

    PROCEDURE Last(REF t : AVLTree):AVLNodePtr;

  END AVLTrees;

  DEFINITION MODULE AVLCursorTrees(type : ANYPTR);

    TYPE
      CNodePtr   = POINTER TO CNode;

    DEFINITION MODULE CTree = AVLTrees(CNodePtr);

    TYPE
      CNode      = RECORD OF CTree.AVLNode
                     data : type;
                   END;

      Comparison = PROCEDURE(a,b : type):Equation;
      Destructor = PROCEDURE(VAR a : type);

      AVLTree    = RECORD OF CTree.AVLTree
                     cursor   : CNodePtr;
                     greater2 : Comparison;
                   END;

    FROM CTree IMPORT AllreadyExists,NotFound;

    PROCEDURE Init(VAR t : AVLTree;compare : Comparison);

    PROCEDURE Insert(VAR t : AVLTree;data : type);

    PROCEDURE Search(VAR t : AVLTree;data : type);

    PROCEDURE Get(VAR t : AVLTree):type;

    PROCEDURE Delete(VAR t : AVLTree);

    PROCEDURE Remove(VAR t : AVLTree);

    PROCEDURE Destruct(VAR t : AVLTree;destructor : Destructor);

    PROCEDURE Delete_All(VAR t : AVLTree);

    PROCEDURE Destruct_All(VAR t : AVLTree;destructor : Destructor);

    PROCEDURE Next(VAR t : AVLTree);

    PROCEDURE Prev(VAR t : AVLTree);

    PROCEDURE First(VAR t : AVLTree);

    PROCEDURE Last(VAR t : AVLTree);

  END AVLCursorTrees;

END AVLTrees.

