range-tree: Add print utility
Useful for debugging
This commit is contained in:
@@ -443,6 +443,30 @@ remove_data_func (GcalRange *range,
|
|||||||
return GCAL_TRAVERSE_CONTINUE;
|
return GCAL_TRAVERSE_CONTINUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
recursively_print_node_to_string (Node *n,
|
||||||
|
GString *string,
|
||||||
|
gint depth)
|
||||||
|
{
|
||||||
|
g_autofree gchar *range = NULL;
|
||||||
|
gint64 i;
|
||||||
|
|
||||||
|
for (i = 0; i < depth * 2; i++)
|
||||||
|
g_string_append (string, " ");
|
||||||
|
|
||||||
|
if (!n)
|
||||||
|
{
|
||||||
|
g_string_append (string, "(null)\n");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
range = gcal_range_to_string (n->range);
|
||||||
|
g_string_append_printf (string, "Node %s (hits: %d)\n", range, n->hits);
|
||||||
|
|
||||||
|
recursively_print_node_to_string (n->left, string, depth + 1);
|
||||||
|
recursively_print_node_to_string (n->right, string, depth + 1);
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
gcal_range_tree_free (GcalRangeTree *self)
|
gcal_range_tree_free (GcalRangeTree *self)
|
||||||
{
|
{
|
||||||
@@ -714,3 +738,23 @@ gcal_range_tree_count_entries_at_range (GcalRangeTree *self,
|
|||||||
|
|
||||||
return gather_data.counter;
|
return gather_data.counter;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* gcal_range_tree_print:
|
||||||
|
* @self: a #GcalRangeTree
|
||||||
|
*
|
||||||
|
* Prints @self. This is only useful for debugging purposes. There
|
||||||
|
* are no guarantees about the format, except that it's human-readable.
|
||||||
|
*/
|
||||||
|
void
|
||||||
|
gcal_range_tree_print (GcalRangeTree *self)
|
||||||
|
{
|
||||||
|
g_autoptr (GString) string = NULL;
|
||||||
|
|
||||||
|
g_return_if_fail (self);
|
||||||
|
|
||||||
|
string = g_string_new ("");
|
||||||
|
recursively_print_node_to_string (self->root, string, 0);
|
||||||
|
|
||||||
|
g_print ("%s", string->str);
|
||||||
|
}
|
||||||
|
|||||||
@@ -82,6 +82,8 @@ GPtrArray* gcal_range_tree_get_data_at_range (GcalRangeTree
|
|||||||
guint64 gcal_range_tree_count_entries_at_range (GcalRangeTree *self,
|
guint64 gcal_range_tree_count_entries_at_range (GcalRangeTree *self,
|
||||||
GcalRange *range);
|
GcalRange *range);
|
||||||
|
|
||||||
|
void gcal_range_tree_print (GcalRangeTree *self);
|
||||||
|
|
||||||
G_DEFINE_AUTOPTR_CLEANUP_FUNC (GcalRangeTree, gcal_range_tree_unref)
|
G_DEFINE_AUTOPTR_CLEANUP_FUNC (GcalRangeTree, gcal_range_tree_unref)
|
||||||
|
|
||||||
G_END_DECLS
|
G_END_DECLS
|
||||||
|
|||||||
Reference in New Issue
Block a user