diff options
author | Joe Thornber <ejt@redhat.com> | 2018-05-29 11:03:10 +0100 |
---|---|---|
committer | Joe Thornber <ejt@redhat.com> | 2018-05-29 11:03:10 +0100 |
commit | 033df741e2e771b3abda3e190ed9c359d579ce4a (patch) | |
tree | b9d0f295c44755894bdae31dfa93008d2a62a034 /base/data-struct | |
parent | 28c8e95d197bf512a39b561281162ff4d93a598e (diff) | |
download | lvm2-033df741e2e771b3abda3e190ed9c359d579ce4a.tar.gz |
data-struct/radix-tree: pass the value dtr into create.
Rather than having to pass it into every method that removes items.
Diffstat (limited to 'base/data-struct')
-rw-r--r-- | base/data-struct/radix-tree.c | 10 | ||||
-rw-r--r-- | base/data-struct/radix-tree.h | 7 |
2 files changed, 10 insertions, 7 deletions
diff --git a/base/data-struct/radix-tree.c b/base/data-struct/radix-tree.c index b4b6791dd..c50bd43f8 100644 --- a/base/data-struct/radix-tree.c +++ b/base/data-struct/radix-tree.c @@ -74,17 +74,21 @@ struct node256 { struct radix_tree { unsigned nr_entries; struct value root; + radix_value_dtr dtr; + void *dtr_context; }; //---------------------------------------------------------------- -struct radix_tree *radix_tree_create(void) +struct radix_tree *radix_tree_create(radix_value_dtr dtr, void *dtr_context) { struct radix_tree *rt = malloc(sizeof(*rt)); if (rt) { rt->nr_entries = 0; rt->root.type = UNSET; + rt->dtr = dtr; + rt->dtr_context = dtr_context; } return rt; @@ -153,9 +157,9 @@ static void _free_node(struct value v, radix_value_dtr dtr, void *context) } } -void radix_tree_destroy(struct radix_tree *rt, radix_value_dtr dtr, void *context) +void radix_tree_destroy(struct radix_tree *rt) { - _free_node(rt->root, dtr, context); + _free_node(rt->root, rt->dtr, rt->dtr_context); free(rt); } diff --git a/base/data-struct/radix-tree.h b/base/data-struct/radix-tree.h index d84e3c54e..13ab4cde9 100644 --- a/base/data-struct/radix-tree.h +++ b/base/data-struct/radix-tree.h @@ -25,12 +25,11 @@ union radix_value { uint64_t n; }; -struct radix_tree *radix_tree_create(void); - typedef void (*radix_value_dtr)(void *context, union radix_value v); -// dtr may be NULL -void radix_tree_destroy(struct radix_tree *rt, radix_value_dtr dtr, void *context); +// dtr will be called on any deleted entries. dtr may be NULL. +struct radix_tree *radix_tree_create(radix_value_dtr dtr, void *dtr_context); +void radix_tree_destroy(struct radix_tree *rt); unsigned radix_tree_size(struct radix_tree *rt); bool radix_tree_insert(struct radix_tree *rt, uint8_t *kb, uint8_t *ke, union radix_value v); |