--File: OrderedRefArray.mesa
Last Edited by: CSChow, February 1, 1985 0:23:15 am PST
--NB: `Array' here is use in the Cedar sense, ie. fixed size
OrderedRefArray: CEDAR DEFINITIONS = BEGIN
-- Intro: This is a non-Standard interface. It is used to collect results from searches.
-- It was meant to be quick and simple and so may not be the most general one.
-- It makes the uniform assumption that item of smallest value is of the most desirable
-- as far as prunning is concerned
-- Impl: List of ref any with head and tail pointers
Ref: TYPE = REF Rep;
Rep: TYPE; -- Opaque
Index: TYPE = [1..LAST[INTEGER]];
OutOfRange: ERROR[index: Index];
PruneMethodTypes: TYPE = {firstValue, lastValue, firstValueIfFilled, lastValueIfFilled};
PruneMethod: PruneMethodTypes; --Initialized to lastValueIfFilled
--Only Affects GetPruneValue below. See OrderedRefArrayImpl.GetPruneValue
-- This is a global switch that affects all instances.
--eg. change PruneMethod from program or interpter
EachItemAction: TYPE = PROC[itemIndex: Index, item: REF, value: INT] RETURNS [quit: BOOLFALSE];
Create: PROC [maxSize: Index] RETURNS [Ref];
-- maxSize is max number of items to collect
Copy: PROC[oArray: Ref] RETURNS [Ref];
-- Copies 1 level only => shares item
Size: PROC [oArray: Ref] RETURNS [NAT];
MaxSize: PROC[oArray: Ref] RETURNS [Index];
Insert: PROC[oArray: Ref, item: REF, value: INT];
-- values determines ordering of item.
-- smallest at the beginning (index = 1) and most desirable
InsertCheck: PROC[oArray: Ref, item: REF, value: INT] RETURNS [BOOL];
--Insert is going to insert item iff InsertCheck = TRUE
Enumerate: PROC[oArray: Ref, action: EachItemAction, increasing: BOOLTRUE];
Fetch: PROC[oArray: Ref, at: Index] RETURNS [item: REF, value: INT];
--! ERROR OutOfRange[at]
GetPruneValue: PROC[oArray: Ref] RETURNS [INT];
-- IF oArray is Filled THEN return value of worst item kept
-- ELSE return LAST[INT]
GetInsertionCount: PROC[oArray: Ref] RETURNS [INT];
--Counts #calls to Insert on oArray
-- Count is from 1 to LAST[INT] and wrap around to FIRST[INT]
-- Introduced for statistics gathering
END.