TSAListImpl.mesa
Maintains an association list from long cardinals to REF ANYs.
Michael Plass, November 2, 1982 10:47 am
DIRECTORY TSAList;
TSAListImpl:
CEDAR MONITOR
EXPORTS TSAList =
BEGIN
list: REF Pair;
Pair: TYPE = RECORD [succ: REF Pair, key: LONG CARDINAL, value: REF ANY];
Define:
PUBLIC
ENTRY
PROCEDURE [key:
LONG
CARDINAL, value:
REF
ANY] =
BEGIN ENABLE UNWIND => {};
p: REF Pair;
FOR p ← list, p.succ UNTIL p=NIL OR p.key = key DO ENDLOOP;
IF p=
NIL
THEN
BEGIN
pair:REF Pair = NEW[Pair];
pair^ ← [succ:list, key:key, value:value];
list ← pair
END
ELSE p.value ← value
END;
Find:
PUBLIC
ENTRY
PROCEDURE [key:
LONG
CARDINAL]
RETURNS [value:
REF
ANY] =
BEGIN ENABLE UNWIND => {};
p: REF Pair;
FOR p ← list, p.succ UNTIL p=NIL OR p.key = key DO ENDLOOP;
value ← IF p=NIL THEN NIL ELSE p.value
END;
UnDefine:
PUBLIC
ENTRY
PROCEDURE [key:
LONG
CARDINAL] =
BEGIN ENABLE UNWIND => {};
prev,p: REF Pair;
prev ← NIL; p ← list;
UNTIL p=
NIL
OR p.key = key
DO
prev ← p;
p ← p.succ
ENDLOOP;
IF p#
NIL
THEN
BEGIN
IF prev=NIL THEN list ← list.succ
ELSE prev.succ ← p.succ
END
END;
END.
Michael Plass, June 28, 1982 8:46 am. Rename of module.
Michael Plass, November 2, 1982 10:47 am. CEDARized.