blob: 4df241afda6bc07786a79913d09d7daa1c994e4f (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
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;
}
|