| 1 |
/***************************************************************************
|
| 2 |
trie_dict.h - description
|
| 3 |
-------------------
|
| 4 |
Copyright : (C) 2004-2025 by Leaflet
|
| 5 |
Email : leaflet@leafok.com
|
| 6 |
***************************************************************************/
|
| 7 |
|
| 8 |
/***************************************************************************
|
| 9 |
* *
|
| 10 |
* This program is free software; you can redistribute it and/or modify *
|
| 11 |
* it under the terms of the GNU General Public License as published by *
|
| 12 |
* the Free Software Foundation; either version 3 of the License, or *
|
| 13 |
* (at your option) any later version. *
|
| 14 |
* *
|
| 15 |
***************************************************************************/
|
| 16 |
|
| 17 |
#ifndef _TRIE_DICT_H_
|
| 18 |
#define _TRIE_DICT_H_
|
| 19 |
|
| 20 |
#include <stdint.h>
|
| 21 |
|
| 22 |
#define TRIE_CHILDREN 256
|
| 23 |
#define TRIE_MAX_KEY_LEN 1023
|
| 24 |
#define TRIE_NODE_PER_POOL 5000
|
| 25 |
|
| 26 |
struct trie_node_t
|
| 27 |
{
|
| 28 |
int64_t values[TRIE_CHILDREN];
|
| 29 |
int8_t flags[TRIE_CHILDREN];
|
| 30 |
struct trie_node_t *p_nodes[TRIE_CHILDREN];
|
| 31 |
};
|
| 32 |
typedef struct trie_node_t TRIE_NODE;
|
| 33 |
|
| 34 |
typedef void (*trie_dict_traverse_cb)(const char *, int64_t);
|
| 35 |
|
| 36 |
extern int trie_dict_init(const char *filename, int node_count_limit);
|
| 37 |
extern void trie_dict_cleanup(void);
|
| 38 |
|
| 39 |
extern int set_trie_dict_shm_readonly(void);
|
| 40 |
extern int detach_trie_dict_shm(void);
|
| 41 |
|
| 42 |
extern TRIE_NODE *trie_dict_create(void);
|
| 43 |
extern void trie_dict_destroy(TRIE_NODE *p_dict);
|
| 44 |
|
| 45 |
extern int trie_dict_set(TRIE_NODE *p_dict, const char *key, int64_t value);
|
| 46 |
extern int trie_dict_get(TRIE_NODE *p_dict, const char *key, int64_t *p_value);
|
| 47 |
extern int trie_dict_del(TRIE_NODE *p_dict, const char *key);
|
| 48 |
|
| 49 |
extern void trie_dict_traverse(TRIE_NODE *p_dict, trie_dict_traverse_cb cb);
|
| 50 |
|
| 51 |
extern int trie_dict_used_nodes(void);
|
| 52 |
|
| 53 |
#endif //_TRIE_DICT_H_
|