OneToOne.Mesa
Last Edited by: Spreitzer, May 7, 1986 4:19:15 pm PDT
DIRECTORY Asserting, HashTable, IO, Rope;
OneToOne: CEDAR DEFINITIONS =
BEGIN
One-to-One Mappings
OneToOne: TYPE = REF OneToOnePrivate;
Represents a one-to-one relation between two sets of non-NIL REF ANYs.
Enumerate: PROC [oto: OneToOne, Consume: PROC [a, b: REF ANY]]
= INLINE {oto.Enumerator[oto, Consume]};
Associate: PROC [oto: OneToOne, a, b: REF ANY]
Will raise Contradiction if a or b already associated or either is NIL.
= INLINE {oto.Associator[oto, a, b]};
Contradiction: ERROR [oto: OneToOne, a, b: REF ANY];
Map: PROC [oto: OneToOne, from: REF ANY, forward: BOOLTRUE] RETURNS [to: REF ANY]
Returns NIL if no association.
= INLINE {to ← oto.Mapper[oto, from, forward]};
CreateVanillaOneToOne: PROC RETURNS [oto: OneToOne];
Creates a OneToOne with an implementation that is likely to often be OK.
Reverse: PROC [OneToOne] RETURNS [OneToOne];
Translate: PROC [inner, translator: OneToOne, translateForward: BOOLTRUE] RETURNS [outer: OneToOne];
xlate = IF translateForward THEN translator ELSE Reverse[translator]
outer[ao, bo] {  ai, bi : xlate[ai, ao] ' inner[ai, bi] ' xlate[bi, bo]
Implementing One-To-One Mappings
OneToOnePrivate: TYPE = RECORD [
Enumerator: PROC [oto: OneToOne, Consume: PROC [a, b: REF ANY]],
Associator: PROC [oto: OneToOne, a, b: REF ANY],
Mapper: PROC [oto: OneToOne, from: REF ANY, forward: BOOLTRUE] RETURNS [REF ANY],
data: REF ANY
];
END.