You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
import radix
# Function to check if a node is a leaf node
def is_leaf(node):
return not node.prefixes()
# Function to collect all leaf nodes
def get_all_leaf_nodes(rt):
leaf_nodes = []
for node in rt:
if is_leaf(node):
leaf_nodes.append(node)
return leaf_nodes
# Example usage
def main():
rt = radix.Radix()
# Adding some prefixes
rt.add("1.2.2.0/23")
rt.add("1.2.2.0/24")
rt.add("1.2.3.0/24")
rt.add("1.2.4.0/24")
# Getting all leaf nodes
leaf_nodes = get_all_leaf_nodes(rt)
# Printing all leaf nodes
for leaf in leaf_nodes:
print(leaf.prefix)
if __name__ == "__main__":
main()
How to get all leaf nodes from radix tree?
The text was updated successfully, but these errors were encountered: