diff options
author | Mattias Andrée <maandree@operamail.com> | 2014-11-09 02:40:16 +0100 |
---|---|---|
committer | Mattias Andrée <maandree@operamail.com> | 2014-11-09 02:40:16 +0100 |
commit | 6b4d77e566197d464e3501cc8919637ac4192b66 (patch) | |
tree | 55dc842126abf97ec5f45bdae2a70c9498b72ce9 /src/mds-kbdc | |
parent | mds-kbdc: tree: m fixes + destroy and free functions (diff) | |
download | mds-6b4d77e566197d464e3501cc8919637ac4192b66.tar.gz mds-6b4d77e566197d464e3501cc8919637ac4192b66.tar.bz2 mds-6b4d77e566197d464e3501cc8919637ac4192b66.tar.xz |
add initialise and create for the tree structure
Signed-off-by: Mattias Andrée <maandree@operamail.com>
Diffstat (limited to '')
-rw-r--r-- | src/mds-kbdc/tree.c | 32 | ||||
-rw-r--r-- | src/mds-kbdc/tree.h | 16 |
2 files changed, 47 insertions, 1 deletions
diff --git a/src/mds-kbdc/tree.c b/src/mds-kbdc/tree.c index 45d2ca0..600bf2a 100644 --- a/src/mds-kbdc/tree.c +++ b/src/mds-kbdc/tree.c @@ -18,6 +18,37 @@ #include "tree.h" #include <stdlib.h> +#include <string.h> + + + +/** + * Initialise a tree node + * + * @param this The memory slot for the tree node + * @param type The type of the node + */ +void mds_kbdc_tree_initialise(mds_kbdc_tree_t* restrict this, int type) +{ + memset(this, 0, sizeof(mds_kbdc_tree_t)); + this->type = type; +} + + +/** + * Create a tree node + * + * @param type The type of the node + * @return The tree node, `NULL` on error + */ +mds_kbdc_tree_t* mds_kbdc_tree_create(int type) +{ + mds_kbdc_tree_t* this = malloc(sizeof(mds_kbdc_tree_t)); + if (this == NULL) + return NULL; + mds_kbdc_tree_initialise(this, type); + return this; +} /** @@ -127,7 +158,6 @@ static void mds_kbdc_tree_destroy_(mds_kbdc_tree_t* restrict this, int recursive } - /** * Release all resources stored in a tree node, * without freeing the node itself or freeing diff --git a/src/mds-kbdc/tree.h b/src/mds-kbdc/tree.h index ac6ba7e..13a79cb 100644 --- a/src/mds-kbdc/tree.h +++ b/src/mds-kbdc/tree.h @@ -646,6 +646,22 @@ union mds_kbdc_tree /** + * Initialise a tree node + * + * @param this The memory slot for the tree node + * @param type The type of the node + */ +void mds_kbdc_tree_initialise(mds_kbdc_tree_t* restrict this, int type); + +/** + * Create a tree node + * + * @param type The type of the node + * @return The tree node, `NULL` on error + */ +mds_kbdc_tree_t* mds_kbdc_tree_create(int type); + +/** * Release all resources stored in a tree node, * without freeing the node itself or freeing * or destroying inner `mds_kbdc_tree_t*`:s |