|
solidc
Robust collection of general-purpose cross-platform C libraries and data structures designed for rapid and safe development in C
|
Trie data structure implementation for efficient string storage and retrieval. More...
#include "arena.h"#include <stdbool.h>#include <stdint.h>#include <stdio.h>#include <stdlib.h>#include <string.h>Go to the source code of this file.
Classes | |
| struct | suggestions_collector_t |
Typedefs | |
| typedef struct _trie | trie_t |
Functions | |
| trie_t * | trie_create (void) |
| void | trie_destroy (trie_t *trie) |
| bool | trie_insert (trie_t *trie, const char *word) |
| bool | trie_search (const trie_t *trie, const char *word) |
| bool | trie_starts_with (const trie_t *trie, const char *prefix) |
| bool | trie_delete (trie_t *trie, const char *word) |
| uint32_t | trie_get_frequency (const trie_t *trie, const char *word) |
| size_t | trie_get_word_count (const trie_t *trie) |
| bool | trie_is_empty (const trie_t *trie) |
| const char ** | trie_autocomplete (const trie_t *trie, const char *prefix, size_t max_suggestions, size_t *out_count, Arena *arena) |
Trie data structure implementation for efficient string storage and retrieval.
Definition in file trie.h.
| typedef struct _trie trie_t |
| const char ** trie_autocomplete | ( | const trie_t * | trie, |
| const char * | prefix, | ||
| size_t | max_suggestions, | ||
| size_t * | out_count, | ||
| Arena * | arena | ||
| ) |
Autocomplete function that returns all words with a given prefix. Stores the result array and suggestion strings in the provided Arena.
| trie | The Trie structure. |
| prefix | The prefix to search for (null-terminated). |
| max_suggestions | Maximum number of suggestions to return. |
| out_count | Output parameter for number of suggestions found. |
| arena | The Arena allocator to use for the results. |
Definition at line 235 of file trie.c.
References trie_autocomplete().
Referenced by trie_autocomplete().
| trie_t * trie_create | ( | void | ) |
Creates a new Trie data structure.
Definition at line 117 of file trie.c.
References trie_create().
Referenced by trie_create().
| bool trie_delete | ( | trie_t * | trie, |
| const char * | word | ||
| ) |
Deletes a word from the Trie.
| trie | The Trie structure. |
| word | The word to delete (null-terminated). |
Definition at line 176 of file trie.c.
References trie_delete().
Referenced by trie_delete().
| void trie_destroy | ( | trie_t * | trie | ) |
Destroys a Trie and frees all associated memory.
| trie | Trie to destroy (can be NULL). |
Definition at line 129 of file trie.c.
References trie_destroy().
Referenced by trie_destroy().
| uint32_t trie_get_frequency | ( | const trie_t * | trie, |
| const char * | word | ||
| ) |
Gets the frequency count for a word.
| trie | The Trie structure. |
| word | The word to query (null-terminated). |
Definition at line 193 of file trie.c.
References trie_get_frequency().
Referenced by trie_get_frequency().
| size_t trie_get_word_count | ( | const trie_t * | trie | ) |
Gets the total number of unique words in the Trie.
| trie | The Trie structure. |
Definition at line 205 of file trie.c.
References trie_get_word_count().
Referenced by trie_get_word_count().
| bool trie_insert | ( | trie_t * | trie, |
| const char * | word | ||
| ) |
Inserts a word into the Trie.
| trie | The Trie structure. |
| word | The word to insert (null-terminated). |
Definition at line 135 of file trie.c.
References trie_insert().
Referenced by trie_insert().
| bool trie_is_empty | ( | const trie_t * | trie | ) |
Checks if the Trie is empty.
| trie | The Trie structure. |
Definition at line 206 of file trie.c.
References trie_is_empty().
Referenced by trie_is_empty().
| bool trie_search | ( | const trie_t * | trie, |
| const char * | word | ||
| ) |
Searches for an exact word in the Trie.
| trie | The Trie structure. |
| word | The word to search for (null-terminated). |
Definition at line 152 of file trie.c.
References trie_search().
Referenced by trie_search().
| bool trie_starts_with | ( | const trie_t * | trie, |
| const char * | prefix | ||
| ) |
Checks if any word in the Trie starts with the given prefix.
| trie | The Trie structure. |
| prefix | The prefix to search for (null-terminated). |
Definition at line 164 of file trie.c.
References trie_starts_with().
Referenced by trie_starts_with().