SetDef
is a generic interface defining sets of Elem.T
's,
implemented via hash tables.
GENERIC INTERFACESetDef (ElemSet);
WHEREElemSet = Set(Elem)
, andElem.T
is a type that is not an open array type andElem
contains
PROCEDURE Equal(e1, e2: Elem.T): BOOLEAN; PROCEDURE Hash(k: Key.T): Word.T;Equal
must be an equivalence relation andHash
must respect that equivalence relation, i.e., ifEqual(k1, k2)
, thenHash(k1)=Hash(k2)
.
Hash
andEqual
may be declared with a parameter mode of eitherVALUE
orREADONLY
, but notVAR
.
TYPE Public = ElemSet.T OBJECT METHODS init(sizeHint: CARDINAL := 0): T END; T <: Public; Iterator <: ElemSet.Iterator;The expression
NEW(SetDef.T).init(sz)creates a new, empty set. The argument
sz
is a hint; the set may
be more efficient if sz
accurately predicts the maximum number of
elements it will ever contain.
END SetDef.