INTERFACEAnM3ID ;
M3ID.T
represents a Modula-3 identifier. Equal identifiers
are represented by the same M3ID.T. Any non-NULL character
may be included in an M3ID.T
.
IMPORT M3Buf; TYPE T = [-16_7fffffff-1 .. 16_7fffffff]; (* a 32-bit integer *) CONST NoID = 0; (* an illegal ID, never returned by Add or FromStr *) PROCEDURE Add (x: TEXT; class: [0..255] := 0): T;
Returns the ID representingx
and sets the class of the ID toclass
.
PROCEDURE FromStr (READONLY buf: ARRAY OF CHAR; length: INTEGER := 99999): T;
Returns the ID representing buf[0 .. MIN(HIGH(buf), length-1)].
PROCEDURE ToText (t: T): TEXT;
Returns a text equal to the one t
represents.
PROCEDURE GetClass (t: T): INTEGER;
Returns the class assigned to t
.
PROCEDURE Hash (t: T): INTEGER;
Returns the hash value of t
.
PROCEDURE Put (wr: M3Buf.T; t: T);
== M3Buf.PutText (ToText(t)), without the implied TEXT allocation
PROCEDURE AdvanceMarks ();
start using a new
set of marks. They're recycled after 256 advances.
PROCEDURE SetMark (t: T): BOOLEAN;
ReturnTRUE
ifSetMark(t)
hash been called since the last call toAdvanceMarks
. There's a chance for false positives, so clients must be prepared to check thatt
was indeed marked twice.
PROCEDURE IsLT (a, b: T): BOOLEAN;
ReturnTRUE
if the text represented bya
is lexicographically less than the one represented byb
.
END M3ID.