Revealing the frontier with stacks and queues

17 points by denys_seguret


fanf

The comments here led me to think “defunctionalizing the continuation” but that’s way more fancy jargon than this article needs :-)

dpercy

A related advantage: with all the state explicit, it's easier to turn into an iterator. You can provide a nice API like:

fn reachable_from(root: Node) -> impl Iterator<Item = Node>;

...
for n in reachable_from(root) {
  ...
}

which lets the caller break early, etc.

anex9d

Pardon my ignorance, but I don’t understand what reification of the frontier means after reading your article. In particular I would have appreciated seeing examples of this:

And because we reified the frontier, it's very easy to change the control flow, to deal with interrupts, pause the iteration, have interleaving tasks, like iterating on another tree at the same time, etc.

And why that is made easier without recursion and with stacks and queues. Can you help me understand?