Created
December 7, 2022 19:12
-
-
Save RafaelGSS/5b4f09c559a54f53f9b7c8c030744d19 to your computer and use it in GitHub Desktop.
PrintTree helper to visualize the fs prefix radix tree
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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