Mark partial words as not a word
This commit is contained in:
parent
e4726b87dd
commit
16375e2c7c
|
@ -12,6 +12,7 @@
|
|||
|
||||
struct trie {
|
||||
struct trie *children[26];
|
||||
uint8_t terminal;
|
||||
};
|
||||
|
||||
void new_trie(struct trie *tree) {
|
||||
|
@ -20,6 +21,8 @@ void new_trie(struct trie *tree) {
|
|||
for(; idx < 26; idx += 1) {
|
||||
tree->children[idx] = NULL;
|
||||
}
|
||||
|
||||
tree->terminal = 0;
|
||||
}
|
||||
|
||||
void trie_insert(struct trie *tree, const char *str, uint8_t len) {
|
||||
|
@ -43,6 +46,8 @@ void trie_insert(struct trie *tree, const char *str, uint8_t len) {
|
|||
|
||||
node = node->children[pos];
|
||||
}
|
||||
|
||||
node->terminal = 1;
|
||||
}
|
||||
|
||||
uint8_t trie_has(struct trie *tree, const char *str, uint8_t len) {
|
||||
|
@ -59,7 +64,7 @@ uint8_t trie_has(struct trie *tree, const char *str, uint8_t len) {
|
|||
node = node->children[pos];
|
||||
}
|
||||
|
||||
return 1;
|
||||
return node->terminal;
|
||||
}
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
|
|
Loading…
Reference in New Issue