libreis  0.1.0
A simple header-based drop-in library
trie.h
1 #ifndef __REIS_TRIE_H__
2 #define __REIS_TRIE_H__
3 
4 #include <reis/base.h>
5 
6 #ifdef __cplusplus
7 extern "C" {
8 #endif
9 
10 // Default to English but designed to be changed.
11 static int rsTrieAlphabetSize = 26;
12 
13 typedef struct trie_t trie_t;
14 struct trie_t { // TrieNode
15  wchar_t data;
16  bool is_leaf;
17  trie_t* children[];
18 };
19 
20 trie_t* rsTrieInit(wchar_t data, int numOfLetters);
21 void rsTrieFree(trie_t *node);
22 
23 trie_t* rsTrieInsert(trie_t *root, wchar_t *word);
24 trie_t* rsTrieDelete(trie_t *root, wchar_t *word);
25 
26 bool rsTrieSearch(trie_t *root, wchar_t *word);
27 
28 void rsTriePrint(trie_t *root);
29 bool rsTriePrintSearch(trie_t *root, wchar_t *word);
30 
31 #ifdef __cplusplus
32 }
33 #endif
34 
35 #endif
Shared types and functions, accounts for GNU Linux and MacOS specifications.
Definition: trie.h:14
bool rsTrieSearch(trie_t *root, wchar_t *word)
Searches for a given word.
Definition: trie.c:85
trie_t * rsTrieInsert(trie_t *root, wchar_t *word)
Inserts word onto the trie.
Definition: trie.c:43
trie_t * rsTrieDelete(trie_t *root, wchar_t *word)
Deletes words from trie. Will try to delete the word sequence from trie only if it ends up in a leaf ...
Definition: trie.c:67