* Allocate an empty id tree. You can free it with talloc_free().
*
* Example:
- * #include <err.h>
- *
* static struct idtree *ids;
*
- * ...
+ * static void init(void)
+ * {
* ids = idtree_new(NULL);
* if (!ids)
* err(1, "Failed to allocate idtree");
+ * }
*/
struct idtree *idtree_new(void *mem_ctx);
* Example:
* struct foo {
* unsigned int id;
- * ...
+ * // ...
* };
*
* // Create a new foo, assigning an id.
- * struct foo *new_foo(void)
+ * static struct foo *new_foo(void)
* {
* int id;
- * foo = malloc(sizeof(*foo));
+ * struct foo *foo = malloc(sizeof(*foo));
* if (!foo)
* return NULL;
*
*
* Example:
* static int last_id = -1;
- * struct foo {
- * unsigned int id;
- * ...
- * };
*
* // Create a new foo, assigning a consecutive id.
* // This maximizes the time before ids roll.
- * struct foo *new_foo(void)
+ * static struct foo *new_foo_inc_id(void)
* {
* int id;
- * foo = malloc(sizeof(*foo));
+ * struct foo *foo = malloc(sizeof(*foo));
* if (!foo)
* return NULL;
*
*
* Example:
* // Look up a foo for a given ID.
- * struct foo *find_foo(unsigned int id)
+ * static struct foo *find_foo(unsigned int id)
* {
* return idtree_lookup(ids, id);
* }
* Returns false if the id was not in the tree.
*
* Example:
- * #include <assert.h>
- *
* // Look up a foo for a given ID.
- * void *free_foo(struct foo *foo)
+ * static void free_foo(struct foo *foo)
* {
* bool exists = idtree_remove(ids, foo->id);
* assert(exists);