56 lines
1.9 KiB
C
56 lines
1.9 KiB
C
#ifndef INCLUDED_C_TRIESET_H
|
|
#define INCLUDED_C_TRIESET_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
|
|
|
|
typedef struct c_TrieSetNode {
|
|
bool is_key; // 标志位:true 代表从根到此节点的路径构成集合内一个有效的唯一元素
|
|
struct c_TrieSetNode* next[C_TRIE_R]; // 密集平铺的 256 路子节点二级指针控制控制总线
|
|
} c_TrieSetNode;
|
|
|
|
typedef struct {
|
|
c_TrieSetNode* root; // 集合树的根节点指针
|
|
c_size_t size; // 当前集合内有效驻留的唯一元素总个数
|
|
c_Allocator_t allocator; // 内联组合分配器实例与自适应 Fallback 缺省机制
|
|
} c_TrieSet_t;
|
|
|
|
/* ------------------------------------------------------------------------------------------------------------------ */
|
|
/* */
|
|
|
|
c_err_t c_TrieSet_Init(c_TrieSet_t* self, c_Allocator_t* allocator);
|
|
|
|
c_err_t c_TrieSet_Add(c_TrieSet_t* self, const char* key);
|
|
|
|
bool c_TrieSet_Contains(const c_TrieSet_t* self, const char* key);
|
|
|
|
c_err_t c_TrieSet_Remove(c_TrieSet_t* self, const char* key);
|
|
|
|
void c_TrieSet_Destroy(c_TrieSet_t* self);
|
|
|
|
C_STATIC_FORCE_INLINE
|
|
bool c_TrieSet_IsEmpty(const c_TrieSet_t* self) {
|
|
if (!self) return true;
|
|
return self->size==0;
|
|
}
|
|
|
|
c_err_t c_TrieSet_KeysWithPrefix(c_TrieSet_t* self, const char* prefix, c_StringList_t* results);
|
|
c_err_t c_TrieSet_KeysThatMatch(c_TrieSet_t* self, const char* pattern, c_StringList_t* results);
|
|
c_err_t c_TrieSet_LongestPrefixOf(c_TrieSet_t* self, const char* query, c_StringList_t* results);
|
|
|
|
#endif /*INCLUDED_C_TRIESET_H*/
|