#ifndef INCLUDED_C_BST_H #define INCLUDED_C_BST_H #ifndef INCLUDED_C_SORTCOMPARE_H #include #endif /*INCLUDED_C_SORTCOMPARE_H*/ #ifndef INCLUDED_C_ALLOCATOR_H #include #endif /*INCLUDED_C_ALLOCATOR_H*/ /* ------------------------------------------------------------------------------------------------------------------ */ /* */ typedef struct c_BSTNode { void* key; // 独立分配存储的 Key 物理地址 void* val; // 独立分配存储的 Value 物理地址 struct c_BSTNode* left; // 左子节点指针 (指向更小键的子树) struct c_BSTNode* right; // 右子节点指针 (指向更大键的子树) } c_BSTNode; /** * @brief 工业级泛型二叉搜索树结构体(分配器内联组合版) */ typedef struct { c_BSTNode* 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_BST_t; /* ------------------------------------------------------------------------------------------------------------------ */ /* */ c_err_t c_BST_Init(c_BST_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_BST_Get(const c_BST_t* self, const void* key, void* out_val); bool c_BST_Contains(const c_BST_t* self, const void* key); c_err_t c_BST_Put(c_BST_t* self, const void* key, const void* val) ; c_err_t c_BST_Delete(c_BST_t* self, const void* key); void c_BST_Destroy(c_BST_t* self); #endif /*INCLUDED_C_BST_H*/