| 1 |
/* SPDX-License-Identifier: GPL-3.0-or-later */
|
| 2 |
/*
|
| 3 |
* trie_dict
|
| 4 |
* - trie-tree based dict feature
|
| 5 |
*
|
| 6 |
* Copyright (C) 2004-2026 Leaflet <leaflet@leafok.com>
|
| 7 |
*/
|
| 8 |
|
| 9 |
#ifndef _TRIE_DICT_H_
|
| 10 |
#define _TRIE_DICT_H_
|
| 11 |
|
| 12 |
#include <stdint.h>
|
| 13 |
|
| 14 |
enum trie_dict_constant_t
|
| 15 |
{
|
| 16 |
TRIE_CHILDREN = 256,
|
| 17 |
TRIE_MAX_KEY_LEN = 1023,
|
| 18 |
TRIE_NODE_PER_POOL = 5000,
|
| 19 |
};
|
| 20 |
|
| 21 |
struct trie_node_t
|
| 22 |
{
|
| 23 |
int64_t values[TRIE_CHILDREN];
|
| 24 |
int8_t flags[TRIE_CHILDREN];
|
| 25 |
struct trie_node_t *p_nodes[TRIE_CHILDREN];
|
| 26 |
};
|
| 27 |
typedef struct trie_node_t TRIE_NODE;
|
| 28 |
|
| 29 |
typedef void (*trie_dict_traverse_cb)(const char *, int64_t);
|
| 30 |
|
| 31 |
extern int trie_dict_init(const char *filename, int node_count_limit);
|
| 32 |
extern void trie_dict_cleanup(void);
|
| 33 |
|
| 34 |
extern int set_trie_dict_shm_readonly(void);
|
| 35 |
extern int detach_trie_dict_shm(void);
|
| 36 |
|
| 37 |
extern TRIE_NODE *trie_dict_create(void);
|
| 38 |
extern void trie_dict_destroy(TRIE_NODE *p_dict);
|
| 39 |
|
| 40 |
extern int trie_dict_set(TRIE_NODE *p_dict, const char *key, int64_t value);
|
| 41 |
extern int trie_dict_get(TRIE_NODE *p_dict, const char *key, int64_t *p_value);
|
| 42 |
extern int trie_dict_del(TRIE_NODE *p_dict, const char *key);
|
| 43 |
|
| 44 |
extern void trie_dict_traverse(TRIE_NODE *p_dict, trie_dict_traverse_cb cb);
|
| 45 |
|
| 46 |
extern int trie_dict_used_nodes(void);
|
| 47 |
|
| 48 |
#endif //_TRIE_DICT_H_
|