1 #ifndef TRIE_SEARCH_H 2 #define TRIE_SEARCH_H 3 4 5 6 #include <stdio.h> 7 #include <stdlib.h> 8 #include <stdint.h> 9 10 #include "trie.h" 11 12 #include "collections.h" 13 #include "klib/kvec.h" 14 #include "log/log.h" 15 #include "string_utils.h" 16 #include "tokens.h" 17 #include "vector.h" 18 #include "utf8proc/utf8proc.h" 19 20 typedef struct phrase { 21 uint32_t start; 22 uint32_t len; 23 uint32_t data; 24 } phrase_t; 25 26 VECTOR_INIT(phrase_array, phrase_t) 27 28 #define NULL_PHRASE (phrase_t){0, 0, 0} 29 #define NULL_PHRASE_MEMBERSHIP -1 30 31 phrase_array *trie_search(trie_t *self, char *text); 32 bool trie_search_from_index(trie_t *self, char *text, uint32_t start_node_id, phrase_array **phrases); 33 bool trie_search_with_phrases(trie_t *self, char *text, phrase_array **phrases); 34 phrase_array *trie_search_tokens(trie_t *self, char *str, token_array *tokens); 35 bool trie_search_tokens_from_index(trie_t *self, char *str, token_array *tokens, uint32_t start_node_id, phrase_array **phrases); 36 bool trie_search_tokens_with_phrases(trie_t *self, char *text, token_array *tokens, phrase_array **phrases); 37 phrase_t trie_search_suffixes_from_index(trie_t *self, char *word, size_t len, uint32_t start_node_id); 38 phrase_t trie_search_suffixes_from_index_get_suffix_char(trie_t *self, char *word, size_t len, uint32_t start_node_id); 39 phrase_t trie_search_suffixes(trie_t *self, char *word, size_t len); 40 phrase_t trie_search_prefixes_from_index(trie_t *self, char *word, size_t len, uint32_t start_node_id); 41 phrase_t trie_search_prefixes_from_index_get_prefix_char(trie_t *self, char *word, size_t len, uint32_t start_node_id); 42 phrase_t trie_search_prefixes(trie_t *self, char *word, size_t len); 43 44 bool token_phrase_memberships(phrase_array *phrases, int64_array *phrase_memberships, size_t len); 45 46 char *cstring_array_get_phrase(cstring_array *str, char_array *phrase_tokens, phrase_t phrase); 47 48 #endif 49