X-Git-Url: http://git.archive.openwrt.org/?p=project%2Flibubox.git;a=blobdiff_plain;f=avl.h;h=46a396f2d6d55191d9e3117f563726c0d4ac8a23;hp=80a29b75ca5f22ed2cb820f16cde996846e79bc2;hb=a1a97eb11e89c420b84a659a88a4e72c7f04367d;hpb=63cea8dcb79be7bf2bd32b7c05ac289a473192a5 diff --git a/avl.h b/avl.h index 80a29b7..46a396f 100644 --- a/avl.h +++ b/avl.h @@ -82,7 +82,7 @@ struct avl_node { /** * pointer to key of node */ - void *key; + const void *key; /** * balance state of AVL tree (0,-1,+1) @@ -160,8 +160,6 @@ struct avl_node *EXPORT(avl_find_greaterequal)(const struct avl_tree *tree, cons struct avl_node *EXPORT(avl_find_lessequal)(const struct avl_tree *tree, const void *key); int EXPORT(avl_insert)(struct avl_tree *, struct avl_node *); void EXPORT(avl_delete)(struct avl_tree *, struct avl_node *); -void *EXPORT(__avl_find_element)(const struct avl_tree *tree, const void *key, - size_t offset, enum avl_find_mode mode); /** * @param tree pointer to avl-tree @@ -193,6 +191,32 @@ avl_is_empty(struct avl_tree *tree) { } /** + * Internal function to support returning the element from a avl tree query + * @param tree pointer to avl tree + * @param key pointer to key + * @param offset offset of node inside the embedded struct + * @param mode mode of lookup operation (less equal, equal or greater equal) + * @param pointer to elemen, NULL if no fitting one was found + */ +static inline void * +__avl_find_element(const struct avl_tree *tree, const void *key, size_t offset, enum avl_find_mode mode) { + void *node = NULL; + + switch (mode) { + case AVL_FIND_EQUAL: + node = avl_find(tree, key); + break; + case AVL_FIND_LESSEQUAL: + node = avl_find_lessequal(tree, key); + break; + case AVL_FIND_GREATEREQUAL: + node = avl_find_greaterequal(tree, key); + break; + } + return node == NULL ? NULL : (((char *)node) - offset); +} + +/** * @param tree pointer to avl-tree * @param key pointer to key * @param element pointer to a node element