https://github.com/redislabs/triemap
C implementation of a compressed trie lookup map
https://github.com/redislabs/triemap
Last synced: about 1 year ago
JSON representation
C implementation of a compressed trie lookup map
- Host: GitHub
- URL: https://github.com/redislabs/triemap
- Owner: RedisLabs
- License: bsd-2-clause
- Created: 2017-01-18T10:03:21.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2019-05-14T10:39:09.000Z (about 7 years ago)
- Last Synced: 2025-04-06T17:01:48.134Z (about 1 year ago)
- Language: C
- Size: 45.9 KB
- Stars: 21
- Watchers: 9
- Forks: 9
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# triemap
C implementation of a compact trie lookup map
## Features
* High memory efficiency, fast lookups and insertions
* Deletions with node rejoining
* Prefix lookups with an iterator API
* Random key extraction
* No external dependencies, just one C and one H file
## Basic Example
```c
TrieMap *tm = NewTrieMap();
char buf[32];
for (int i = 0; i < 100; i++) {
sprintf(buf, "key%d", i);
TrieMap_Add(tm, buf, strlen(buf), NULL, NULL);
}
TrieMapIterator *it = TrieMap_Iterate(tm, "key1", 4);
char *str = NULL;
tm_len_t len = 0;
void *ptr = NULL;
/* Prefix Iteration */
while (TrieMapIterator_Next(it, &str, &len, &ptr)) {
printf("Found key %.*s\n", (int)len, str);
}
TrieMapIterator_Free(&it);
TrieMap_Free(tm, NULL);
```