You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The previous data structure fits quite well with most AST (LiveHD) tree operations with the exception of two popular ones: get_next_sibling and add_child.
156
133
157
-
An alternative data structure. The siblings are consecutive, the descendent from the siblings are after all the siblings.
134
+
### Forest Support
158
135
136
+
Trees can share subtrees via the Forest container:
137
+
```cpp
138
+
Forest<int> forest;
139
+
Tree_pos subtree = forest.create_tree(root_data);
140
+
tree.add_subtree_ref(node_pos, subtree);
159
141
```
160
-
Index: first_child, last_child, parent
161
-
// 01: 02,05,00 | 1
162
-
// 02: 00,00,01 -── 1.1
163
-
// 03: 06,06,01 ├── 1.2
164
-
// 04: 12,14,01 ├── 1.3
165
-
// 05: 17,19,01 ├── 1.4
166
-
// 06: 07,09,03 │ -── 1.2.1
167
-
// 07: 00,00,06 │ -── 1.2.1.1
168
-
// 08: 00,00,06 │ ├── 1.2.1.2
169
-
// 09: 10,11,06 │ |── 1.2.1.3
170
-
// 10: 00,00,09 │ -── 1.2.1.3.1
171
-
// 11: 00,00,09 │ -── 1.2.1.3.2
172
-
// 12: 15,16,04 │ -── 1.3.1
173
-
// 13: 00,00,04 │ ├── 1.3.2
174
-
// 14: 00,00,04 │ ├── 1.3.3
175
-
// 15: 00,00,12 │ -── 1.3.1.1
176
-
// 16: 00,00,12 │ |── 1.3.1.2
177
-
// 17: 00,00,05 │ -── 1.4.1
178
-
// 18: 20,21,05 │ ├── 1.4.2
179
-
// 19: 00,00,05 │ ├── 1.4.3
180
-
// 20: 00,00,18 │ │ -── 1.4.2.1
181
-
// 21: 00,00,18 │ │ -── 1.4.3.1
182
-
```
183
-
184
-
The previous structure handles everything quite fast with the exception of add_child
185
-
186
-
add_child tends to add nodes close to the end. In which case, and append or just shifting a few nodes works fast.
187
-
188
-
Some solutions for random location add_child:
189
-
190
-
-Support a small hashmap with "other children" that did not fit. Only insert starting from last_child, and change last_child to 0 to indicate that last children are in a hashmap.
191
-
192
-
-Allow it BUT trigger a message to fix. This should be rare and easy to fix so that calls are not in that order
193
-
194
-
-Chunk the vector to blocks of 16K entries. This allows smaller pointers (first_child,last_child, parent) using shorts (16bits). WHen a pointer needs to point to other table (16K entry max per table),
195
-
it can have a all ones value (-1) to indicate that the following entry uses the 3 fields (16 bits) as pointer to the larger table (32 bits) and 16 bits as offset.
196
142
143
+
The Forest manages reference counting and cleanup of shared subtrees.
197
144
198
145
### Related
199
146
@@ -202,5 +149,3 @@ Not same, but similar idea and different representation:
202
149
Meyerovich, Leo A., Todd Mytkowicz, and Wolfram Schulte. "Data parallel programming for irregular tree computations." (2011).
203
150
204
151
Vollmer, Michael, Sarah Spall, Buddhika Chamith, Laith Sakka, Chaitanya Koparkar, Milind Kulkarni, Sam Tobin-Hochstadt, and Ryan R. Newton. "Compiling tree transforms to operate on packed representations." (2017): 26.
0 commit comments