|##########|
|#MAGIC   #|CLABLLDM
|#PROJECT #|"ImportHelp"
|#PATHS   #|"StdProject"
|#FLAGS   #|xx---x--x-----x-----------------
|#USERSW  #|--------------------------------
|#USERMASK#|--------------------------------
|#SWITCHES#|xx---xxxxx------
|##########|
DEFINITION MODULE Sets;

IMPORT Resources;

  DEFINITION MODULE Sets(ElemPtr : ANYPTR;
                         SetPtr  : POINTER TO Set);

    TYPE
      SetElemPtr = HIDDEN;

    DEFINITION MODULE SetRes = Resources.ResHandles(SetPtr);

    TYPE
      Set        = RECORD OF SetRes.ResHandle;
                     firstElem : SetElemPtr;
                   END;

      ApplyProc  = PROCEDURE(e : ElemPtr);
      ApplySet   = PROCEDURE(s : SetPtr);
      CheckProc  = PROCEDURE(e : ElemPtr):BOOLEAN;
      Destructor = PROCEDURE(e : ElemPtr);

    PROCEDURE Init(s : SetPtr);


    PROCEDURE Include(s : SetPtr;e : ElemPtr);

    PROCEDURE Exclude(s : SetPtr;e : ElemPtr);

    PROCEDURE Exclude_All(s : SetPtr);

    PROCEDURE Exclude_IF(s : SetPtr;check : CheckProc);


    PROCEDURE IsIn(s : SetPtr;e : ElemPtr):BOOLEAN;


    PROCEDURE Unite(dest,source : SetPtr);

    PROCEDURE Intersect(dest,source : SetPtr);

    PROCEDURE Duplicate(dest,source : SetPtr);


    PROCEDURE Apply(s : SetPtr;apply : ApplyProc);

    PROCEDURE ApplySets(e : ElemPtr;apply : ApplySet);

    PROCEDURE GarbageCollect;

  END Sets;

  DEFINITION MODULE RefSets(ElemPtr : POINTER TO Elem;
                            SetPtr  : POINTER TO Set);

    TYPE
      SetElemPtr = HIDDEN;

    DEFINITION MODULE SetRes = Resources.ResHandles(SetPtr);

    TYPE
      Elem       = RECORD
                     refCount  : INTEGER;
                   END;

      Destructor = PROCEDURE(e : ElemPtr);

      Set        = RECORD OF SetRes.ResHandle;
                     firstElem : SetElemPtr;
                     destruct  : Destructor;
                   END;

      ApplyProc  = PROCEDURE(e : ElemPtr);
      ApplySet   = PROCEDURE(s : SetPtr);
      CheckProc  = PROCEDURE(e : ElemPtr):BOOLEAN;

    PROCEDURE Init(s : SetPtr;des : Destructor);

    PROCEDURE InitElem(e : ElemPtr);


    PROCEDURE Include(s : SetPtr;e : ElemPtr);

    PROCEDURE Exclude(s : SetPtr;e : ElemPtr);

    PROCEDURE Exclude_All(s : SetPtr);

    PROCEDURE Exclude_IF(s : SetPtr;check : CheckProc);


    PROCEDURE IsIn(s : SetPtr;e : ElemPtr):BOOLEAN;


    PROCEDURE Unite(dest,source : SetPtr);

    PROCEDURE Intersect(dest,source : SetPtr);

    PROCEDURE Duplicate(dest,source : SetPtr);


    PROCEDURE Apply(s : SetPtr;apply : ApplyProc);

    PROCEDURE ApplySets(e : ElemPtr;apply : ApplySet);


    PROCEDURE GarbageCollect;

  END RefSets;

  DEFINITION MODULE Bags(ElemPtr : ANYPTR;
                         BagPtr  : POINTER TO Bag);

    TYPE
      BagElemPtr = HIDDEN;

    DEFINITION MODULE BagRes = Resources.ResHandles(BagPtr);

    TYPE
      Bag        = RECORD OF BagRes.ResHandle;
                     firstElem : BagElemPtr;
                   END;

      ApplyProc  = PROCEDURE(e : ElemPtr);
      ApplyBag   = PROCEDURE(s : BagPtr);
      CheckProc  = PROCEDURE(e : ElemPtr):BOOLEAN;
      Destructor = PROCEDURE(e : ElemPtr);

    PROCEDURE Init(s : BagPtr);


    PROCEDURE Include(s : BagPtr;e : ElemPtr);

    PROCEDURE Exclude(s : BagPtr;e : ElemPtr);

    PROCEDURE Exclude_All(s : BagPtr);

    PROCEDURE Exclude_IF(s : BagPtr;check : CheckProc);


    PROCEDURE IsIn(s : BagPtr;e : ElemPtr):BOOLEAN;


    PROCEDURE Unite(dest,source : BagPtr);

    PROCEDURE Intersect(dest,source : BagPtr);

    PROCEDURE Duplicate(dest,source : BagPtr);


    PROCEDURE Apply(s : BagPtr;apply : ApplyProc);

    PROCEDURE ApplyBags(e : ElemPtr;apply : ApplyBag);


    PROCEDURE GarbageCollect;

  END Bags;

  DEFINITION MODULE RefBags(ElemPtr : POINTER TO Elem;
                            BagPtr  : POINTER TO Bag);

    TYPE
      BagElemPtr = HIDDEN;

    DEFINITION MODULE BagRes = Resources.ResHandles(BagPtr);

    TYPE
      Elem       = RECORD
                     refCount  : INTEGER;
                   END;

      Destructor = PROCEDURE(e : ElemPtr);

      Bag        = RECORD OF BagRes.ResHandle;
                     firstElem : BagElemPtr;
                     destruct  : Destructor;
                   END;

      ApplyProc  = PROCEDURE(e : ElemPtr);
      ApplyBag   = PROCEDURE(s : BagPtr);
      CheckProc  = PROCEDURE(e : ElemPtr):BOOLEAN;

    PROCEDURE Init(s : BagPtr;des : Destructor);

    PROCEDURE InitElem(e : ElemPtr);


    PROCEDURE Include(s : BagPtr;e : ElemPtr);

    PROCEDURE Exclude(s : BagPtr;e : ElemPtr);

    PROCEDURE Exclude_All(s : BagPtr);

    PROCEDURE Exclude_IF(s : BagPtr;check : CheckProc);


    PROCEDURE IsIn(s : BagPtr;e : ElemPtr):BOOLEAN;

    PROCEDURE Unite(dest,source : BagPtr);

    PROCEDURE Intersect(dest,source : BagPtr);

    PROCEDURE Duplicate(dest,source : BagPtr);


    PROCEDURE Apply(s : BagPtr;apply : ApplyProc);

    PROCEDURE ApplyBags(e : ElemPtr;apply : ApplyBag);


    PROCEDURE GarbageCollect;

  END RefBags;

END Sets.




