Add more utility functions to work with patricia trees

This commit is contained in:
Alfredo Cardigliano
2021-02-23 11:53:15 +01:00
parent 888ddfcd17
commit 566d5db402
3 changed files with 43 additions and 0 deletions
+30
View File
@@ -1660,6 +1660,12 @@ static int ac_match_handler(AC_MATCH_t *m, AC_TEXT_t *txt, AC_REP_t *match) {
/* ******************************************************************** */
u_int16_t ndpi_patricia_get_maxbits(ndpi_patricia_tree_t *tree) {
return(tree->maxbits);
}
/* ******************************************************************** */
int ndpi_fill_prefix_v4(ndpi_prefix_t *p, const struct in_addr *a, int b, int mb) {
if(b < 0 || b > mb)
return(-1);
@@ -1703,6 +1709,30 @@ int ndpi_fill_prefix_mac(ndpi_prefix_t *prefix, u_int8_t *mac, int bits, int max
/* ******************************************* */
ndpi_prefix_t *ndpi_patricia_get_node_prefix(ndpi_patricia_node_t *node) {
return(node->prefix);
}
/* ******************************************* */
u_int16_t ndpi_patricia_get_node_bits(ndpi_patricia_node_t *node) {
return(node->bit);
}
/* ******************************************* */
void ndpi_patricia_set_node_data(ndpi_patricia_node_t *node, void *data) {
node->data = data;
}
/* ******************************************* */
void *ndpi_patricia_get_node_data(ndpi_patricia_node_t *node) {
return(node->data);
}
/* ******************************************* */
void ndpi_patricia_set_node_u64(ndpi_patricia_node_t *node, u_int64_t value) {
node->value.u.uv64 = value;
}
+7
View File
@@ -449,6 +449,13 @@ ndpi_patricia_walk_inorder(ndpi_patricia_node_t *node, ndpi_void_fn3_t func, voi
return n;
}
size_t
ndpi_patricia_walk_tree_inorder(ndpi_patricia_tree_t *patricia, ndpi_void_fn3_t func, void *data) {
if (patricia->head == NULL)
return 0;
return ndpi_patricia_walk_inorder(patricia->head, func, data);
}
ndpi_patricia_node_t *
ndpi_patricia_search_exact (ndpi_patricia_tree_t *patricia, ndpi_prefix_t *prefix)