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/dict.b | |
| parent | 54bc8ff236ac10b3eaa928fd6bcfc0cdb2ba46ae (diff) | |
20060303a
Diffstat (limited to 'appl/lib/dict.b')
| -rw-r--r-- | appl/lib/dict.b | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/appl/lib/dict.b b/appl/lib/dict.b new file mode 100644 index 00000000..4df241af --- /dev/null +++ b/appl/lib/dict.b @@ -0,0 +1,57 @@ +implement Dictionary; + +# +# This is intended to be a simple dictionary of string tuples +# It is not intended for large data sets or efficient deletion of keys +# + +include "dict.m"; + +Dict.add( d: self ref Dict, e: (string, string) ) +{ + if (d.entries == nil) + d.entries = e::nil; + else + d.entries = e::d.entries; +} + +Dict.delete( d: self ref Dict, k: string ) +{ + key : string; + newlist : list of (string, string); + temp := d.entries; + + while (temp != nil) { + (key,nil) = hd temp; + if (key != k) + newlist = (hd temp)::newlist; + temp = tl temp; + } + d.entries = newlist; +} + +Dict.lookup( d: self ref Dict, k: string ) :string +{ + key, value :string; + temp := d.entries; + while (temp != nil) { + (key,value) = hd temp; + if (key == k) + return value; + temp = tl temp; + } + return nil; +} + +Dict.keys( d: self ref Dict ) :list of string +{ + key: string; + keylist : list of string; + temp := d.entries; + while (temp != nil) { + (key, nil) = hd temp; + keylist = key::keylist; + temp = tl temp; + } + return keylist; +} |
