home *** CD-ROM | disk | FTP | other *** search
- Unit XHeaps;
-
- { PERFORMANCE ISSUES }
- { The biggest performance drawback to this method of "virtual" array }
- { implementation is encountered when each Lobe of the array must be }
- { accessed in turn for a given operation. This is the case for the }
- { SiftDown operation, in particular. Thus, BuildHeap and SiftDown }
- { both suffer from large performance problems. These problems are }
- { decreased as the size of array elements grows, and as the "load }
- { factor" (percent of array in Buffer) increases. Though I have not }
- { tested it, I expect that an array of 1000 records, each of 1000 or }
- { more bytes, would have very satisfactory performance, for example. }
-
- { If you attempt such a test, I would be very interested in the results! }
-
- INTERFACE
- Uses XGenHeap,SrtFuncs;
-
- { All Heaps additionally inherit the following Methods:
-
- (* ExtendedArray Methods *)
- Procedure Create;
- Procedure Destroy;
-
- Function MaxSize;
- Function ElemSize;
-
- (* XGenericHeap Methods *)
- Procedure Swap (I,J : LongInt);
- Procedure SiftDown (I,J : LongInt);
- Procedure BuidHeap;
- Procedure ChangeSort (NewSort : SortFunc);
- Procedure Sort;
- Procedure HeapSort;
- }
-
- Type
- RealHeap = Object (XGenericHeap)
-
- { Re-Defining these methods re-introduces Types and }
- { most importantly, Type-Checking to the Generic }
- { (typeless) Heap, as well as making the calls more }
- { "natural" for the actual applications Heaps. }
-
- { Follow this pattern when defining your descendant Heaps }
-
-
- Procedure Init (MaxElements : LongInt);
-
- Procedure Accept (I : Real; Index : LongInt);
-
- Function Retrieve (Index : LongInt) : Real;
-
- { Retrieve will nead to be a procedure for
- records or objects. }
-
- Procedure SiftUp (I : Real; Index : LongInt);
-
- Procedure Copy (From : RealHeap);
- End;
-
- IMPLEMENTATION
-
- Procedure RealHeap.Init;
- Begin
- XGenericHeap.Init (MaxElements,SizeOf(Real),SortReal)
- End;
-
- Procedure RealHeap.Accept;
- Var
- J : Real;
- Begin
- J := I;
- XGenericHeap.Accept (J,Index,SizeOf(Real))
- End;
-
- Function RealHeap.Retrieve;
- Var
- J : Real;
- Begin
- XGenericHeap.Retrieve (J,Index,SizeOf(Real));
- Retrieve := J
- End;
-
- Procedure RealHeap.SiftUp;
- Var
- J : Real;
- Begin
- J := I;
- XGenericHeap.SiftUp (J,Index,SizeOf(Real))
- End;
-
- Procedure RealHeap.Copy (From : RealHeap);
- Begin
- XGenericHeap.Copy (From)
- End;
-
- BEGIN
- END.