libvieter/src/tree/vieter_tree_node.h

48 lines
1.6 KiB
C
Raw Normal View History

#ifndef VIETER_TREE_NODE
#define VIETER_TREE_NODE
2023-01-19 21:22:08 +01:00
#include "vieter_tree.h"
2023-01-19 21:22:08 +01:00
#include <stdint.h>
2023-01-20 12:08:05 +01:00
#include <stdbool.h>
2023-01-29 17:32:27 +01:00
typedef enum vieter_tree_node_flag {
vieter_tree_node_black = ((uint8_t)1) << 0
} vieter_tree_node_flag;
2023-01-19 21:22:08 +01:00
typedef struct vieter_tree_node {
uint64_t key;
void *data;
struct vieter_tree_node *parent;
2023-01-19 21:22:08 +01:00
struct vieter_tree_node *left;
struct vieter_tree_node *right;
2023-01-20 12:08:05 +01:00
uint8_t flags;
2023-01-19 21:22:08 +01:00
} vieter_tree_node;
vieter_tree_node *vieter_tree_node_init();
2023-01-20 11:07:33 +01:00
void vieter_tree_node_free(vieter_tree_node *node);
vieter_tree_error vieter_tree_node_insert(vieter_tree_node *root, uint64_t key, void *data);
2023-01-29 17:32:27 +01:00
/*
* Return the node representing the requested value.
*/
vieter_tree_error vieter_tree_node_search_node(vieter_tree_node **out, vieter_tree_node *root, uint64_t key);
2023-01-29 17:32:27 +01:00
vieter_tree_error vieter_tree_node_search(void **out, vieter_tree_node *root, uint64_t key);
vieter_tree_error vieter_tree_node_remove(void **out, vieter_tree_node *root, uint64_t key);
2023-01-29 17:32:27 +01:00
void vieter_tree_node_replace_with_child(vieter_tree_node *to_replace, vieter_tree_node *replacement);
2023-01-29 17:32:27 +01:00
void vieter_tree_node_set(vieter_tree_node *node, vieter_tree_node_flag flag);
void vieter_tree_node_unset(vieter_tree_node *node, vieter_tree_node_flag flag);
bool vieter_tree_node_get(vieter_tree_node *node, vieter_tree_node_flag flag);
2023-01-20 12:08:05 +01:00
void vieter_tree_node_add_child(vieter_tree_node *parent, uint64_t key,
vieter_tree_node *child);
2023-01-29 17:32:27 +01:00
bool vieter_tree_node_validate(vieter_tree_node *node, uint64_t passed_black_nodes, uint64_t expected_black_nodes);
2023-01-19 21:22:08 +01:00
#endif