naspro

view naspro-core/include/NASPRO/core/avl.h @ 173:71372f617827

Totally CMakeized, a bit of doc
author Stefano D'Angelo <zanga.mail@gmail.com>
date Fri Mar 26 18:54:24 2010 +0200 (2010-03-26)
parents c7f1f52651be
children 4f7243a606b1
line source
1 /*
2 * NASPRO - NASPRO Architecture for Sound Processing
3 * Core library
4 *
5 * Copyright (C) 2007-2010 Stefano D'Angelo <zanga.mail@gmail.com>
6 *
7 * See the COPYING file for license conditions.
8 */
10 #ifndef _NACORE_AVL_H
11 #define _NACORE_AVL_H
13 #include <stdlib.h>
15 #ifdef __cplusplus
16 extern "C" {
17 #endif
19 /* WARNING: this API is not thread-safe */
21 /* AVL tree handle */
22 typedef struct _nacore_avl_tree * nacore_avl_tree_t;
24 /*
25 * Creates a new AVL tree, returns NULL in case of faliure.
26 *
27 * content_cmp is a pointer to a function which compares the content of two
28 * nodes (strcmp()-like)
29 * key_cmp is a pointer to a function which compares the content of a node with
30 a key value (strcmp()-like)
31 */
32 nacore_avl_tree_t nacore_avl_tree_new(int (*content_cmp)(void *c1, void *c2),
33 int (*key_cmp)(void *content, void *key));
35 /*
36 * Adds a node to the tree and balances it, in case of failure the node is
37 * simply not added.
38 *
39 * tree is the AVL tree handle
40 * content is the node content
41 */
42 void nacore_avl_tree_add(nacore_avl_tree_t tree, void *content);
44 /*
45 * Calls a callback function for each node of the tree (the order of such calls
46 * is not defined)
47 *
48 * tree is the AVL tree handle
49 * callback is the callback function
50 * data is the data pointer which gets passed to the callback
51 */
52 void nacore_avl_tree_for_each(nacore_avl_tree_t tree,
53 void (*callback)(void *content, void *data),
54 void *data);
56 /*
57 * Finds a node in the tree by comparing node contents with a key, in case none
58 * is found NULL is returned.
59 *
60 * tree is the AVL tree handle
61 * key is the key value to look for
62 */
63 void *nacore_avl_tree_find(nacore_avl_tree_t tree, void *key);
65 /*
66 * Returns the number of nodes in a tree
67 *
68 * tree is the AVL tree handle
69 */
70 size_t nacore_avl_tree_get_nodes_count(nacore_avl_tree_t tree);
72 /*
73 * Destroys a tree (frees the tree structure only, not nodes' content)
74 *
75 * tree is the AVL tree handle
76 */
77 void nacore_avl_tree_free(nacore_avl_tree_t tree);
79 /*
80 * Convenience function for comparing nodes in trees of NASPRO core plugin
81 * descriptors where the URI is the ordering field.
82 *
83 * c1 and c2 are plugin descriptors
84 */
85 int nacore_content_cmp_descriptor_by_uri(void *c1, void *c2);
87 /*
88 * Convenience function for comparing a node's content with a key value where
89 * nodes are NASPRO core plugin descriptors and the key is a URI.
90 *
91 * content is a plugin descriptor
92 * data is the URI string
93 */
94 int nacore_key_cmp_descriptor_by_uri(void *content, void *data);
96 #ifdef __cplusplus
97 }
98 #endif
100 #endif /* !_NACORE_AVL_H */