Mercurial > libavutil.hg
annotate tree.h @ 414:a30cad55db8b libavutil
Support removing elements.
author | michael |
---|---|
date | Fri, 04 Jan 2008 18:20:03 +0000 |
parents | a54e20281de9 |
children | dee66b77779a |
rev | line source |
---|---|
136 | 1 /* |
2 * copyright (c) 2006 Michael Niedermayer <michaelni@gmx.at> | |
3 * | |
4 * This file is part of FFmpeg. | |
5 * | |
6 * FFmpeg is free software; you can redistribute it and/or | |
7 * modify it under the terms of the GNU Lesser General Public | |
8 * License as published by the Free Software Foundation; either | |
9 * version 2.1 of the License, or (at your option) any later version. | |
10 * | |
11 * FFmpeg is distributed in the hope that it will be useful, | |
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
14 * Lesser General Public License for more details. | |
15 * | |
16 * You should have received a copy of the GNU Lesser General Public | |
17 * License along with FFmpeg; if not, write to the Free Software | |
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | |
19 */ | |
20 | |
261
2ed59b450840
Add Doxygen author and file description, rephrase a Doxygen comment.
diego
parents:
259
diff
changeset
|
21 /** |
2ed59b450840
Add Doxygen author and file description, rephrase a Doxygen comment.
diego
parents:
259
diff
changeset
|
22 * @file tree.h |
2ed59b450840
Add Doxygen author and file description, rephrase a Doxygen comment.
diego
parents:
259
diff
changeset
|
23 * A tree container. |
2ed59b450840
Add Doxygen author and file description, rephrase a Doxygen comment.
diego
parents:
259
diff
changeset
|
24 * @author Michael Niedermayer <michaelni@gmx.at> |
2ed59b450840
Add Doxygen author and file description, rephrase a Doxygen comment.
diego
parents:
259
diff
changeset
|
25 */ |
2ed59b450840
Add Doxygen author and file description, rephrase a Doxygen comment.
diego
parents:
259
diff
changeset
|
26 |
392 | 27 #ifndef FFMPEG_TREE_H |
28 #define FFMPEG_TREE_H | |
136 | 29 |
30 struct AVTreeNode; | |
413
a54e20281de9
Move *malloc() out of tree.c, that way the code can be used with
michael
parents:
392
diff
changeset
|
31 extern const int av_tree_node_size; |
150 | 32 |
33 /** | |
34 * Finds an element. | |
35 * @param root a pointer to the root node of the tree | |
259 | 36 * @param next If next is not NULL then next[0] will contain the previous |
37 * element and next[1] the next element if either does not exist | |
38 * then the corresponding entry in next is unchanged. | |
39 * @return An element with cmp(key, elem)==0 or NULL if no such element exists in | |
40 * the tree. | |
150 | 41 */ |
42 void *av_tree_find(const struct AVTreeNode *root, void *key, int (*cmp)(void *key, const void *b), void *next[2]); | |
43 | |
44 /** | |
45 * Finds a element for which cmp(key, elem)==0, if no such element is found key | |
46 * is inserted into the tree. | |
259 | 47 * @param rootp A pointer to a pointer to the root node of the tree. Note that |
48 * the root node can change during insertions, this is required | |
49 * to keep the tree balanced. | |
413
a54e20281de9
Move *malloc() out of tree.c, that way the code can be used with
michael
parents:
392
diff
changeset
|
50 * @param next AVTreeNode used for the inserted element, must be allocated and |
a54e20281de9
Move *malloc() out of tree.c, that way the code can be used with
michael
parents:
392
diff
changeset
|
51 * zeroed by the user. And will be set to NULL if used by |
a54e20281de9
Move *malloc() out of tree.c, that way the code can be used with
michael
parents:
392
diff
changeset
|
52 * av_tree_insert(). This allows the use of flat arrays, which have |
a54e20281de9
Move *malloc() out of tree.c, that way the code can be used with
michael
parents:
392
diff
changeset
|
53 * lower overhead compared to many malloced elements. |
a54e20281de9
Move *malloc() out of tree.c, that way the code can be used with
michael
parents:
392
diff
changeset
|
54 * You might want to define a function like: |
a54e20281de9
Move *malloc() out of tree.c, that way the code can be used with
michael
parents:
392
diff
changeset
|
55 * void *tree_insert(struct AVTreeNode **rootp, void *key, int (*cmp)(void *key, const void *b), AVTreeNode **next){ |
a54e20281de9
Move *malloc() out of tree.c, that way the code can be used with
michael
parents:
392
diff
changeset
|
56 * if(!*next) *next= av_mallocz(av_tree_node_size); |
a54e20281de9
Move *malloc() out of tree.c, that way the code can be used with
michael
parents:
392
diff
changeset
|
57 * return av_tree_insert(rootp, key, cmp, next); |
a54e20281de9
Move *malloc() out of tree.c, that way the code can be used with
michael
parents:
392
diff
changeset
|
58 * } |
150 | 59 * |
259 | 60 * @return If no insertion happened, the found element. |
261
2ed59b450840
Add Doxygen author and file description, rephrase a Doxygen comment.
diego
parents:
259
diff
changeset
|
61 * If an insertion happened, then either key or NULL will be returned. |
2ed59b450840
Add Doxygen author and file description, rephrase a Doxygen comment.
diego
parents:
259
diff
changeset
|
62 * Which one it is depends on the tree state and the implementation. You |
2ed59b450840
Add Doxygen author and file description, rephrase a Doxygen comment.
diego
parents:
259
diff
changeset
|
63 * should make no assumptions that it's one or the other in the code. |
150 | 64 */ |
413
a54e20281de9
Move *malloc() out of tree.c, that way the code can be used with
michael
parents:
392
diff
changeset
|
65 void *av_tree_insert(struct AVTreeNode **rootp, void *key, int (*cmp)(void *key, const void *b), struct AVTreeNode **next); |
136 | 66 void av_tree_destroy(struct AVTreeNode *t); |
67 | |
392 | 68 #endif /* FFMPEG_TREE_H */ |