Iterate starting at X #185

Closed
opened 2022-03-06 16:56:24 +00:00 by danthegoodman1 · 4 comments
danthegoodman1 commented 2022-03-06 16:56:24 +00:00 (Migrated from github.com)

For structures like the btree, it would be useful to be able to specify a node to start from that is not the start or end of the tree. For example how google's btree has the AscendRange function, it would be nice to be able to efficiently move to a node, and start iterating from there.

For structures like the btree, it would be useful to be able to specify a node to start from that is not the start or end of the tree. For example how google's btree has the `AscendRange` function, it would be nice to be able to efficiently move to a node, and start iterating from there.
emirpasic commented 2022-03-09 08:17:41 +00:00 (Migrated from github.com)

@danthegoodman1 you do have access to the internal nodes if you look at how the iterators work, and the nodes are exposed so you could implement your own transversal: https://pkg.go.dev/github.com/emirpasic/[email protected]/trees/btree

In short, each Node is a subtree, so as long you reach some Node you can create an iterator at that level to iterate over the sub-tree. Let me know if I can help here to provide some more general solutions if the above does not satisfy your needs.

@danthegoodman1 you do have access to the internal nodes if you look at how the iterators work, and the nodes are exposed so you could implement your own transversal: https://pkg.go.dev/github.com/emirpasic/[email protected]/trees/btree In short, each Node is a subtree, so as long you reach some Node you can create an iterator at that level to iterate over the sub-tree. Let me know if I can help here to provide some more general solutions if the above does not satisfy your needs.
danthegoodman1 commented 2022-03-10 21:35:38 +00:00 (Migrated from github.com)

Hey Emir, thanks for the quick response!

Yes having to implement a custom traversal was something I was hoping to avoid, I know it's relatively trivial, maybe I was just being a bit lazy :P

Maybe having .Next() and .Prev() functions on the nodes would make this easier too, but I guess I can just pull a bunch of code from the Iterator and do this myself.

Hey Emir, thanks for the quick response! Yes having to implement a custom traversal was something I was hoping to avoid, I know it's relatively trivial, maybe I was just being a bit lazy :P Maybe having `.Next()` and `.Prev()` functions on the nodes would make this easier too, but I guess I can just pull a bunch of code from the `Iterator` and do this myself.
emirpasic commented 2022-03-10 22:36:37 +00:00 (Migrated from github.com)

@danthegoodman1 it is probably trivial but this is all relative depending on the experience one has with this. It is hard to provide a generic solution to satisfy all requirements here, so your custom implementation would perhaps be the best option here. Let me know if you hit a snag with it and if I can help out.

@danthegoodman1 it is probably trivial but this is all relative depending on the experience one has with this. It is hard to provide a generic solution to satisfy all requirements here, so your custom implementation would perhaps be the best option here. Let me know if you hit a snag with it and if I can help out.
danthegoodman1 commented 2022-03-10 22:51:41 +00:00 (Migrated from github.com)

I appreciate the extended hand, thanks!

I appreciate the extended hand, thanks!
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
golibs/gms-gods#185
No description provided.