SinixD2Intervals.mesa
Copyright Ó 1985, 1987 by Xerox Corporation. All rights reversed.
Created by Bertrand Serlet, March 8, 1986 1:40:51 pm PST
Bertrand Serlet, March 18, 1987 0:34:52 am PST
Very much like D2Intervals, but instanciating the types for the Sinix application yields a 20% win in memory and a factor of N (maybe N=3) in speed.
DIRECTORY CD, CDBasics, Core, CoreGeometry, SinixIntervals;
SinixD2Intervals: CEDAR DEFINITIONS = BEGIN
Rect: TYPE = CD.Rect;
universe: Rect = CDBasics.universe;
empty: Rect = CDBasics.empty;
Table: TYPE = REF TableRec;
TableRec: TYPE = MONITORED RECORD [
range: Rect,    -- given at creation time, it retains the range of all rects. Clients should not change this field.
leafBuckets: PRIVATE NAT, -- private field to detect when ReHashing is necessary.
data: PRIVATE REF TableData
];
TableData: PRIVATE TYPE = RECORD [c: SEQUENCE hashSize: NAT OF SinixIntervals.Table];
Create: PROC [range: Rect, logHashSize: NAT ← 2] RETURNS [Table];
Creates a new table with a suggested hash size of 2**logHashSize-1.
Insert: PROC [table: Table, instance: CoreGeometry.Instance, wire: Core.Wire];
Adds a new value in the table.
The corresponding interval must lie in the creation range, otherwise an ERROR might occur.
This operation is monitored.
Does NOT check if already member of the table.
Enumerate: PROC [table: Table, action: PROC [CoreGeometry.Instance, Core.Wire], rect: Rect ← universe];
Enumerates all values of the table that overlap a given rect.
The interval can be outside the range of the table.
This operation is NOT monitored.
Applies action to each value until action returns TRUE or no more value.
Returns TRUE if some action returns TRUE.
DeleteOutside: PROC [table: Table, rect: Rect];
Deletes all occurences of instances that do not overlap rect in table.
The interval can be outside the range of the table.
Table is erased when rect=universe.
The corresponding interval must lie in the creation range, otherwise an ERROR might occur.
This operation is monitored.
END.