16#ifndef UTILS_GP_TRIE_H
17#define UTILS_GP_TRIE_H
54 memset(node, 0,
sizeof(*node));
59static inline void gp_trie_free(
gp_trie_node *root,
void (*payload_free)(
void *payload))
67 avl_root = root->nodes;
73 gp_trie_free(node, payload_free);
78 payload_free(root->payload);
88 return ta->key - tb->key;
91static inline int gp_trie_key_cmp(
gp_avl_node *a,
const void *key)
94 uint32_t kval = *(
const uint32_t*)key;
96 return ta->key - kval;
106 root = gp_trie_node_new();
112 root->payload = payload;
120 node = gp_trie_ins(node, str_key, payload);
127 root->nodes =
gp_avl_tree_ins(root->nodes, &node->avl_next, gp_trie_cmp);
163 *payload = root->payload;
166 root->payload = NULL;
177 node = gp_trie_del_(node, str_key, payload);
179 root->nodes =
gp_avl_tree_del(root->nodes, &key, NULL, gp_trie_key_cmp);
194 gp_trie_node *node = gp_trie_del_(root, str_key, payload);
#define GP_CONTAINER_OF(ptr, structure, member)
Converts from a pointer to a struct field to a pointer to the struct itself.
static gp_avl_node * gp_avl_tree_del_min(gp_avl_node *root, gp_avl_node **min)
Removes a minimal node from an AVL tree.
static gp_avl_node * gp_avl_tree_ins(gp_avl_node *root, gp_avl_node *node, int(*cmp)(gp_avl_node *a, gp_avl_node *b))
Inserts a node into an AVL tree.
static gp_avl_node * gp_avl_tree_lookup(gp_avl_node *root, const void *key, int(*cmp)(gp_avl_node *a, const void *key))
Looks up a node by a key.
static gp_avl_node * gp_avl_tree_del(gp_avl_node *root, const void *key, gp_avl_node **del, int(*cmp)(gp_avl_node *a, const void *key))
Removes a node by a key from an AVL tree.
A compiler dependent macros.
#define GP_WUR
Expands to warn_unused_result attribute when supported by the compiler.
Unicode helper macros and functions.
static uint32_t gp_utf8_next(const char **str)
Parses next unicode character in UTF-8 string.
Trie node stores pointers.