DIRECTORY D2Intervals, Random; TestD2Intervals: CEDAR PROGRAM IMPORTS D2Intervals, Random SHARES D2Intervals = BEGIN OPEN D2Intervals; Int: TYPE = INT _ 0; ValueRect: PROC [table: Table, value: REF] RETURNS [rect: Rect] = { sizeOfValues: REF INT _ NARROW [table.userData]; pos: REF LIST OF INT _ NARROW [value]; posx: INT _ pos.first; posy: INT _ pos.rest.first; rect _ [[posx-sizeOfValues^, posx+sizeOfValues^], [posy-sizeOfValues^, posy+sizeOfValues^]]; }; Test: PROC [numberOfValues: NAT, rangeMax: NAT] RETURNS [table: Table, results: LIST OF INT _ NIL, rects: LIST OF Rect _ NIL] = { sizeOfValues: NAT _ 2; rs: Random.RandomStream _ Random.Create[rangeMax, rangeMax]; last: REF; posx, posy: INT; count: INT _ 0; Count: PROC [table: Table, v: Value] RETURNS [BOOL _ FALSE] = {count _ count+1}; Each: PROC [table: Table, value: Value] RETURNS [BOOL _ FALSE] = {rects _ CONS [ValueRect[table, value], rects]}; MakeError: PROC [table: Table, v: Value] RETURNS [BOOL _ FALSE] = {ERROR}; table _ Create[range: [[-sizeOfValues, rangeMax+sizeOfValues], [-sizeOfValues, rangeMax+sizeOfValues]], valueRect: ValueRect, userData: NEW [INT _ sizeOfValues]]; THROUGH [0 .. numberOfValues] DO posx _ Random.NextInt[rs]; posy _ Random.NextInt[rs]; Insert[table, (last _ NEW [LIST OF INT _ LIST [posx, posy]])]; ENDLOOP; IF table.size#numberOfValues+1 THEN ERROR; Delete[table, last]; IF table.size#numberOfValues THEN ERROR; Delete[table, last]; IF table.size#numberOfValues THEN ERROR; FOR i: NAT IN [0 .. table.data.hashSize) DO results _ CONS [IF table.data[i]#NIL THEN table.data[i].size ELSE -1, results]; ENDLOOP; [] _ Enumerate[table, Count]; IF count#numberOfValues THEN ERROR; [] _ Enumerate[table, Each, [[rangeMax/2-10*sizeOfValues, rangeMax/2+10*sizeOfValues], [rangeMax/2-10*sizeOfValues, rangeMax/2+10*sizeOfValues]]]; [] _ Enumerate[table, MakeError, [[-sizeOfValues-10, -sizeOfValues-5], [-sizeOfValues-10, -sizeOfValues-5]]]; }; END. ϊTestD2Intervals.mesa Copyright c 1985 by Xerox Corporation. All rights reversed. Created by Bertrand Serlet, March 12, 1986 11:08:26 pm PST Bertrand Serlet, March 12, 1986 11:34:01 pm PST Test program to shake a little bit the implementation Κέ– "cedar" style˜codešœ™Kšœ Οmœ1™Kšžœ˜—Kšžœžœžœ˜*Kšœ˜Kšžœžœžœ˜(Kšœ˜Kšžœžœžœ˜(šžœžœžœž˜+Jš œ žœžœžœžœžœ˜OKšžœ˜—Kšœ˜Kšžœžœžœ˜#Kšœ’˜’Kšœm˜mKšœ˜—K˜Kšžœ˜K˜K˜K˜——…—  w