What pointer lifetime to use when iterating through a tree?
I've created a tree data structure:
which I've added nodes to. I now want to search for a node by iterating over its children:
As you can see, I'm using
I get an error at the
Is there an idiomatic way to do this correctly? I've tried
which I've added nodes to. I now want to search for a node by iterating over its children:
As you can see, I'm using
UnsafePointer here which I don't really like. I tried to use Pointer, but I can't figure out how to get the lifetime right. If I use:I get an error at the
append call: invalid call to 'append': method argument #0 cannot be converted from 'Pointer[0, BKTreeNode, self.root._value.children, 0]' to 'Pointer[0, BKTreeNode, self.root._value, 0]'.Is there an idiomatic way to do this correctly? I've tried
Arc but this seems to slow the search down by a lot. I'm using Pointers to avoid copying nodes. Is this the right way to go about this in the first place?