2 * Definitions for the Wireshark Memory Manager Red-Black Tree
3 * Based on the red-black tree implementation in epan/emem.*
4 * Copyright 2015, Matthieu coudron <matthieu.coudron@lip6.fr>
6 * Wireshark - Network traffic analyzer
7 * By Gerald Combs <gerald@wireshark.org>
8 * Copyright 1998 Gerald Combs
10 * SPDX-License-Identifier: GPL-2.0-or-later
12 #ifndef __WMEM_INTERVAL_TREE_H__
13 #define __WMEM_INTERVAL_TREE_H__
15 #include "wmem_core.h"
16 #include "wmem_tree.h"
17 #include "wmem_list.h"
22 #endif /* __cplusplus */
26 * @defgroup wmem-interval-tree Interval Tree
28 * http://www.geeksforgeeks.org/interval-tree/
29 * The idea is to augment a self-balancing Binary Search Tree (BST) like Red Black Tree, AVL Tree, etc ...
30 * to maintain a set of intervals so that all operations can be done in O(Logn) time.
32 * Following wikipedia's convention this is an augmented tree rather then an interval tree
33 * http://www.wikiwand.com/en/Interval_tree
37 typedef struct _wmem_tree_t wmem_itree_t
;
39 struct _wmem_range_t
{
40 uint64_t low
; /* low is used as the key in the binary tree */
41 uint64_t high
; /* Max value of the range */
42 uint64_t max_edge
; /* max value among subtrees */
47 wmem_itree_new(wmem_allocator_t
*allocator
)
51 /** Returns true if the tree is empty (has no nodes). */
54 wmem_itree_is_empty(wmem_itree_t
*tree
);
57 /** Inserts a range low-high indexed by "low" in O(log(n)).
58 * As in wmem_tree, if a key "low" already exists, it will be overwritten with the new data
63 wmem_itree_insert(wmem_itree_t
*tree
, const uint64_t low
, const uint64_t high
, void *data
);
67 * Save results in a wmem_list with the scope passed as a parameter.
68 * wmem_list_t is always allocated even if there is no result
72 wmem_itree_find_intervals(wmem_itree_t
*tree
, wmem_allocator_t
*allocator
, uint64_t low
, uint64_t high
);
76 * Print ranges along the tree
79 wmem_print_itree(wmem_itree_t
*tree
);
86 #endif /* __cplusplus */
88 #endif /* __WMEM_INTERVAL_TREE_H__ */
91 * Editor modelines - https://www.wireshark.org/tools/modelines.html
96 * indent-tabs-mode: nil
99 * vi: set shiftwidth=4 tabstop=8 expandtab:
100 * :indentSize=4:tabSize=8:noTabs=true: