GRU tree example.
#include <inttypes.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
return root;
}
printf("Comparing %s with %s\n", (const char *) current, (const char *) data);
if (strcmp((const char *) current, (const char *) data) == 0) {
return true;
}
return false;
}
void print_path(
const void *nodedata,
void *data) {
printf("\t%s\n", (const char *) nodedata);
}
}
int main(
int argc,
char **argv) {
if (count != 11) {
fprintf(stderr, "Expected 11 nodes but got %d\n", count);
return EXIT_FAILURE;
}
if (children != 4) {
fprintf(stderr, "Expected 4 children nodes but got %d\n", children);
return EXIT_FAILURE;
}
printf("Printing childs of var\n");
printf("Done");
if (count != 6) {
fprintf(stderr, "Expected 7 nodes after removing var but got %d\n", count);
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}
int main(int argc, char **argv)
Definition: gru_list_test.c:198
#define gru_attr_unused
Definition: gru_portable.h:21
const gru_tree_node_t * gru_tree_search(gru_tree_node_t *node, compare_function_t comparable, const void *other)
Searches the tree using DFS.
Definition: gru_tree.c:78
uint32_t gru_tree_count_children(gru_tree_node_t *node)
Returns the number of children of a node.
Definition: gru_tree.c:212
gru_tree_node_t * gru_tree_new(const void *data)
Creates a new tree and returns a pointer to the root node.
Definition: gru_tree.c:18
void gru_tree_for_each_child(gru_tree_node_t *node, tree_callback_fn callback, void *payload)
Executes an operation on each child of the given node.
Definition: gru_tree.c:190
const gru_tree_node_t * gru_tree_for_each(gru_tree_node_t *node, tree_callback_fn callback, void *payload)
Traverses the tree executing a set of operations.
Definition: gru_tree.c:144
gru_tree_node_t * gru_tree_add_child(gru_tree_node_t *node, const void *data)
Adds a child node to a given node.
Definition: gru_tree.c:61
uint32_t gru_tree_count(gru_tree_node_t *node)
Returns the number of children of a tree.
Definition: gru_tree.c:230
bool gru_tree_remove_child(gru_tree_node_t *node, compare_function_t comparable, const void *other)
Removes a direct descendant of a node.
Definition: gru_tree.c:109
void gru_tree_destroy(gru_tree_node_t **ptr)
Destroys a tree node and all it's descendants.
Definition: gru_tree.c:45
bool compare_file_name(const void *current, const void *data, void *result)
Definition: gru_tree_test.c:44
void print_path2(const void *nodedata, void *data)
Definition: gru_tree_test.c:57
void print_path(const void *nodedata, void *data)
Definition: gru_tree_test.c:53
Definition: gru_tree.h:33