Project

General

Profile

Actions

Feature #6222

open

libuutil could provide a way to re-create an AVL tree

Added by Josef Sipek almost 6 years ago. Updated almost 6 years ago.

Status:
New
Priority:
Normal
Assignee:
Category:
lib - userland libraries
Start date:
2015-09-11
Due date:
% Done:

80%

Estimated time:
Difficulty:
Medium
Tags:
needs-triage
Gerrit CR:

Description

If one wants to quickly empty out a tree, it makes sense to use avl_destroy_nodes via uu_avl_teardown. The one unfortunate side effect is that after all the nodes are freed, one must destroy & create the avl tree. See avl.h's note:

 * 3. Use avl_destroy_nodes() to quickly process/free up any remaining nodes.
 *    Note that once you use avl_destroy_nodes(), you can no longer
 *    use any routine except avl_destroy_nodes() and avl_destoy().

Since libuutil stashes the comparator, and other avl_create args in the uu_avl_pool_t structure, we can add a helper function to do the destroy/create combo and save the library users some headaches and typing:

void
uu_avl_recreate(uu_avl_t *ap)
{
       uu_avl_pool_t *pp = ap->ua_pool;

       avl_destroy(&ap->ua_tree);
       avl_create(&ap->ua_tree, &uu_avl_node_compare, pp->uap_objsize,
           pp->uap_nodeoffset);
}
Actions #1

Updated by Josef Sipek almost 6 years ago

  • Description updated (diff)
Actions

Also available in: Atom PDF