From bd83ad37bf8831600b9e5cb42d75c784402b681b Mon Sep 17 00:00:00 2001 From: Mahmoud Emad Date: Mon, 17 Mar 2025 22:23:14 +0200 Subject: [PATCH] feat: Improve RadixTree debugging output - Enable printing of RadixTree debug information: The `debug_db` and `print_tree_from_node` functions now print detailed information about the RadixTree's internal structure, aiding in debugging. This improves the developer experience by providing better tools for understanding and troubleshooting issues within the RadixTree. - Remove unnecessary comments: Unnecessary comments in the `debug_db` function have been removed to improve code clarity. --- lib/data/radixtree/radixtree_debug.v | 18 ++++++++++-------- lib/vfs/vfs_contacts/vfs_implementation_test.v | 1 - 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/lib/data/radixtree/radixtree_debug.v b/lib/data/radixtree/radixtree_debug.v index 931e935c..86062683 100644 --- a/lib/data/radixtree/radixtree_debug.v +++ b/lib/data/radixtree/radixtree_debug.v @@ -1,5 +1,7 @@ module radixtree +import freeflowuniverse.herolib.ui.console + // Gets a node from the database by its ID pub fn (mut rt RadixTree) get_node_by_id(id u32) !Node { node_data := rt.db.get(id)! @@ -29,18 +31,18 @@ pub fn (mut rt RadixTree) debug_db() ! { for id := u32(0); id < next_id; id++ { if data := rt.db.get(id) { if node := deserialize_node(data) { - // console.print_debug('ID ${id}:') - // console.print_debug(' Key Segment: "${node.key_segment}"') - // console.print_debug(' Is Leaf: ${node.is_leaf}') - // console.print_debug(' Children: ${node.children.len}') + console.print_debug('ID ${id}:') + console.print_debug(' Key Segment: "${node.key_segment}"') + console.print_debug(' Is Leaf: ${node.is_leaf}') + console.print_debug(' Children: ${node.children.len}') for child in node.children { - // console.print_debug(' - Child ID: ${child.node_id}, Key Part: "${child.key_part}"') + console.print_debug(' - Child ID: ${child.node_id}, Key Part: "${child.key_part}"') } } else { - // console.print_debug('ID ${id}: Failed to deserialize node') + console.print_debug('ID ${id}: Failed to deserialize node') } } else { - // console.print_debug('ID ${id}: No data') + console.print_debug('ID ${id}: No data') } } } @@ -66,7 +68,7 @@ pub fn (mut rt RadixTree) print_tree_from_node(node_id u32, indent string) ! { } node_info += ']' } - // console.print_debug(node_info) + console.print_debug(node_info) // Print children recursively with increased indentation for i, child in node.children { diff --git a/lib/vfs/vfs_contacts/vfs_implementation_test.v b/lib/vfs/vfs_contacts/vfs_implementation_test.v index 21d568b0..1142723c 100644 --- a/lib/vfs/vfs_contacts/vfs_implementation_test.v +++ b/lib/vfs/vfs_contacts/vfs_implementation_test.v @@ -1,6 +1,5 @@ module vfs_contacts -import freeflowuniverse.herolib.vfs import freeflowuniverse.herolib.circles.base import freeflowuniverse.herolib.circles.mcc.db as core import freeflowuniverse.herolib.circles.mcc.models as contacts