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:
BOOL ←
TRUE]
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:
BOOL ←
TRUE]
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: BOOL ← TRUE] RETURNS [REF ANY],
data: REF ANY
];
Structural Comparison
Compare: PROC [ctA, ctB: Core.CellType--of class Record--, hints: OneToOne] RETURNS [isomorphic: BOOL, association: OneToOne];
}.