Skip to content

Instantly share code, notes, and snippets.

@RafaelGSS
Created December 7, 2022 19:12
Show Gist options
  • Save RafaelGSS/5b4f09c559a54f53f9b7c8c030744d19 to your computer and use it in GitHub Desktop.
Save RafaelGSS/5b4f09c559a54f53f9b7c8c030744d19 to your computer and use it in GitHub Desktop.
PrintTree helper to visualize the fs prefix radix tree
void PrintTree(FSPermission::RadixTree::Node* node, int spaces = 0) {
std::string whitespace = "";
for (int i = 0; i < spaces; ++i) {
whitespace += " ";
}
if (node == nullptr) {
std::cout << whitespace << "Node nullptr" << std::endl;
return;
}
if (node->wildcard_child != nullptr) {
std::cout << whitespace << "Wilcard: " << node->prefix << std::endl;
} else {
std::cout << whitespace << "Prefix: " << node->prefix << std::endl;
if (node->children.size()) {
int child = 0;
for (const auto pair : node->children) {
++child;
std::cout << whitespace << "Child " << pair.first << std::endl;
PrintTree(pair.second, spaces + 2);
}
std::cout << whitespace << "End of tree(c): " << node->prefix << std::endl;
} else {
std::cout << whitespace << "End of tree: " << node->prefix << std::endl;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment