squareball/sb-trie.h File Reference
Implementation of a trie data structure.
More...
#include <stdbool.h>
#include <stdlib.h>
#include <stdarg.h>
#include "sb-mem.h"
Go to the source code of this file.
Detailed Description
Implementation of a trie data structure.
This trie implementation is mostly designed to be used as a replacement for a hash table, where the keys are always strings (arrays of char
elements).
Typedef Documentation
Trie foreach callback function type.
Function Documentation
Function that calls a given function for each element of a trie.
- Parameters:
-
| trie | The trie. |
| func | The function that should be called for each element. |
| user_data | Pointer to user data to be passed to func . |
- Examples:
- hello_trie.c.
Function that frees the memory allocated for a trie, and for its elements (using the free function provided when creating the trie).
- Parameters:
-
- Examples:
- hello_trie.c.
void sb_trie_insert |
( |
sb_trie_t * |
trie, |
|
|
const char * |
key, |
|
|
void * |
data | |
|
) |
| | |
Function that inserts an element on the trie. If the key already exists, its current element is free'd (using the free function provided when creating the trie) and replaced with new one.
- Parameters:
-
| trie | The trie. |
| key | The key string. |
| data | The data to be stored for the key. Users should not free it explicitly if the tree was initialized with a valid free function. |
- Examples:
- hello_trie.c.
void* sb_trie_lookup |
( |
sb_trie_t * |
trie, |
|
|
const char * |
key | |
|
) |
| | |
Function that searches the trie for a given key, and return its data.
- Parameters:
-
| trie | The trie. |
| key | The key string to be looked for. |
- Returns:
- The date stored for the given key, if found, otherwise NULL.
- Examples:
- hello_trie.c.
Function that creates a new trie.
- Parameters:
-
| free_func | The sb_free_func_t to be used to free the memory allocated for the elements automatically when needed. If NULL, the trie won't touch the elements when free'ing itself. |
- Returns:
- A new trie.
- Examples:
- hello_trie.c.
Function that returns the size of a given trie.
- Parameters:
-
- Returns:
- The size of the given trie.
- Examples:
- hello_trie.c.