C Fundamentals
Algorithms · data structures · cryptography · systems — pure C11, zero deps
Loading...
Searching...
No Matches
trie.h
Go to the documentation of this file.
1/**
2 * @file trie.h
3 * @brief Prefix tree (trie) over lowercase ASCII letters a-z.
4 *
5 * 26-way fixed branching, one node per inserted prefix. Memory cost is
6 * proportional to the union of all prefixes — heavier than a hash set
7 * but supports starts_with (prefix queries) in O(prefix length).
8 */
9
10#ifndef TRIE_H
11#define TRIE_H
12
13#include <stdbool.h>
14
15typedef struct trie trie_t;
16
17trie_t *trie_create(void);
18void trie_destroy(trie_t *t);
19
20/** Inserts a lowercase a-z word. Returns false on allocation failure or
21 * if the word contains a non-{a-z} character. */
22bool trie_insert(trie_t *t, const char *word);
23
24bool trie_contains(const trie_t *t, const char *word);
25
26/** True if any inserted word begins with `prefix`. */
27bool trie_starts_with(const trie_t *t, const char *prefix);
28
29#endif /* TRIE_H */
Definition trie.c:15
bool trie_insert(trie_t *t, const char *word)
Definition trie.c:49
bool trie_contains(const trie_t *t, const char *word)
Definition trie.c:76
bool trie_starts_with(const trie_t *t, const char *prefix)
Definition trie.c:81
void trie_destroy(trie_t *t)
Definition trie.c:37
trie_t * trie_create(void)
Definition trie.c:29