as is
without express or implied warranty. Export of this
software outside of the United States of America may require an
export license.
$Id: Equivalence.ig.html,v 1.3 2010-04-29 17:17:56 wagner Exp $
GENERIC INTERFACEEquivalence (Elem);
A T
represents an equivalence relation on the set of all Elem.T
s.
A newly created Default
has each Elem.T
in its own equivalence
class.
Interface Elem
is expected to have the following declaration:
PROCEDURE Equal(e1, e2: Elem.T): BOOLEAN;which defines the a priori equality of two elements.
The Default
implementation (union-find with path compression using
hash tables) also expects an ElemElemTbl
.
TYPE T = OBJECT METHODS equal(e1, e2: Elem.T): BOOLEAN;
aree1
ande2
members of the same equivalence class?
identify(e1, e2: Elem.T): BOOLEAN;
join the two equivalence classes represented bye1
ande2
. returnTRUE
iff they are already equal.
canon(e: Elem.T): Elem.T;
return the canonical representative of the class containing e
.
iterate(): Iterator;
For each element which is not its own canonical representative, obtain that element asalias
, and its canonical representative ascanon
.
END; Iterator = OBJECT METHODS next(VAR alias, canon: Elem.T): BOOLEAN; END; Default <: T OBJECT METHODS init(sizeHint: CARDINAL := 0; leaderPreference: Preference := NIL): Default; END; Preference = OBJECT METHODS is(thisBetter, thanThis: Elem.T): BOOLEAN; END; END Equivalence.