home *** CD-ROM | disk | FTP | other *** search
- Unit L_Heaps;
- {$O+,S-}
-
- { While its VERY ineffecient to use the L_Heap for Integers,
- I will do so here anyway since this is only an example Unit
- intended to demonstrate the declaration of application-level
- versions of the L_Heap. }
-
- { NOTE: L_Heaps are "Indexed" from 1 to CurrentLength }
- { CurrentLength = 0 equals Empty List }
-
- INTERFACE
-
- Uses LGenHeap,DoubLink,NodeSort;
-
- {
- All L_Heaps additionally inherit the following Methods:
-
- (* GenList Methods *)
- Procedure Create;
- Procedure Destroy;
- Procedure ReWind; (* "GoTo" Element 1 instantly *)
- (* used to speed up listhead *)
- (* accesses. *)
-
- Function CurrentLength; (* LongInt *)
- Function ElemSize; (* Word *)
-
- Function Node_N (N : LongInt) : D_Ptr;
-
- (* Note on Node_N: It is used only in order
- to simplify the Swap operation, and I can
- think of no other useful application, but
- maybe you can. The D_Ptr is defined in
- Unit DoubLink. *)
-
- (* L_Heap Methods *)
- Procedure Swap (I,J : LongInt);
- Procedure SiftDown (I,J : LongInt);
- Procedure BuidHeap;
- Procedure ChangeSort (NewSort : NodeSortFunc);
- Procedure Sort;
- Procedure HeapSort;
- }
-
- Type
- L_IntHeap = Object (L_Heap)
-
- { Re-Defining these methods re-introduces Types and }
- { most importantly, Type-Checking to the Generic }
- { (typeless) L_Heap, as well as making the calls more }
- { "natural" for the actual applications Heaps. }
-
- { Follow this pattern when defining your descendant Heaps }
-
-
- Procedure Init;
-
- (* Linked-List Methods *)
-
- Procedure Append (I : Integer);
-
- Procedure Insert (I : Integer; After : LongInt);
-
- Procedure SiftUp (I : Integer);
-
- (* Array-Like Methods *)
-
- Procedure Accept (I : Integer; Index : LongInt);
-
- Function Retrieve (Index : LongInt) : Integer;
-
- (* General Methods *)
-
- Procedure Copy (From : L_IntHeap);
-
- End;
-
-
- IMPLEMENTATION
-
- Procedure L_IntHeap.Init;
- Begin
- L_Heap.Init (IntGreater,SizeOf(Integer))
- End;
-
- Procedure L_IntHeap.Append (I : Integer);
- Var
- J : Integer;
- Begin
- J := I;
- L_Heap.Append (J,SizeOf(Integer))
- End;
-
- Procedure L_IntHeap.Insert (I : Integer; After : LongInt);
- Var
- J : Integer;
- Begin
- J := I;
- InsertAfter_N (J,After,SizeOf(Integer))
- End;
-
- Procedure L_IntHeap.SiftUp (I : Integer);
- Var
- J : Integer;
- Begin
- J := I;
- L_Heap.SiftUp (J,SizeOf(Integer))
- End;
-
- Procedure L_IntHeap.Accept (I : Integer; Index : LongInt);
- Var
- J : Integer;
- Begin
- J := I;
- ReSetElement_N (J,Index,SizeOf(Integer))
- End;
-
- Function L_IntHeap.Retrieve (Index : LongInt) : Integer;
- Var
- J : Integer;
- Begin
- GetElement_N (J,Index,SizeOf(Integer));
- Retrieve := J
- End;
-
- Procedure L_IntHeap.Copy (From : L_IntHeap);
- Begin
- L_Heap.Copy (From)
- End;
-
- BEGIN
- END.