home *** CD-ROM | disk | FTP | other *** search
/ PsL Monthly 1993 December / PSL Monthly Shareware CD-ROM (December 1993).iso / prgmming / dos / pascal / exarray.com / TEST.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1989-08-19  |  2.1 KB  |  73 lines

  1. Program Test_ExtendedArray_Based_Heaps;
  2.  
  3. Uses XHeaps,Crt;
  4.  
  5. Const
  6.   Num = 100000;  {Compile to disk.  Takes 18 hours, 23 minutes on my
  7.                   6.44mhz 8088 XT-Clone.}
  8.  
  9.                  {
  10.                    This ExtendedHeap exists in 11 lobes, each holding
  11.                    9091 real numbers.  8 are always in memory, and 3
  12.                    are always on disk.  It took 42 minutes to SiftUp
  13.                    all 100000 reals, which I consider very good. BUT,
  14.                    the first 9090 elements took 6 hours and 47 minutes
  15.                    to Sort out. The second 9091 took 4 hours and 48
  16.                    minutes, and the third took 3 hours and 17 minutes.
  17.                    The remaining 8 took only 3 hours and 31 minutes.
  18.                    This rather extreme example points out the inherent
  19.                    slowness encountered in the SiftDown operation,
  20.                    whenever even 1 Lobe must still reside on Disk, due
  21.                    to SiftDown's need to examine each Lobe for each pass.
  22.  
  23.                    For serial applications (such as Stacks, or arrays
  24.                    which will always be accessed sequentially), the
  25.                    ExtendedArray should be very satisfactory even for
  26.                    ridiculously large applications.  For Random access,
  27.                    something else will be preferable!
  28.                  }
  29.  
  30. Var
  31.   H : RealHeap;
  32.   I : LongInt;
  33.   R : Real;
  34.  
  35. Begin
  36.   ClrScr;
  37.   Randomize;
  38.  
  39.   WriteLn (MemAvail,' Bytes Available before Initialization.');
  40.  
  41.   H.Create;
  42.   H.Init(Num);
  43.  
  44.   WriteLn (MemAvail,' Bytes Available after Initialization.');
  45.   WriteLn;
  46.   WriteLn ('SORTING ',Num,' FLOATING POINT NUMBERS.');
  47.  
  48.   For I := 1 to Num do
  49.     Begin
  50.       R := Random;
  51.       R := R*1000000;
  52.       GoToXY (1,5);
  53.       Write ('Sifting Up ',I,'th Element.');
  54.       H.SiftUp (R,I)
  55.     End;
  56.  
  57.   GoToXY (1,6);
  58.   ClrEol;
  59.   Write ('Sorting');
  60.   H.Sort;
  61.   WriteLn;
  62.  
  63.  {  (* Commented off for Time-Test *)
  64.  
  65.   For I := 1 to Num do WriteLn (H.Retrieve(I):5:5,' was the ',I,'th Element');
  66.  
  67.   ReadLn;
  68.  
  69.   H.Destroy;
  70.  
  71.  }
  72.  
  73. End.