#include <stdint.h>
#include <stdbool.h>
Go to the source code of this file.
|
| void | ck_trie_clear (CKTrie *trie) |
| |
| CKTrie * | ck_trie_create (size_t max_nodes) |
| |
| int32_t | ck_trie_find_longest (const CKTrie *trie, const char *text, size_t text_len, size_t start_pos, size_t *match_len) |
| |
| void | ck_trie_free (CKTrie *trie) |
| |
| bool | ck_trie_has_prefix (const CKTrie *trie, const char *text, size_t text_len, size_t pos) |
| |
| int | ck_trie_insert (CKTrie *trie, const char *token, int32_t token_id, bool is_special, int32_t priority) |
| |
| size_t | ck_trie_node_count (const CKTrie *trie) |
| |
◆ ck_trie_clear()
| void ck_trie_clear |
( |
CKTrie * |
trie | ) |
|
Definition at line 80 of file trie.c.
87 size_t head = 0, tail = 0;
88 queue[tail++] = trie->
root;
92 for (
int i = 0; i < 256; i++) {
98 if (node != trie->
root) {
struct CKTrieNode * children[256]
◆ ck_trie_create()
| CKTrie* ck_trie_create |
( |
size_t |
max_nodes | ) |
|
Definition at line 29 of file trie.c.
#define DEFAULT_MAX_NODES
static CKTrieNode * create_node(void)
◆ ck_trie_find_longest()
| int32_t ck_trie_find_longest |
( |
const CKTrie * |
trie, |
|
|
const char * |
text, |
|
|
size_t |
text_len, |
|
|
size_t |
start_pos, |
|
|
size_t * |
match_len |
|
) |
| |
Definition at line 142 of file trie.c.
144 if (!trie || !
text || start_pos >=
text_len || !match_len) {
151 size_t last_token_len = 0;
152 size_t pos = start_pos;
156 unsigned char c = (
unsigned char)
text[pos];
167 last_token_node = node;
168 last_token_len = pos - start_pos;
172 *match_len = last_token_len;
174 if (last_token_node) {
◆ ck_trie_free()
| void ck_trie_free |
( |
CKTrie * |
trie | ) |
|
Definition at line 51 of file trie.c.
63 size_t head = 0, tail = 0;
64 queue[tail++] = trie->
root;
68 for (
int i = 0; i < 256; i++) {
◆ ck_trie_has_prefix()
| bool ck_trie_has_prefix |
( |
const CKTrie * |
trie, |
|
|
const char * |
text, |
|
|
size_t |
text_len, |
|
|
size_t |
pos |
|
) |
| |
Definition at line 181 of file trie.c.
187 unsigned char c = (
unsigned char)
text[pos];
◆ ck_trie_insert()
| int ck_trie_insert |
( |
CKTrie * |
trie, |
|
|
const char * |
token, |
|
|
int32_t |
token_id, |
|
|
bool |
is_special, |
|
|
int32_t |
priority |
|
) |
| |
Definition at line 110 of file trie.c.
111 if (!trie || !
token)
return -1;
114 const unsigned char *p = (
const unsigned char *)
token;
117 unsigned char c = *p++;
125 if (!new_node)
return -1;
int32_t int32_t int32_t int32_t priority
◆ ck_trie_node_count()
| size_t ck_trie_node_count |
( |
const CKTrie * |
trie | ) |
|