diff options
| author | Charles.Forsyth <devnull@localhost> | 2006-12-22 17:07:39 +0000 |
|---|---|---|
| committer | Charles.Forsyth <devnull@localhost> | 2006-12-22 17:07:39 +0000 |
| commit | 37da2899f40661e3e9631e497da8dc59b971cbd0 (patch) | |
| tree | cbc6d4680e347d906f5fa7fca73214418741df72 /appl/lib/strinttab.b | |
| parent | 54bc8ff236ac10b3eaa928fd6bcfc0cdb2ba46ae (diff) | |
20060303a
Diffstat (limited to 'appl/lib/strinttab.b')
| -rw-r--r-- | appl/lib/strinttab.b | 28 |
1 files changed, 28 insertions, 0 deletions
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; +} |
