3 ms·
One thing that's not explicitly mentioned: append-only trees necessarily lack `parent` pointers. This means that your "iterator" can't be a lightweight type, i
by o11c 3y ago
One thing that's not explicitly mentioned: append-only trees necessarily lack `parent` pointers.
This means that your "iterator" can't be a lightweight type, it has to contain an array of parent nodes to visit (again) later. You can use a fixed-size array if you can reason about the maximum height of the tree (for a balanced binary tree, this means around `2*POINTER_BITS`, which is 1024 bytes on a 64-bit platform; it will be less for a B-tree (`2*log(POINTER_MAX, CHILDREN_PER_NODE)`) but you now have to either track or re-scan for the index of the child you just returned from). Beware buffer overflow logic bugs if your tree isn't as balanced as you thought!