DIRECTORY PrincOps USING [zXOR], RefTab USING [EachPairAction, Key, Node, NodeRep, Ref, RefTabRep, Seq, SeqIndex, Val]; RefTabImpl: CEDAR MONITOR LOCKS x USING x: Ref EXPORTS RefTab = { OPEN RefTab; Munch: PROC [key: Key] RETURNS [CARDINAL] = TRUSTED MACHINE CODE { PrincOps.zXOR; }; Create: PUBLIC PROC [mod: SeqIndex _ 17] RETURNS [Ref] = { index: CARDINAL _ 0; data: REF Seq _ NIL; IF mod < 7 THEN mod _ 7; data _ NEW[Seq[mod]]; RETURN[NEW[RefTabRep _ [mod: mod, size: 0, data: data]]]; }; GetSize: PUBLIC PROC [x: Ref] RETURNS [INT] = { RETURN [x.size]; }; Fetch: PUBLIC ENTRY PROC [x: Ref, key: Key] RETURNS [found: BOOL, val: Val] = { ENABLE UNWIND => NULL; hash: CARDINAL _ Munch[key] MOD x.mod; node: Node _ x.data[hash]; WHILE node # NIL DO IF key = node.key THEN RETURN [TRUE, node.val]; node _ node.next; ENDLOOP; RETURN [FALSE, NIL]; }; Replace: PUBLIC ENTRY PROC [x: Ref, key: Key, val: Val] RETURNS [BOOL] = { ENABLE UNWIND => NULL; hash: CARDINAL _ Munch[key] MOD x.mod; node: Node _ x.data[hash]; head: Node _ node; WHILE node # NIL DO IF key = node.key THEN {node.val _ val; RETURN [TRUE]}; node _ node.next; ENDLOOP; RETURN [FALSE]; }; Store: PUBLIC ENTRY PROC [x: Ref, key: Key, val: Val] RETURNS [BOOL] = { ENABLE UNWIND => NULL; hash: CARDINAL _ Munch[key] MOD x.mod; node: Node _ x.data[hash]; head: Node _ node; WHILE node # NIL DO IF key = node.key THEN {node.val _ val; RETURN [FALSE]}; node _ node.next; ENDLOOP; x.data[hash] _ NEW[NodeRep _ [key: key, val: val, next: head]]; x.size _ x.size + 1; RETURN [TRUE]; }; Insert: PUBLIC ENTRY PROC [x: Ref, key: Key, val: Val] RETURNS [BOOL] = { ENABLE UNWIND => NULL; hash: CARDINAL _ Munch[key] MOD x.mod; node: Node _ x.data[hash]; head: Node _ node; WHILE node # NIL DO IF key = node.key THEN RETURN [FALSE]; node _ node.next; ENDLOOP; x.data[hash] _ NEW[NodeRep _ [key: key, val: val, next: head]]; x.size _ x.size + 1; RETURN [TRUE]; }; Delete: PUBLIC ENTRY PROC [x: Ref, key: Key] RETURNS [BOOL] = { ENABLE UNWIND => NULL; hash: CARDINAL _ Munch[key] MOD x.mod; node: Node _ x.data[hash]; head: Node _ node; lag: Node _ NIL; WHILE node # NIL DO IF key = node.key THEN { IF lag = NIL THEN x.data[hash] _ node.next ELSE lag.next _ node.next; x.size _ x.size - 1; RETURN [TRUE]}; lag _ node; node _ node.next; ENDLOOP; RETURN [FALSE]; }; Pairs: PUBLIC PROC [x: Ref, action: EachPairAction] RETURNS [quit: BOOL] = { node: Node _ NIL; index: CARDINAL _ 0; DO [node, index] _ GetNext[x, node, index]; IF node = NIL THEN RETURN [FALSE]; IF action[node.key, node.val] THEN RETURN [TRUE]; ENDLOOP; }; GetNext: ENTRY PROC [x: Ref, node: Node, index: CARDINAL] RETURNS [Node, CARDINAL] = { ENABLE UNWIND => NULL; mod: CARDINAL _ x.mod; IF node # NIL THEN { node _ node.next; IF node # NIL THEN RETURN [node, index]; index _ index + 1} ELSE index _ 0; WHILE index < mod DO node _ x.data[index]; IF node = NIL THEN {index _ index + 1; LOOP}; RETURN [node, index]; ENDLOOP; RETURN [NIL, mod]; }; }. >RefTabImpl.Mesa - implementation of REF table abstraction Copyright c 1985 by Xerox Corporation. All rights reserved. Paxton - August 19, 1982 9:25 am Teitelman - September 8, 1982 9:12 pm Rovner - August 9, 1983 5:26 pm Russ Atkinson (RRA) February 5, 1985 2:01:52 pm PST Private Operations public operations Κ±˜codešœ9™9Kšœ Οmœ1™