Files
xiuos/Ubiquitous/XiZi_AIoT/softkernel/include/rbtree.h
2024-10-31 23:33:58 +08:00

40 lines
749 B
C

#pragma once
#include <stddef.h>
#include <stdint.h>
#include "actracer.h"
// CLRS
// Insertion and Deletion in a Red Black Tree
enum rbt_type {
RED,
BLACK
};
typedef struct RbtNode {
uintptr_t key;
void* data;
struct RbtNode* left;
struct RbtNode* right;
struct RbtNode* parent;
enum rbt_type color;
} RbtNode;
typedef struct RbtTree {
RbtNode* root;
int nr_ele;
} RbtTree;
void rbtree_init(RbtTree* tree);
int rbt_insert(RbtTree* tree, uintptr_t key, void* data);
RbtNode* rbt_search(RbtTree* tree, uintptr_t key);
int rbt_delete(RbtTree* tree, uintptr_t key);
void module_rbt_factory_init(TraceTag* _softkernel_tag);
static inline bool rbt_is_empty(RbtTree* tree)
{
return tree->nr_ele == 0;
}