blob: 1d7bc4df9054745f1973a8a54fe3026a152caa62 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
|
/** @file
* Definitions for the Wireshark Memory Manager Red-Black Tree
* Based on the red-black tree implementation in epan/emem.*
* Copyright 2015, Matthieu coudron <matthieu.coudron@lip6.fr>
*
* Wireshark - Network traffic analyzer
* By Gerald Combs <gerald@wireshark.org>
* Copyright 1998 Gerald Combs
*
* SPDX-License-Identifier: GPL-2.0-or-later
*/
#ifndef __WMEM_INTERVAL_TREE_H__
#define __WMEM_INTERVAL_TREE_H__
#include "wmem_core.h"
#include "wmem_tree.h"
#include "wmem_list.h"
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
/** @addtogroup wmem
* @{
* @defgroup wmem-interval-tree Interval Tree
*
* http://www.geeksforgeeks.org/interval-tree/
* The idea is to augment a self-balancing Binary Search Tree (BST) like Red Black Tree, AVL Tree, etc ...
* to maintain a set of intervals so that all operations can be done in O(Logn) time.
* @{
* Following wikipedia's convention this is an augmented tree rather then an interval tree
* http://www.wikiwand.com/en/Interval_tree
*/
struct _wmem_tree_t;
typedef struct _wmem_tree_t wmem_itree_t;
struct _wmem_range_t {
uint64_t low; /* low is used as the key in the binary tree */
uint64_t high; /* Max value of the range */
uint64_t max_edge; /* max value among subtrees */
};
WS_DLL_PUBLIC
wmem_itree_t *
wmem_itree_new(wmem_allocator_t *allocator)
G_GNUC_MALLOC;
/** Returns true if the tree is empty (has no nodes). */
WS_DLL_PUBLIC
bool
wmem_itree_is_empty(wmem_itree_t *tree);
/** Inserts a range low-high indexed by "low" in O(log(n)).
* As in wmem_tree, if a key "low" already exists, it will be overwritten with the new data
*
*/
WS_DLL_PUBLIC
void
wmem_itree_insert(wmem_itree_t *tree, const uint64_t low, const uint64_t high, void *data);
/*
* Save results in a wmem_list with the scope passed as a parameter.
* wmem_list_t is always allocated even if there is no result
*/
WS_DLL_PUBLIC
wmem_list_t *
wmem_itree_find_intervals(wmem_itree_t *tree, wmem_allocator_t *allocator, uint64_t low, uint64_t high);
/**
* Print ranges along the tree
*/
void
wmem_print_itree(wmem_itree_t *tree);
/** @}
* @} */
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif /* __WMEM_INTERVAL_TREE_H__ */
/*
* Editor modelines - https://www.wireshark.org/tools/modelines.html
*
* Local variables:
* c-basic-offset: 4
* tab-width: 8
* indent-tabs-mode: nil
* End:
*
* vi: set shiftwidth=4 tabstop=8 expandtab:
* :indentSize=4:tabSize=8:noTabs=true:
*/
|