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