From 37da2899f40661e3e9631e497da8dc59b971cbd0 Mon Sep 17 00:00:00 2001 From: "Charles.Forsyth" Date: Fri, 22 Dec 2006 17:07:39 +0000 Subject: 20060303a --- appl/lib/strinttab.b | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 appl/lib/strinttab.b (limited to 'appl/lib/strinttab.b') diff --git a/appl/lib/strinttab.b b/appl/lib/strinttab.b new file mode 100644 index 00000000..a96d0f57 --- /dev/null +++ b/appl/lib/strinttab.b @@ -0,0 +1,28 @@ +implement StringIntTab; + +include "strinttab.m"; + +lookup(t: array of StringInt, key: string) : (int, int) +{ + min := 0; + max := len t-1; + while(min <= max){ + try := (min+max)/2; + if(t[try].key < key) + min = try+1; + else if(t[try].key > key) + max = try-1; + else + return (1, t[try].val); + } + return (0, 0); +} + +revlookup(t: array of StringInt, val: int) : string +{ + n := len t; + for(i:=0; i < n; i++) + if(t[i].val == val) + return t[i].key; + return nil; +} -- cgit v1.2.3