Mercurial > repos > rhope
annotate dict.rhope @ 83:27bb051d631c
Initial implementation of Dictionary
author | Mike Pavone <pavone@retrodev.com> |
---|---|
date | Tue, 27 Jul 2010 23:33:31 -0400 |
parents | |
children | 3c4325e6298f |
rev | line source |
---|---|
83
27bb051d631c
Initial implementation of Dictionary
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1 |
27bb051d631c
Initial implementation of Dictionary
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
2 Blueprint Empty Dictionary |
27bb051d631c
Initial implementation of Dictionary
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
3 { |
27bb051d631c
Initial implementation of Dictionary
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
4 } |
27bb051d631c
Initial implementation of Dictionary
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
5 |
27bb051d631c
Initial implementation of Dictionary
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
6 Blueprint Dictionary |
27bb051d631c
Initial implementation of Dictionary
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
7 { |
27bb051d631c
Initial implementation of Dictionary
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
8 Left |
27bb051d631c
Initial implementation of Dictionary
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
9 Right |
27bb051d631c
Initial implementation of Dictionary
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
10 Straight |
27bb051d631c
Initial implementation of Dictionary
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
11 Bits(UInt32,Naked) |
27bb051d631c
Initial implementation of Dictionary
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
12 } |
27bb051d631c
Initial implementation of Dictionary
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
13 |
27bb051d631c
Initial implementation of Dictionary
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
14 Dictionary[:out] |
27bb051d631c
Initial implementation of Dictionary
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
15 { |
27bb051d631c
Initial implementation of Dictionary
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
16 out <- Build[Empty Dictionary()] |
27bb051d631c
Initial implementation of Dictionary
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
17 } |
27bb051d631c
Initial implementation of Dictionary
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
18 |
27bb051d631c
Initial implementation of Dictionary
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
19 _Index@Empty Dictionary[dict,index,bits,bitindex:out,not found] |
27bb051d631c
Initial implementation of Dictionary
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
20 { |
27bb051d631c
Initial implementation of Dictionary
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
21 not found <- dict |
27bb051d631c
Initial implementation of Dictionary
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
22 } |
27bb051d631c
Initial implementation of Dictionary
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
23 |
27bb051d631c
Initial implementation of Dictionary
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
24 Index@Empty Dictionary[dict,index:out,not found] |
27bb051d631c
Initial implementation of Dictionary
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
25 { |
27bb051d631c
Initial implementation of Dictionary
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
26 not found <- dict |
27bb051d631c
Initial implementation of Dictionary
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
27 } |
27bb051d631c
Initial implementation of Dictionary
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
28 |
27bb051d631c
Initial implementation of Dictionary
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
29 _Terminal Node[val:out] |
27bb051d631c
Initial implementation of Dictionary
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
30 { |
27bb051d631c
Initial implementation of Dictionary
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
31 out <- [[[[Build[Dictionary()] |
27bb051d631c
Initial implementation of Dictionary
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
32 ]Left <<[Dictionary[]] |
27bb051d631c
Initial implementation of Dictionary
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
33 ]Right <<[Dictionary[]] |
27bb051d631c
Initial implementation of Dictionary
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
34 ]Straight <<[val] |
27bb051d631c
Initial implementation of Dictionary
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
35 ]Bits <<[4294967295u32] //Maximum 32-bit unsigned int value |
27bb051d631c
Initial implementation of Dictionary
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
36 } |
27bb051d631c
Initial implementation of Dictionary
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
37 |
27bb051d631c
Initial implementation of Dictionary
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
38 _Set New[index,val,bits,bitindex:out] |
27bb051d631c
Initial implementation of Dictionary
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
39 { |
27bb051d631c
Initial implementation of Dictionary
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
40 nbitindex <- [bitindex]+[1] |
27bb051d631c
Initial implementation of Dictionary
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
41 [index]Dict Bits[nbitindex] |
27bb051d631c
Initial implementation of Dictionary
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
42 { straight <- _Set New[index,val,~,nbitindex] } |
27bb051d631c
Initial implementation of Dictionary
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
43 { straight <- _Terminal Node[val] } |
27bb051d631c
Initial implementation of Dictionary
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
44 out <- [[[[Build[Dictionary()]]Left <<[Dictionary[]]]Right <<[Dictionary[]]]Straight <<[straight]]Bits <<[bits] |
27bb051d631c
Initial implementation of Dictionary
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
45 } |
27bb051d631c
Initial implementation of Dictionary
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
46 |
27bb051d631c
Initial implementation of Dictionary
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
47 _Set@Empty Dictionary[dict,index,val,bits,bitindex:out] |
27bb051d631c
Initial implementation of Dictionary
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
48 { |
27bb051d631c
Initial implementation of Dictionary
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
49 out <- _Set New[index,val,bits,bitindex] |
27bb051d631c
Initial implementation of Dictionary
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
50 } |
27bb051d631c
Initial implementation of Dictionary
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
51 |
27bb051d631c
Initial implementation of Dictionary
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
52 Set@Empty Dictionary[dict,index,val:out] |
27bb051d631c
Initial implementation of Dictionary
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
53 { |
27bb051d631c
Initial implementation of Dictionary
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
54 out <- _Set New[index,val, Dict Type ID[index], -1] |
27bb051d631c
Initial implementation of Dictionary
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
55 } |
27bb051d631c
Initial implementation of Dictionary
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
56 |
27bb051d631c
Initial implementation of Dictionary
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
57 First@Empty Dictionary[dict:first,not found] |
27bb051d631c
Initial implementation of Dictionary
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
58 { |
27bb051d631c
Initial implementation of Dictionary
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
59 not found <- dict |
27bb051d631c
Initial implementation of Dictionary
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
60 } |
27bb051d631c
Initial implementation of Dictionary
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
61 |
27bb051d631c
Initial implementation of Dictionary
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
62 Next@Empty Dictionary[dict,index:next,not found] |
27bb051d631c
Initial implementation of Dictionary
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
63 { |
27bb051d631c
Initial implementation of Dictionary
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
64 not found <- dict |
27bb051d631c
Initial implementation of Dictionary
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
65 } |
27bb051d631c
Initial implementation of Dictionary
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
66 |
27bb051d631c
Initial implementation of Dictionary
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
67 |
27bb051d631c
Initial implementation of Dictionary
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
68 Index@Dictionary[dict,index:out,not found] |
27bb051d631c
Initial implementation of Dictionary
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
69 { |
27bb051d631c
Initial implementation of Dictionary
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
70 out,not found <- [dict]_Index[index,Dict Type ID[index], -1] |
27bb051d631c
Initial implementation of Dictionary
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
71 } |
27bb051d631c
Initial implementation of Dictionary
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
72 |
27bb051d631c
Initial implementation of Dictionary
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
73 _Index@Dictionary[dict,index,bits,bitindex:out,not found] |
27bb051d631c
Initial implementation of Dictionary
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
74 { |
27bb051d631c
Initial implementation of Dictionary
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
75 If[[bits]=[[dict]Bits >>]] |
27bb051d631c
Initial implementation of Dictionary
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
76 { |
27bb051d631c
Initial implementation of Dictionary
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
77 If[[bits]=[4294967295u32]] |
27bb051d631c
Initial implementation of Dictionary
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
78 { |
27bb051d631c
Initial implementation of Dictionary
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
79 out <- Straight >>[dict] |
27bb051d631c
Initial implementation of Dictionary
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
80 }{ |
27bb051d631c
Initial implementation of Dictionary
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
81 nbitindex <- [bitindex]+[1] |
27bb051d631c
Initial implementation of Dictionary
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
82 nbits <- [index]Dict Bits[nbitindex] {} |
27bb051d631c
Initial implementation of Dictionary
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
83 { nbits <- 4294967295u32 } |
27bb051d631c
Initial implementation of Dictionary
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
84 out,not found <- [[dict]Straight >>]_Index[index,nbits,nbitindex] |
27bb051d631c
Initial implementation of Dictionary
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
85 } |
27bb051d631c
Initial implementation of Dictionary
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
86 }{ |
27bb051d631c
Initial implementation of Dictionary
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
87 If[[bits]<[[dict]Bits >>]] |
27bb051d631c
Initial implementation of Dictionary
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
88 { |
27bb051d631c
Initial implementation of Dictionary
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
89 go <- Right >>[dict] |
27bb051d631c
Initial implementation of Dictionary
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
90 |
27bb051d631c
Initial implementation of Dictionary
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
91 }{ |
27bb051d631c
Initial implementation of Dictionary
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
92 go <- Left >>[dict] |
27bb051d631c
Initial implementation of Dictionary
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
93 } |
27bb051d631c
Initial implementation of Dictionary
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
94 out,not found <- [go]_Index[index,bits,bitindex] |
27bb051d631c
Initial implementation of Dictionary
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
95 } |
27bb051d631c
Initial implementation of Dictionary
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
96 } |
27bb051d631c
Initial implementation of Dictionary
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
97 |
27bb051d631c
Initial implementation of Dictionary
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
98 Set@Dictionary[dict,index,val:out] |
27bb051d631c
Initial implementation of Dictionary
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
99 { |
27bb051d631c
Initial implementation of Dictionary
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
100 out <- [dict]_Set[index,val,Dict Type ID[index], -1] |
27bb051d631c
Initial implementation of Dictionary
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
101 } |
27bb051d631c
Initial implementation of Dictionary
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
102 |
27bb051d631c
Initial implementation of Dictionary
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
103 _Set@Dictionary[dict,index,val,bits,bitindex:out] |
27bb051d631c
Initial implementation of Dictionary
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
104 { |
27bb051d631c
Initial implementation of Dictionary
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
105 If[[bits]=[[dict]Bits >>]] |
27bb051d631c
Initial implementation of Dictionary
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
106 { |
27bb051d631c
Initial implementation of Dictionary
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
107 If[[bits]=[4294967295u32]] |
27bb051d631c
Initial implementation of Dictionary
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
108 { |
27bb051d631c
Initial implementation of Dictionary
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
109 out <- [dict]Straight <<[val] |
27bb051d631c
Initial implementation of Dictionary
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
110 }{ |
27bb051d631c
Initial implementation of Dictionary
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
111 nbitindex <- [bitindex]+[1] |
27bb051d631c
Initial implementation of Dictionary
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
112 nbits <- [index]Dict Bits[nbitindex] {} |
27bb051d631c
Initial implementation of Dictionary
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
113 { nbits <- 4294967295u32 } |
27bb051d631c
Initial implementation of Dictionary
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
114 out <- [dict]Straight <<[[[dict]Straight >>]_Set[index,val,nbits,nbitindex]] |
27bb051d631c
Initial implementation of Dictionary
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
115 } |
27bb051d631c
Initial implementation of Dictionary
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
116 }{ |
27bb051d631c
Initial implementation of Dictionary
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
117 If[[bits]<[[dict]Bits >>]] |
27bb051d631c
Initial implementation of Dictionary
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
118 { |
27bb051d631c
Initial implementation of Dictionary
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
119 go <- Right >>[dict] |
27bb051d631c
Initial implementation of Dictionary
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
120 out <- [dict]Right <<[new] |
27bb051d631c
Initial implementation of Dictionary
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
121 |
27bb051d631c
Initial implementation of Dictionary
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
122 }{ |
27bb051d631c
Initial implementation of Dictionary
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
123 go <- Left >>[dict] |
27bb051d631c
Initial implementation of Dictionary
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
124 out <- [dict]Left <<[new] |
27bb051d631c
Initial implementation of Dictionary
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
125 } |
27bb051d631c
Initial implementation of Dictionary
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
126 new <- [go]_Set[index,val,bits,bitindex] |
27bb051d631c
Initial implementation of Dictionary
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
127 } |
27bb051d631c
Initial implementation of Dictionary
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
128 } |
27bb051d631c
Initial implementation of Dictionary
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
129 |