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/ebook/strmap.b | |
| parent | 54bc8ff236ac10b3eaa928fd6bcfc0cdb2ba46ae (diff) | |
20060303a
Diffstat (limited to 'appl/ebook/strmap.b')
| -rw-r--r-- | appl/ebook/strmap.b | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/appl/ebook/strmap.b b/appl/ebook/strmap.b new file mode 100644 index 00000000..32e94b31 --- /dev/null +++ b/appl/ebook/strmap.b @@ -0,0 +1,40 @@ +implement Strmap; +include "strmap.m"; + +Map.new(a: array of string): ref Map +{ + map := ref Map(a, array[31] of list of (string, int)); + # enter all style names in hash table for reverse lookup + s2i := map.s2i; + for (i := 0; i < len a; i++) { + if (a[i] != nil) { + v := hashfn(a[i], len s2i); + s2i[v] = (a[i], i) :: s2i[v]; + } + } + return map; +} + +Map.s(map: self ref Map, i: int): string +{ + return map.i2s[i]; +} + +Map.i(map: self ref Map, s: string): int +{ + v := hashfn(s, len map.s2i); + for (l := map.s2i[v]; l != nil; l = tl l) + if ((hd l).t0 == s) + return (hd l).t1; + return -1; +} + +hashfn(s: string, n: int): int +{ + h := 0; + m := len s; + for(i:=0; i<m; i++){ + h = 65599*h+s[i]; + } + return (h & 16r7fffffff) % n; +} |
