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
15
typedef
struct
trie
trie_t
;
16
17
trie_t
*
trie_create
(
void
);
18
void
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. */
22
bool
trie_insert
(
trie_t
*t,
const
char
*word);
23
24
bool
trie_contains
(
const
trie_t
*t,
const
char
*word);
25
26
/** True if any inserted word begins with `prefix`. */
27
bool
trie_starts_with
(
const
trie_t
*t,
const
char
*prefix);
28
29
#endif
/* TRIE_H */
trie
Definition
trie.c:15
trie_insert
bool trie_insert(trie_t *t, const char *word)
Definition
trie.c:49
trie_contains
bool trie_contains(const trie_t *t, const char *word)
Definition
trie.c:76
trie_starts_with
bool trie_starts_with(const trie_t *t, const char *prefix)
Definition
trie.c:81
trie_destroy
void trie_destroy(trie_t *t)
Definition
trie.c:37
trie_create
trie_t * trie_create(void)
Definition
trie.c:29
data_structures
trie
trie.h
Generated by
1.9.8