String
This commit is contained in:
@@ -0,0 +1,61 @@
|
||||
#ifndef INCLUDED_C_TRIEST_H
|
||||
#define INCLUDED_C_TRIEST_H
|
||||
|
||||
#ifndef INCLUDED_C_TYPES_H
|
||||
#include <c_Types.h>
|
||||
#endif /*INCLUDED_C_TYPES_H*/
|
||||
|
||||
#ifndef INCLUDED_C_ALLOCATOR_H
|
||||
#include <c_Allocator.h>
|
||||
#endif /*INCLUDED_C_ALLOCATOR_H*/
|
||||
|
||||
#ifndef INCLUDED_C_STRINGLIST_H
|
||||
#include <c_StringList.h>
|
||||
#endif /*INCLUDED_C_STRINGLIST_H*/
|
||||
|
||||
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------------------------ */
|
||||
/* */
|
||||
|
||||
#define C_TRIE_R 256
|
||||
|
||||
/**
|
||||
* @brief Trie 树内部多路物理节点封装
|
||||
*/
|
||||
typedef struct c_TrieNode {
|
||||
void* val; // 指向用户多态 Value 的物理堆地址 (若为 NULL 代表该前缀路径非完整键)
|
||||
struct c_TrieNode* next[C_TRIE_R]; // 密集平铺的 256 路子节点二级指针控制控制总线
|
||||
} c_TrieNode;
|
||||
|
||||
typedef struct {
|
||||
c_TrieNode* root; // 查找树的根节点指针
|
||||
c_size_t size; // 当前符号表内有效驻留的完整键值对总个数
|
||||
void* (*val_cp)(const void* data, void* arg); // 值高级多态深拷贝虚函数
|
||||
void (*val_free)(void* data, void* arg); // 值高级多态解构自毁灭虚函数
|
||||
void* val_arg; // 多态虚函数伴生上下文参数
|
||||
c_Allocator_t allocator; // 内联组合分配器实例与自适应 Fallback 缺省机制
|
||||
} c_TrieST_t;
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------------------------ */
|
||||
/* */
|
||||
|
||||
c_err_t c_TrieST_Init(c_TrieST_t* self,
|
||||
void* (*val_cp)(const void*, void*),
|
||||
void (*val_free)(void*, void*), void* val_arg,
|
||||
c_Allocator_t* allocator);
|
||||
void c_TrieST_Destroy(c_TrieST_t* self);
|
||||
|
||||
c_err_t c_TrieST_Put(c_TrieST_t* self, const char* key, const void* val);
|
||||
|
||||
void* c_TrieST_Get(const c_TrieST_t* self, const char* key);
|
||||
|
||||
bool c_TrieST_Contains(const c_TrieST_t* self, const char* key);
|
||||
|
||||
c_err_t c_TrieST_Delete(c_TrieST_t* self, const char* key);
|
||||
|
||||
c_err_t c_TrieST_KeysWithPrefix(c_TrieST_t* self, const char* prefix, c_StringList_t* results);
|
||||
c_err_t c_TrieST_KeysThatMatch(c_TrieST_t* self, const char* pattern, c_StringList_t* results);
|
||||
c_err_t c_TrieST_LongestPrefixOf(c_TrieST_t* self, const char* query, c_StringList_t* results);
|
||||
|
||||
#endif /*INCLUDED_C_TRIEST_H*/
|
||||
Reference in New Issue
Block a user