HeapTimeImpl.mesa
Copyright Ó 1992 by Xerox Corporation. All rights reserved.
Greene, August 13, 1990 6:01 pm PDT
Chauser, June 2, 1992 2:06 pm PDT

DIRECTORY
Basics,
Commander,
Heap;
HeapTimeImpl: CEDAR PROGRAM IMPORTS Basics, Commander, Heap =
BEGIN
limit: INT = 5003;
iterations: INT = 200;
RefIntCompareProc: Heap.CompareEvents = TRUSTED{
RETURN [Basics.CompareInt[LOOPHOLE[e1, REF INT]­, LOOPHOLE[e2, REF INT]­]];
};
HeapTime: Commander.CommandProc = {
save: REF ARRAY[0..limit) OF REF INT ¬ NEW[ARRAY [0..limit) OF REF INT];
i, j: INT;
step: INT = limit/iterations;
queue: Heap.Queue = Heap.CreateQueue[RefIntCompareProc];
FOR i IN [0..limit) DO
save[i] ¬ NEW[INT ¬ i];
ENDLOOP;
FOR k: INT ¬ 1, k + step DO
IF k >= limit THEN EXIT;
j ¬ 0;
DO
Heap.InsertEvent[queue, save[j]];
j ¬ j + k;
IF j >= limit THEN j ¬ j - limit;
IF j = 0 THEN EXIT;
ENDLOOP;
FOR i DECREASING IN [0..limit) DO
ref: REF INT ¬ NARROW[Heap.NextEvent[queue]];
IF NOT ref­ = i THEN ERROR;
ENDLOOP;
ENDLOOP;
};
Commander.Register[key: "HeapTime", proc: HeapTime, doc: "To time the heap package"];
END.