forsyth20121205-174063a80cc13 years agoHistory
87 lines · 1.6 KB · Text
RawDownload
.TH STRINGINTTAB 2.SH NAMEstringinttab \- string table lookup module.SH SYNOPSIS.EXinclude "strinttab.m";StringInt: import StringIntTab; strinttab := load StringIntTab StringIntTab->PATH; StringInt: adt{    key: string;    val: int;}; lookup:    fn(tab: array of StringInt, key: string) : (int, int);revlookup: fn(tab: array of StringInt, val: int)    : string;.EE.SH DESCRIPTION.B Stringinttabprovides functions that perform forward and reverse searches of an ordered table of.I key\-valuepairs..PPA table should be constructed as an array of.B StringIntentries, ordered by increasing.I keyvalue.  Keys ordering is determined by comparison of the Unicodevalue of their characters..PP.B Lookupperforms a binary search of.I tabfor the.B StringIntentry whose.B keyfield has a value equal to.I keyand returns a tuple: an.B intwhose value is non-zero if a match has been found and zero otherwise,and an.B intwhose value is equal to the.B valfield of the matching.B StringIntentry..PP.B Revlookupsearches.I tabfor the first.B StringIntentry whose.B valfield has a value equal to.I valand returns the corresponding.B keystring..SH EXAMPLES.EXT := load StringIntTab StringIntTab->PATH; fmtstringtab := array[] of { Strinttab->StringInt	("html", FHtml),	("latex", FLatex),	("latexbook", FLatexBook),	("latexpart", FLatexPart),	("latexproc", FLatexProc),	("latexslides", FLatexSlides),}; (fnd, fmt) := T->lookup(fmtstringtab, "latexbook");fmtstring := T->revlookup(fmtstringtab, FLatex);.EE.SH SOURCE.B /appl/lib/strinttab.b.SH SEE ALSO.IR hash (2).SH BUGS.B Revlookupperforms a sequential search of the table.