Mark partial words as not a word

This commit is contained in:
Nick Chambers 2024-05-06 14:50:12 -05:00
parent e4726b87dd
commit 16375e2c7c
1 changed files with 6 additions and 1 deletions

View File

@ -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) {