Trie datastructure with utility functions. More...
#include "dtrie.h"#include "../../dprint.h"#include "../../mem/shm_mem.h"#include "../../mem/mem.h"
Go to the source code of this file.
Provides a generic trie datastructure and utility functions to initialize and manage individual nodes. Its optimized towards the usecase of a matching tree that contains only digits, e.g. for LCR or blacklist modules. Nevertheless it also supports the matching of characters when configured correctly. For normal digit only matching you need to use a branches parameter of 10, when you use 128, the complete standard ascii charset is available for matching. The trie is setup in shared memory.
Definition in file dtrie.c.
| void dtrie_clear | ( | struct dtrie_node_t * | root, | |
| dt_delete_func_t | delete_payload, | |||
| const unsigned int | branches | |||
| ) |
Deletes everything but the root node, the root node is new initialized. This could be used to create an empty tree like after dtrie_init. It also deletes eventual payload on all nodes including the root node.
| root | root node | |
| delete_payload | pointer to a function for deleting payload. If NULL, it will not be used. | |
| branches | number of branches in the trie |
Definition at line 113 of file dtrie.c.
References dtrie_delete().
Referenced by db_reload_source().


| void** dtrie_contains | ( | struct dtrie_node_t * | root, | |
| const char * | number, | |||
| const unsigned int | numberlen, | |||
| const unsigned int | branches | |||
| ) |
| root | root node | |
| number | matched prefix | |
| numberlen | length of number | |
| branches | number of branches in the trie |
Definition at line 249 of file dtrie.c.
References dtrie_longest_match().
Referenced by add_failure_route_to_tree(), and add_route_to_tree().


| void dtrie_delete | ( | struct dtrie_node_t * | root, | |
| struct dtrie_node_t * | node, | |||
| dt_delete_func_t | delete_payload, | |||
| const unsigned int | branches | |||
| ) |
| root | root node of the whole tree | |
| node | root of the subtree | |
| delete_payload | pointer to a function for deleting payload. If NULL, it will not be used. | |
| branches | number of branches in the trie |
Definition at line 75 of file dtrie.c.
References dtrie_node_t::child, dtrie_node_t::data, and dtrie_delete().
Referenced by dtrie_clear(), dtrie_delete(), and dtrie_destroy().


| void dtrie_destroy | ( | struct dtrie_node_t ** | root, | |
| dt_delete_func_t | delete_payload, | |||
| const unsigned int | branches | |||
| ) |
| root | root node | |
| delete_payload | pointer to a function for deleting payload. If NULL, it will not be used. | |
| branches | number of branches in the trie |
Definition at line 101 of file dtrie.c.
References dtrie_delete().
Referenced by create_domain_data(), and destroy_domain_data().


| struct dtrie_node_t* dtrie_init | ( | const unsigned int | branches | ) | [read] |
| branches | number of branches in the trie |
Definition at line 47 of file dtrie.c.
References dtrie_node_t::child, and root.
Referenced by add_source(), and create_domain_data().

| int dtrie_insert | ( | struct dtrie_node_t * | root, | |
| const char * | number, | |||
| const unsigned int | numberlen, | |||
| void * | data, | |||
| const unsigned int | dtrie_size | |||
| ) |
Insert a number with a corresponding id. Nodes are created if necessary and the node after the last digit is marked with the given id.
| root | root node | |
| number | inserted number string | |
| numberlen | number of individual numbers in number | |
| data | pointer to some custom data | |
| branches | number of branches in the trie |
Definition at line 120 of file dtrie.c.
References dtrie_node_t::child, and dtrie_node_t::data.
Referenced by add_failure_route_to_tree(), add_route_to_tree(), and db_reload_source().

| unsigned int dtrie_leaves | ( | const struct dtrie_node_t * | root, | |
| const unsigned int | branches | |||
| ) |
Returns the number of leaf nodes in the given tree. On leaf nodes the leaf flag is set, on other nodes it is cleared.
| root | root node | |
| branches | number of branches in the trie |
Definition at line 200 of file dtrie.c.
References dtrie_node_t::child, and dtrie_leaves().
Referenced by dtrie_leaves().


| unsigned int dtrie_loaded_nodes | ( | const struct dtrie_node_t * | root, | |
| const unsigned int | branches | |||
| ) |
Returns the number of nodes in the given tree that are loaded with data (data != NULL).
| root | root node | |
| branches | number of branches in the trie |
Definition at line 184 of file dtrie.c.
References dtrie_node_t::child, dtrie_node_t::data, and dtrie_loaded_nodes().
Referenced by dtrie_loaded_nodes().


| void** dtrie_longest_match | ( | struct dtrie_node_t * | root, | |
| const char * | number, | |||
| const unsigned int | numberlen, | |||
| int * | nmatchptr, | |||
| const unsigned int | branches | |||
| ) |
Find the longest prefix match of number in root. Set *data according to value in the tree.
| root | root node | |
| number | matched prefix | |
| numberlen | length of number | |
| nmatchptr | if not NULL store the number of matched digits or -1 if not found. | |
| branches | number of branches in the trie |
Definition at line 215 of file dtrie.c.
References dtrie_node_t::child, and dtrie_node_t::data.
Referenced by dtrie_contains(), rewrite_uri_recursor(), and set_next_domain_recursor().

| unsigned int dtrie_size | ( | const struct dtrie_node_t * | root, | |
| const unsigned int | branches | |||
| ) |
| root | root node | |
| branches | number of branches in the trie |
Definition at line 170 of file dtrie.c.
References dtrie_node_t::child, and dtrie_size().
Referenced by dtrie_size().


1.7.1