tree_iterator 3.0.0 tree_iterator: ^3.0.0 copied to clipboard
Provides simple operations for traversing a tree. Works with any tree structure providing that you can return the set of children for a node when requested.
Tree_Iterator #
Provides simple operations for traversing a tree.
Works with any tree structure providing that you can return the set of children for a node when requested.
FindInTree #
Searches the tree for a child that satisfies a condition.
As soon as we find a child that satisfies the condition the tree traversal stops.
/// search the tree for the 'theOne'.
var theOne = findInTree<SMCState>(virtualRoot, (node) => node.children, (node) => node.isTheOne);
traverseTree #
Traverses the entire tree calling an function on each child.
Traversal continues until the entire tree has been traversed on the call to 'processChild' returns false.
traverseTree<SMCState>(root, (node) => node.children, (node) {
print(node);
/// return false if you want to stop traversal
return true;
});
TODO: #
-
change algoritm to use iteration rather than recursion.
-
add an iterator for us in a for loop.
-
offer breadth first and depth first operations.
e.g.
var theOne = findInTree<SMCState>(virtualRoot, (node) => node.children, (node) => node.isTheOne, method: TreeInterator.depthFirst);
Credits #
The project contains code from:
https://github.com/mkobuolys/flutter-design-patterns
Currently this code isn't in use but the plan is to take its breadth first/depth first algorithms and implement them into this pacagek.