Search / Sort
This commit is contained in:
@@ -0,0 +1,55 @@
|
||||
#ifndef INCLUDED_C_RBTREESET_H
|
||||
#define INCLUDED_C_RBTREESET_H
|
||||
|
||||
#ifndef INCLUDED_C_SORTCOMPARE_H
|
||||
#include <c_SortCompare.h>
|
||||
#endif /*INCLUDED_C_SORTCOMPARE_H*/
|
||||
|
||||
|
||||
#ifndef INCLUDED_C_ALLOCATOR_H
|
||||
#include <c_Allocator.h>
|
||||
#endif /*INCLUDED_C_ALLOCATOR_H*/
|
||||
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------------------------ */
|
||||
/* */
|
||||
|
||||
#define C_RB_RED true
|
||||
#define C_RB_BLACK false
|
||||
|
||||
/**
|
||||
* @brief 红黑树集合内部单节点物理封装
|
||||
*/
|
||||
typedef struct c_RBSetNode_t {
|
||||
void* key; // 独立分配存储的元素键物理地址
|
||||
struct c_RBSetNode_t* left; // 左子节点指针
|
||||
struct c_RBSetNode_t* right; // 右子节点指针
|
||||
bool color; // 指向该节点的父链接颜色 (R为红,B为黑)
|
||||
} c_RBSetNode_t;
|
||||
|
||||
/**
|
||||
* @brief 工业级泛型红黑树集合结构体(分配器内联组合版)
|
||||
*/
|
||||
typedef struct {
|
||||
c_RBSetNode_t* root; // 集合树根节点指针
|
||||
c_size_t size; // 当前集合内有效驻留的唯一元素总个数
|
||||
c_size_t key_size; // 元素键占用的物理字节大小 (sizeof)
|
||||
c_SortCompare_t cmp; // 元素专用动态回调比对器
|
||||
void* args; // 自定义上下文参数指针
|
||||
c_Allocator_t allocator; // 内联组合分配器实例与自适应 Fallback 缺省
|
||||
} c_RBTreeSet_t;
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------------------------ */
|
||||
/* */
|
||||
|
||||
c_err_t c_RBTreeSet_Init(c_RBTreeSet_t* self, c_size_t key_size, c_SortCompare_t cmp, void* args, c_Allocator_t* allocator);
|
||||
|
||||
c_err_t c_RBTreeSet_Add(c_RBTreeSet_t* self, const void* key);
|
||||
|
||||
bool c_RBTreeSet_Contains(const c_RBTreeSet_t* self, const void* key);
|
||||
|
||||
c_err_t c_RBTreeSet_Remove(c_RBTreeSet_t* self, const void* key);
|
||||
|
||||
void c_RBTreeSet_Destroy(c_RBTreeSet_t* self);
|
||||
|
||||
#endif /*INCLUDED_C_RBTREESET_H*/
|
||||
Reference in New Issue
Block a user