Mercurial > repos > rhope
comparison dict.rhope @ 90:c25d75c2440b
Implemented Next@Dictionary and Print@Dictionary
author | Mike Pavone <pavone@retrodev.com> |
---|---|
date | Sat, 31 Jul 2010 15:08:15 -0400 |
parents | 3c4325e6298f |
children | e73a93fb5de1 |
comparison
equal
deleted
inserted
replaced
89:5a195ee08eac | 90:c25d75c2440b |
---|---|
30 { | 30 { |
31 out <- [[[[Build[Dictionary()] | 31 out <- [[[[Build[Dictionary()] |
32 ]Left <<[Dictionary[]] | 32 ]Left <<[Dictionary[]] |
33 ]Right <<[Dictionary[]] | 33 ]Right <<[Dictionary[]] |
34 ]Straight <<[val] | 34 ]Straight <<[val] |
35 ]Bits <<[4294967295u32] //Maximum 32-bit unsigned int value | 35 ]Bits <<[0u32] |
36 } | 36 } |
37 | 37 |
38 _Set New[index,val,bits,bitindex:out] | 38 _Set New[index,val,bits,bitindex:out] |
39 { | 39 { |
40 nbitindex <- [bitindex]+[1] | 40 nbitindex <- [bitindex]+[1] |
41 [index]Dict Bits[nbitindex] | 41 [index]Dict Bits[nbitindex] |
42 { straight <- _Set New[index,val,~,nbitindex] } | 42 { straight <- _Set New[index,val,[~]+[1u32],nbitindex] } |
43 { straight <- _Terminal Node[val] } | 43 { straight <- _Terminal Node[val] } |
44 out <- [[[[Build[Dictionary()]]Left <<[Dictionary[]]]Right <<[Dictionary[]]]Straight <<[straight]]Bits <<[bits] | 44 out <- [[[[Build[Dictionary()]]Left <<[Dictionary[]]]Right <<[Dictionary[]]]Straight <<[straight]]Bits <<[bits] |
45 } | 45 } |
46 | 46 |
47 _Set@Empty Dictionary[dict,index,val,bits,bitindex:out] | 47 _Set@Empty Dictionary[dict,index,val,bits,bitindex:out] |
49 out <- _Set New[index,val,bits,bitindex] | 49 out <- _Set New[index,val,bits,bitindex] |
50 } | 50 } |
51 | 51 |
52 Set@Empty Dictionary[dict,index,val:out] | 52 Set@Empty Dictionary[dict,index,val:out] |
53 { | 53 { |
54 out <- _Set New[index,val, Dict Type ID[index], -1] | 54 out <- _Set New[index,val, [Dict Type ID[index]]+[1u32], -1] |
55 } | 55 } |
56 | 56 |
57 First@Empty Dictionary[dict:first,not found] | 57 First@Empty Dictionary[dict:first,not found] |
58 { | 58 { |
59 not found <- dict | 59 not found <- dict |
65 } | 65 } |
66 | 66 |
67 | 67 |
68 Index@Dictionary[dict,index:out,not found] | 68 Index@Dictionary[dict,index:out,not found] |
69 { | 69 { |
70 out,not found <- [dict]_Index[index,Dict Type ID[index], -1] | 70 out,not found <- [dict]_Index[index,[Dict Type ID[index]]+[1u32], -1] |
71 } | 71 } |
72 | 72 |
73 _Index@Dictionary[dict,index,bits,bitindex:out,not found] | 73 _Index@Dictionary[dict,index,bits,bitindex:out,not found] |
74 { | 74 { |
75 If[[bits]=[[dict]Bits >>]] | 75 If[[bits]=[[dict]Bits >>]] |
76 { | 76 { |
77 If[[bits]=[4294967295u32]] | 77 If[[bits]=[0u32]] |
78 { | 78 { |
79 out <- Straight >>[dict] | 79 out <- Straight >>[dict] |
80 }{ | 80 }{ |
81 nbitindex <- [bitindex]+[1] | 81 nbitindex <- [bitindex]+[1] |
82 nbits <- [index]Dict Bits[nbitindex] {} | 82 [index]Dict Bits[nbitindex] |
83 { nbits <- 4294967295u32 } | 83 { nbits <- [~]+[1u32] } |
84 { nbits <- 0u32 } | |
84 out,not found <- [[dict]Straight >>]_Index[index,nbits,nbitindex] | 85 out,not found <- [[dict]Straight >>]_Index[index,nbits,nbitindex] |
85 } | 86 } |
86 }{ | 87 }{ |
87 If[[bits]<[[dict]Bits >>]] | 88 If[[bits]<[[dict]Bits >>]] |
88 { | 89 { |
94 } | 95 } |
95 } | 96 } |
96 | 97 |
97 Set@Dictionary[dict,index,val:out] | 98 Set@Dictionary[dict,index,val:out] |
98 { | 99 { |
99 out <- [dict]_Set[index,val,Dict Type ID[index], -1] | 100 out <- [dict]_Set[index,val,[Dict Type ID[index]]+[1u32], -1] |
100 } | 101 } |
101 | 102 |
102 _Set@Dictionary[dict,index,val,bits,bitindex:out] | 103 _Set@Dictionary[dict,index,val,bits,bitindex:out] |
103 { | 104 { |
104 If[[bits]=[[dict]Bits >>]] | 105 If[[bits]=[[dict]Bits >>]] |
105 { | 106 { |
106 If[[bits]=[4294967295u32]] | 107 If[[bits]=[0u32]] |
107 { | 108 { |
108 out <- [dict]Straight <<[val] | 109 out <- [dict]Straight <<[val] |
109 }{ | 110 }{ |
110 nbitindex <- [bitindex]+[1] | 111 nbitindex <- [bitindex]+[1] |
111 nbits <- [index]Dict Bits[nbitindex] {} | 112 [index]Dict Bits[nbitindex] |
112 { nbits <- 4294967295u32 } | 113 { nbits <- [~]+[1u32] } |
114 { nbits <- 0u32 } | |
113 out <- [dict]Straight <<[[[dict]Straight >>]_Set[index,val,nbits,nbitindex]] | 115 out <- [dict]Straight <<[[[dict]Straight >>]_Set[index,val,nbits,nbitindex]] |
114 } | 116 } |
115 }{ | 117 }{ |
116 If[[bits]<[[dict]Bits >>]] | 118 If[[bits]<[[dict]Bits >>]] |
117 { | 119 { |
132 | 134 |
133 _First Type ID@Dictionary[dict:typeid,node] | 135 _First Type ID@Dictionary[dict:typeid,node] |
134 { | 136 { |
135 typeid,node <- [[dict]Left >>]_First Type ID {} {} | 137 typeid,node <- [[dict]Left >>]_First Type ID {} {} |
136 { | 138 { |
137 typeid <- [dict]Bits >> | 139 typeid <- [[dict]Bits >>]-[1u32] |
138 node <- dict | 140 node <- Straight >>[dict] |
139 } | 141 } |
140 } | 142 } |
141 | 143 |
142 _First@Empty Dictionary[dict,keylist:keyout,none] | 144 _First@Empty Dictionary[dict,keylist:keyout,none] |
143 { | 145 { |
146 | 148 |
147 _First@Dictionary[dict,keylist:keyout] | 149 _First@Dictionary[dict,keylist:keyout] |
148 { | 150 { |
149 keyout <- [[dict]Left >>]_First[keylist] {} | 151 keyout <- [[dict]Left >>]_First[keylist] {} |
150 { | 152 { |
151 If[[[dict]Bits >>] = [4294967295u32]] | 153 If[[[dict]Bits >>] = [0u32]] |
152 { | 154 { |
153 keyout <- keylist | 155 keyout <- keylist |
154 }{ | 156 }{ |
155 keyout <- [[dict]Straight >>]_First[[keylist]Append[[dict]Bits >>]] | 157 keyout <- [[dict]Straight >>]_First[[keylist]Append[[[dict]Bits >>]-[1u32]]] |
156 } | 158 } |
157 } | 159 } |
158 } | 160 } |
159 | 161 |
160 First@Dictionary[dict:out,none] | 162 First@Dictionary[dict:out,none] |
161 { | 163 { |
162 typeid, node <- [dict]_First Type ID | 164 typeid, node <- [dict]_First Type ID |
163 l <- List[] | 165 rawkey <- [node]_First[List[]] |
164 rawkey <- [[node]Left >>]_First[l] {} | |
165 { | |
166 rawkey <- [[node]Straight >>]_First[l] | |
167 } | |
168 out <- [Build[Blueprint From ID[typeid]]]From Dict Key[rawkey] | 166 out <- [Build[Blueprint From ID[typeid]]]From Dict Key[rawkey] |
169 } | 167 } |
170 | 168 |
169 Next@Dictionary[dict,cur:out,none] | |
170 { | |
171 [cur]Dict Type ID | |
172 { rawkey,typeid,none <- [dict]_Next Type ID[[~]+[1u32], cur] } | |
173 | |
174 out <- [Build[Blueprint From ID[typeid]]]From Dict Key[rawkey] | |
175 } | |
176 | |
177 _Next@Empty Dictionary[dict:out,none] | |
178 { | |
179 none <- dict | |
180 } | |
181 | |
182 _Next Type ID@Empty Dictionary[dict:out,typeid,none] | |
183 { | |
184 none <- dict | |
185 } | |
186 | |
187 _Next Type ID@Dictionary[dict,curtypeid,key:out,typeid,none] | |
188 { | |
189 If[[[dict]Bits >>]=[curtypeid]] | |
190 { | |
191 out <- [[dict]Straight >>]_Next[key,0,List[]] | |
192 { typeid <- [curtypeid]-[1u32] } | |
193 { | |
194 typeid,,none <- [[dict]Right >>]_First Type ID {} | |
195 { | |
196 l <- List[] | |
197 out <- [~]_First[l] {} | |
198 } | |
199 } | |
200 }{ | |
201 If[[curtypeid]<[[dict]Bits >>]] | |
202 { | |
203 out,typeid <- [[dict]Left >>]_Next Type ID[curtypeid,key] {} {} | |
204 { | |
205 typeid <- [curtypeid]-[1u32] | |
206 out <- [[dict]Straight >>]_First[List[]] | |
207 } | |
208 }{ | |
209 out,typeid,none <- [[dict]Right >>]_Next Type ID[curtypeid,key] | |
210 } | |
211 } | |
212 } | |
213 | |
214 _Next@Dictionary[dict,key,keyidx,newkey:out,none] | |
215 { | |
216 [key]Dict Bits[keyidx] | |
217 { bits <- [~]+[1u32] } | |
218 { bits <- 0u32 } | |
219 | |
220 If[[[dict]Bits >>]=[bits]] | |
221 { | |
222 ,goright <- If[bits] | |
223 { | |
224 out,goright <- [[dict]Straight >>]_Next[key,[keyidx]+[1], [newkey]Append[[bits]-[1u32]]] | |
225 } | |
226 Val[goright] | |
227 { | |
228 out,none <- [[dict]Right >>]_First[newkey] | |
229 } | |
230 }{ | |
231 If[[bits]<[[dict]Bits >>]] | |
232 { | |
233 out <- [[dict]Left >>]_Next[key, keyidx, newkey] {} | |
234 { out <- [[dict]Straight >>]_First[[newkey]Append[[[dict]Bits >>]-[1u32]]] } | |
235 }{ | |
236 out,none <- [[dict]Right >>]_Next[key, keyidx, newkey] | |
237 } | |
238 } | |
239 } | |
240 | |
241 _Print Dict[dict,key] | |
242 { | |
243 val <- String[[dict]Index[key]] | |
244 Print[ [[["\t"]Append[String[key]]]Append[": "]]Append[val] ] | |
245 { | |
246 [dict]Next[key] | |
247 { | |
248 _Print Dict[dict, ~] | |
249 } | |
250 } | |
251 } | |
252 | |
253 Print@Dictionary[dict:out] | |
254 { | |
255 Print["Dictionary"] | |
256 { _Print Dict[dict, [dict]First] } | |
257 } | |
258 | |
259 Print@Empty Dictionary[dict:out] | |
260 { | |
261 Print["Dictionary\n\t{Empty}"] | |
262 } | |
263 |