mirror of
https://github.com/radareorg/radare2.git
synced 2024-11-24 05:40:10 +00:00
Implement r_rbtree_cont_last ##util
This commit is contained in:
parent
93b4f34b84
commit
a3e3b5af7c
@ -114,6 +114,7 @@ R_API RContRBNode *r_rbtree_cont_find_node(RContRBTree *tree, void *data, RContR
|
||||
R_API RContRBNode *r_rbtree_cont_node_next(RContRBNode *node);
|
||||
R_API void *r_rbtree_cont_find(RContRBTree *tree, void *data, RContRBCmp cmp, void *user);
|
||||
R_API void *r_rbtree_cont_first(RContRBTree *tree);
|
||||
R_API void *r_rbtree_cont_last(RContRBTree *tree);
|
||||
|
||||
#define r_rbtree_cont_foreach(tree, it, dat) \
|
||||
for ((it) = r_rbtree_first ((tree)->root ? &(tree)->root->node : NULL); r_rbtree_iter_has(&it) && (dat = r_rbtree_iter_get (&it, RContRBNode, node)->data); r_rbtree_iter_next (&(it)))
|
||||
|
@ -557,6 +557,21 @@ R_API void *r_rbtree_cont_first(RContRBTree *tree) {
|
||||
return (container_of (first_rbnode, RContRBNode, node))->data;
|
||||
}
|
||||
|
||||
R_API void *r_rbtree_cont_last(RContRBTree *tree) {
|
||||
r_return_val_if_fail (tree, NULL);
|
||||
if (!tree->root) {
|
||||
// empty tree
|
||||
return NULL;
|
||||
}
|
||||
RBIter iter = r_rbtree_last (&tree->root->node);
|
||||
if (iter.len == 0) {
|
||||
// also empty tree
|
||||
return NULL;
|
||||
}
|
||||
RBNode *last_rbnode = iter.path[iter.len-1];
|
||||
return (container_of (last_rbnode, RContRBNode, node))->data;
|
||||
}
|
||||
|
||||
R_API void r_rbtree_cont_free(RContRBTree *tree) {
|
||||
if (tree && tree->root) {
|
||||
r_rbtree_free (&tree->root->node, cont_node_free, tree->free);
|
||||
|
Loading…
Reference in New Issue
Block a user