trie tree 是一种公共前缀树,(和关联规则的一种算法frequent-pattern growth算法的数据结构相同),具体定义见wiki。
上面为一棵trie tree,直观上看,如这种数据结构做索引,应该不错,事实也是如此:)。
节点值为0/1的trie tree,称为bitwise trie。bitwise trie是一个二叉查找trie tree。
下面看nedtrie 的实现。
首先看一下基本用法(code segment in test.c)
//define tree node struct
typedef struct foo_s foo_t;
struct foo_s {
NEDTRIE_ENTRY(foo_s) link;
size_t key;
};
//initial tree root
typedef struct foo_tree_s foo_tree_t;
NEDTRIE_HEAD(foo_tree_s, foo_s);
static foo_tree_t footree;
size_t fookeyfunct(const foo_t *r)
{
return r->key;
}
NEDTRIE_GENERATE(static, foo_tree_s, foo_s, link, fookeyfunct, NEDTRIE_NOBBLEZEROS(foo_tree_s))
int main(void)
{
foo_t a, b, c