#ifndef INCLUDED_C_REDBLACKBST_H #define INCLUDED_C_REDBLACKBST_H #ifndef INCLUDED_C_SORTCOMPARE_H #include #endif /*INCLUDED_C_SORTCOMPARE_H*/ #ifndef INCLUDED_C_ALLOCATOR_H #include #endif /*INCLUDED_C_ALLOCATOR_H*/ /* ------------------------------------------------------------------------------------------------------------------ */ /* */ #define C_RB_RED true #define C_RB_BLACK false typedef struct c_RBBSTNode_t { void* key; // 独立分配存储的 Key 物理地址 void* val; // 独立分配存储的 Value 物理地址 struct c_RBBSTNode_t* left; // 左子节点指针 struct c_RBBSTNode_t* right; // 右子节点指针 bool color; // 指向该节点的父链接颜色 (R 为红链接,B 为黑链接) } c_RBBSTNode_t; typedef struct { c_RBBSTNode_t* root; // 树根节点指针 c_size_t size; // 当前有效键值对总个数 c_size_t key_size; // 键对象占用的物理字节大小 (sizeof) c_size_t val_size; // 值对象占用的物理字节大小 (sizeof) c_SortCompare_t cmp; // 键专用的动态回调比对器 void* args; // 自定义上下文参数指针 c_Allocator_t allocator; // 内联组合分配器实例与默认 Fallback 缺省机制 } c_RedBlackBST_t; /* ------------------------------------------------------------------------------------------------------------------ */ /* */ c_err_t c_RedBlackBST_Init(c_RedBlackBST_t* self, c_size_t key_size, c_size_t val_size, c_SortCompare_t cmp, void* args, c_Allocator_t* allocator); c_err_t c_RedBlackBST_Put(c_RedBlackBST_t* self, const void* key, const void* val); c_err_t c_RedBlackBST_Get(const c_RedBlackBST_t* self, const void* key, void* out_val); bool c_RedBlackBST_Contains(const c_RedBlackBST_t* self, const void* key); c_err_t c_RedBlackBST_Delete(c_RedBlackBST_t* self, const void* key); void c_RedBlackBST_Destroy(c_RedBlackBST_t* self); #endif /*INCLUDED_C_REDBLACKBST_H*/