forked from vieter-v/libvieter
feat(tree): add node bit flags support
parent
910d7bc3bb
commit
41bc6516fa
|
@ -0,0 +1,3 @@
|
|||
#include "balancing.h"
|
||||
|
||||
void vieter_tree_node_balance_after_insert(vieter_tree_node *node) {}
|
|
@ -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
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue