feat(tree): add node bit flags support

pull/5/head
Jef Roosens 2023-01-20 12:08:05 +01:00 committed by Chewing_Bever
parent 910d7bc3bb
commit 41bc6516fa
Signed by: Jef Roosens
GPG Key ID: B75D4F293C7052DB
4 changed files with 35 additions and 0 deletions

View File

@ -0,0 +1,3 @@
#include "balancing.h"
void vieter_tree_node_balance_after_insert(vieter_tree_node *node) {}

View File

@ -0,0 +1,8 @@
#ifndef VIETER_TREE_BALANCING
#define VIETER_TREE_BALANCING
#include "node.h"
void vieter_tree_node_balance_after_insert(vieter_tree_node *node);
#endif

View File

@ -158,3 +158,15 @@ vieter_tree_error vieter_tree_node_remove(void **out, vieter_tree_node *root,
return vieter_tree_ok;
}
void vieter_tree_node_set(vieter_tree_node *node, vieter_node_flag flag) {
node->flags |= flag;
}
void vieter_tree_node_unset(vieter_tree_node *node, vieter_node_flag flag) {
node->flags &= ~flag;
}
bool vieter_tree_node_get(vieter_tree_node *node, vieter_node_flag flag) {
return (node->flags & flag) != 0;
}

View File

@ -3,6 +3,13 @@
#include "vieter_tree.h"
#include <stdint.h>
#include <stdbool.h>
#define VIETER_NODE_BLACK ((uint8_t)1)
typedef enum vieter_node_flag {
vieter_node_black = ((uint8_t)1) << 0
} vieter_node_flag;
typedef struct vieter_tree_node {
uint64_t key;
@ -10,6 +17,7 @@ typedef struct vieter_tree_node {
struct vieter_tree_node *parent;
struct vieter_tree_node *left;
struct vieter_tree_node *right;
uint8_t flags;
} vieter_tree_node;
vieter_tree_node *vieter_tree_node_init();
@ -25,4 +33,8 @@ vieter_tree_error vieter_tree_node_remove(void **out, vieter_tree_node *root, ui
void vieter_tree_node_replace(vieter_tree_node *to_replace, vieter_tree_node *replacement);
void vieter_tree_node_set(vieter_tree_node *node, vieter_node_flag flag);
void vieter_tree_node_unset(vieter_tree_node *node, vieter_node_flag flag);
bool vieter_tree_node_get(vieter_tree_node *node, vieter_node_flag flag);
#endif