summaryrefslogtreecommitdiff
path: root/epan/wmem/wmem_tree.c
diff options
context:
space:
mode:
authorMichael Mann <mmann78@netscape.net>2017-02-07 16:52:42 -0500
committerMichael Mann <mmann78@netscape.net>2017-03-04 21:53:25 +0000
commit9b4f325132091c053131b352df914f378286809a (patch)
tree4b2418f6d53694cbcf8262ac3c6363f8cffc5928 /epan/wmem/wmem_tree.c
parent3cc1d1cf5aa6a5c05aa5d03b5e4c9fd844ced5a2 (diff)
downloadwireshark-9b4f325132091c053131b352df914f378286809a.tar.gz
Add wmem_tree_count.
There are cases where wmem_tree needs to know its number of nodes. Change-Id: I6411cf4275fd4d85a1d76382e1922d236be3b176 Reviewed-on: https://code.wireshark.org/review/20005 Petri-Dish: Michael Mann <mmann78@netscape.net> Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org> Reviewed-by: Michael Mann <mmann78@netscape.net>
Diffstat (limited to 'epan/wmem/wmem_tree.c')
-rw-r--r--epan/wmem/wmem_tree.c21
1 files changed, 21 insertions, 0 deletions
diff --git a/epan/wmem/wmem_tree.c b/epan/wmem/wmem_tree.c
index c5ef912f03..9a76c02982 100644
--- a/epan/wmem/wmem_tree.c
+++ b/epan/wmem/wmem_tree.c
@@ -271,6 +271,27 @@ wmem_tree_is_empty(wmem_tree_t *tree)
return tree->root == NULL;
}
+static gboolean
+count_nodes(const void *key _U_, void *value _U_, void *userdata)
+{
+ guint* count = (guint*)userdata;
+ (*count)++;
+ return FALSE;
+}
+
+guint
+wmem_tree_count(wmem_tree_t* tree)
+{
+ guint count = 0;
+
+ /* Recursing through the tree counting each node is the simplest approach.
+ We don't keep track of the count within the tree because it can get
+ complicated with subtrees within the tree */
+ wmem_tree_foreach(tree, count_nodes, &count);
+
+ return count;
+}
+
static wmem_tree_node_t *
create_node(wmem_allocator_t *allocator, wmem_tree_node_t *parent, const void *key,
void *data, wmem_node_color_t color, gboolean is_subtree)