/src/open5gs/lib/core/ogs-rbtree.h
Line | Count | Source |
1 | | /* |
2 | | * Copyright (C) 2019 by Sukchan Lee <acetcom@gmail.com> |
3 | | * |
4 | | * This file is part of Open5GS. |
5 | | * |
6 | | * This program is free software: you can redistribute it and/or modify |
7 | | * it under the terms of the GNU Affero General Public License as published by |
8 | | * the Free Software Foundation, either version 3 of the License, or |
9 | | * (at your option) any later version. |
10 | | * |
11 | | * This program is distributed in the hope that it will be useful, |
12 | | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 | | * GNU General Public License for more details. |
15 | | * |
16 | | * You should have received a copy of the GNU General Public License |
17 | | * along with this program. If not, see <https://www.gnu.org/licenses/>. |
18 | | */ |
19 | | |
20 | | #if !defined(OGS_CORE_INSIDE) && !defined(OGS_CORE_COMPILATION) |
21 | | #error "This header cannot be included directly." |
22 | | #endif |
23 | | |
24 | | #ifndef OGS_RBTREE_H |
25 | | #define OGS_RBTREE_H |
26 | | |
27 | | #ifdef __cplusplus |
28 | | extern "C" { |
29 | | #endif |
30 | | |
31 | | typedef enum { |
32 | | OGS_RBTREE_BLACK = 0, |
33 | | OGS_RBTREE_RED = 1, |
34 | | } ogs_rbtree_color_e; |
35 | | |
36 | | typedef struct ogs_rbnode_s { |
37 | | struct ogs_rbnode_s *parent; |
38 | | struct ogs_rbnode_s *left; |
39 | | struct ogs_rbnode_s *right; |
40 | | |
41 | | ogs_rbtree_color_e color; |
42 | | } ogs_rbnode_t; |
43 | | |
44 | | typedef struct ogs_rbtree_s { |
45 | | ogs_rbnode_t *root; |
46 | | } ogs_rbtree_t; |
47 | | |
48 | 681 | #define OGS_RBTREE(name) ogs_rbtree_t name = { NULL } |
49 | | |
50 | 31.3k | #define ogs_rb_entry(ptr, type, member) ogs_container_of(ptr, type, member) |
51 | | |
52 | | static ogs_inline void ogs_rbtree_link_node( |
53 | | void *rb_node, ogs_rbnode_t *parent, ogs_rbnode_t **rb_link) |
54 | 6.65k | { |
55 | 6.65k | ogs_rbnode_t *node = (ogs_rbnode_t *)rb_node; |
56 | 6.65k | node->parent = parent; |
57 | 6.65k | node->left = node->right = NULL; |
58 | 6.65k | node->color = OGS_RBTREE_RED; |
59 | | |
60 | 6.65k | *rb_link = node; |
61 | 6.65k | } Unexecuted instantiation: nas-message-fuzz.c:ogs_rbtree_link_node Unexecuted instantiation: decoder.c:ogs_rbtree_link_node Unexecuted instantiation: ies.c:ogs_rbtree_link_node Unexecuted instantiation: types.c:ogs_rbtree_link_node Unexecuted instantiation: ogs-abort.c:ogs_rbtree_link_node Unexecuted instantiation: ogs-strings.c:ogs_rbtree_link_node Unexecuted instantiation: ogs-conv.c:ogs_rbtree_link_node Unexecuted instantiation: ogs-log.c:ogs_rbtree_link_node Unexecuted instantiation: ogs-pkbuf.c:ogs_rbtree_link_node Unexecuted instantiation: ogs-memory.c:ogs_rbtree_link_node Unexecuted instantiation: ogs-sockaddr.c:ogs_rbtree_link_node Unexecuted instantiation: ogs-hash.c:ogs_rbtree_link_node Unexecuted instantiation: ogs-core.c:ogs_rbtree_link_node Unexecuted instantiation: ogs-errno.c:ogs_rbtree_link_node Unexecuted instantiation: ogs-time.c:ogs_rbtree_link_node Unexecuted instantiation: ogs-socket.c:ogs_rbtree_link_node Unexecuted instantiation: ogs-tlv.c:ogs_rbtree_link_node Unexecuted instantiation: gtp-message-fuzz.c:ogs_rbtree_link_node Unexecuted instantiation: context.c:ogs_rbtree_link_node Unexecuted instantiation: xact.c:ogs_rbtree_link_node Unexecuted instantiation: conv.c:ogs_rbtree_link_node Unexecuted instantiation: message.c:ogs_rbtree_link_node Unexecuted instantiation: path.c:ogs_rbtree_link_node Unexecuted instantiation: build.c:ogs_rbtree_link_node Unexecuted instantiation: ogs-timer.c:ogs_rbtree_link_node Unexecuted instantiation: ogs-socknode.c:ogs_rbtree_link_node Unexecuted instantiation: ogs-udp.c:ogs_rbtree_link_node Unexecuted instantiation: ogs-poll.c:ogs_rbtree_link_node ogs-tlv-msg.c:ogs_rbtree_link_node Line | Count | Source | 54 | 6.65k | { | 55 | 6.65k | ogs_rbnode_t *node = (ogs_rbnode_t *)rb_node; | 56 | 6.65k | node->parent = parent; | 57 | 6.65k | node->left = node->right = NULL; | 58 | 6.65k | node->color = OGS_RBTREE_RED; | 59 | | | 60 | 6.65k | *rb_link = node; | 61 | 6.65k | } |
Unexecuted instantiation: ogs-epoll.c:ogs_rbtree_link_node Unexecuted instantiation: ogs-rbtree.c:ogs_rbtree_link_node Unexecuted instantiation: ogs-sockopt.c:ogs_rbtree_link_node Unexecuted instantiation: ogs-notify.c:ogs_rbtree_link_node Unexecuted instantiation: ogs-yaml.c:ogs_rbtree_link_node Unexecuted instantiation: ogs-context.c:ogs_rbtree_link_node Unexecuted instantiation: ogs-config.c:ogs_rbtree_link_node Unexecuted instantiation: ogs-init.c:ogs_rbtree_link_node Unexecuted instantiation: ogs-queue.c:ogs_rbtree_link_node Unexecuted instantiation: ogs-env.c:ogs_rbtree_link_node |
62 | | |
63 | | void ogs_rbtree_insert_color(ogs_rbtree_t *tree, void *rb_node); |
64 | | void ogs_rbtree_delete(ogs_rbtree_t *tree, void *rb_node); |
65 | | |
66 | | static ogs_inline void *ogs_rbtree_min(const ogs_rbnode_t *rb_node) |
67 | 0 | { |
68 | 0 | const ogs_rbnode_t *node = rb_node; |
69 | 0 | ogs_assert(node); |
70 | | |
71 | 0 | while (node->left) |
72 | 0 | node = node->left; |
73 | |
|
74 | 0 | return (void *)node; |
75 | 0 | } Unexecuted instantiation: nas-message-fuzz.c:ogs_rbtree_min Unexecuted instantiation: decoder.c:ogs_rbtree_min Unexecuted instantiation: ies.c:ogs_rbtree_min Unexecuted instantiation: types.c:ogs_rbtree_min Unexecuted instantiation: ogs-abort.c:ogs_rbtree_min Unexecuted instantiation: ogs-strings.c:ogs_rbtree_min Unexecuted instantiation: ogs-conv.c:ogs_rbtree_min Unexecuted instantiation: ogs-log.c:ogs_rbtree_min Unexecuted instantiation: ogs-pkbuf.c:ogs_rbtree_min Unexecuted instantiation: ogs-memory.c:ogs_rbtree_min Unexecuted instantiation: ogs-sockaddr.c:ogs_rbtree_min Unexecuted instantiation: ogs-hash.c:ogs_rbtree_min Unexecuted instantiation: ogs-core.c:ogs_rbtree_min Unexecuted instantiation: ogs-errno.c:ogs_rbtree_min Unexecuted instantiation: ogs-time.c:ogs_rbtree_min Unexecuted instantiation: ogs-socket.c:ogs_rbtree_min Unexecuted instantiation: ogs-tlv.c:ogs_rbtree_min Unexecuted instantiation: gtp-message-fuzz.c:ogs_rbtree_min Unexecuted instantiation: context.c:ogs_rbtree_min Unexecuted instantiation: xact.c:ogs_rbtree_min Unexecuted instantiation: conv.c:ogs_rbtree_min Unexecuted instantiation: message.c:ogs_rbtree_min Unexecuted instantiation: path.c:ogs_rbtree_min Unexecuted instantiation: build.c:ogs_rbtree_min Unexecuted instantiation: ogs-timer.c:ogs_rbtree_min Unexecuted instantiation: ogs-socknode.c:ogs_rbtree_min Unexecuted instantiation: ogs-udp.c:ogs_rbtree_min Unexecuted instantiation: ogs-poll.c:ogs_rbtree_min Unexecuted instantiation: ogs-tlv-msg.c:ogs_rbtree_min Unexecuted instantiation: ogs-epoll.c:ogs_rbtree_min Unexecuted instantiation: ogs-rbtree.c:ogs_rbtree_min Unexecuted instantiation: ogs-sockopt.c:ogs_rbtree_min Unexecuted instantiation: ogs-notify.c:ogs_rbtree_min Unexecuted instantiation: ogs-yaml.c:ogs_rbtree_min Unexecuted instantiation: ogs-context.c:ogs_rbtree_min Unexecuted instantiation: ogs-config.c:ogs_rbtree_min Unexecuted instantiation: ogs-init.c:ogs_rbtree_min Unexecuted instantiation: ogs-queue.c:ogs_rbtree_min Unexecuted instantiation: ogs-env.c:ogs_rbtree_min |
76 | | |
77 | | static ogs_inline void *ogs_rbtree_max(const void *rb_node) |
78 | 0 | { |
79 | 0 | const ogs_rbnode_t *node = (const ogs_rbnode_t *)rb_node; |
80 | 0 | ogs_assert(node); |
81 | | |
82 | 0 | while (node->right) |
83 | 0 | node = node->right; |
84 | |
|
85 | 0 | return (void *)node; |
86 | 0 | } Unexecuted instantiation: nas-message-fuzz.c:ogs_rbtree_max Unexecuted instantiation: decoder.c:ogs_rbtree_max Unexecuted instantiation: ies.c:ogs_rbtree_max Unexecuted instantiation: types.c:ogs_rbtree_max Unexecuted instantiation: ogs-abort.c:ogs_rbtree_max Unexecuted instantiation: ogs-strings.c:ogs_rbtree_max Unexecuted instantiation: ogs-conv.c:ogs_rbtree_max Unexecuted instantiation: ogs-log.c:ogs_rbtree_max Unexecuted instantiation: ogs-pkbuf.c:ogs_rbtree_max Unexecuted instantiation: ogs-memory.c:ogs_rbtree_max Unexecuted instantiation: ogs-sockaddr.c:ogs_rbtree_max Unexecuted instantiation: ogs-hash.c:ogs_rbtree_max Unexecuted instantiation: ogs-core.c:ogs_rbtree_max Unexecuted instantiation: ogs-errno.c:ogs_rbtree_max Unexecuted instantiation: ogs-time.c:ogs_rbtree_max Unexecuted instantiation: ogs-socket.c:ogs_rbtree_max Unexecuted instantiation: ogs-tlv.c:ogs_rbtree_max Unexecuted instantiation: gtp-message-fuzz.c:ogs_rbtree_max Unexecuted instantiation: context.c:ogs_rbtree_max Unexecuted instantiation: xact.c:ogs_rbtree_max Unexecuted instantiation: conv.c:ogs_rbtree_max Unexecuted instantiation: message.c:ogs_rbtree_max Unexecuted instantiation: path.c:ogs_rbtree_max Unexecuted instantiation: build.c:ogs_rbtree_max Unexecuted instantiation: ogs-timer.c:ogs_rbtree_max Unexecuted instantiation: ogs-socknode.c:ogs_rbtree_max Unexecuted instantiation: ogs-udp.c:ogs_rbtree_max Unexecuted instantiation: ogs-poll.c:ogs_rbtree_max Unexecuted instantiation: ogs-tlv-msg.c:ogs_rbtree_max Unexecuted instantiation: ogs-epoll.c:ogs_rbtree_max Unexecuted instantiation: ogs-rbtree.c:ogs_rbtree_max Unexecuted instantiation: ogs-sockopt.c:ogs_rbtree_max Unexecuted instantiation: ogs-notify.c:ogs_rbtree_max Unexecuted instantiation: ogs-yaml.c:ogs_rbtree_max Unexecuted instantiation: ogs-context.c:ogs_rbtree_max Unexecuted instantiation: ogs-config.c:ogs_rbtree_max Unexecuted instantiation: ogs-init.c:ogs_rbtree_max Unexecuted instantiation: ogs-queue.c:ogs_rbtree_max Unexecuted instantiation: ogs-env.c:ogs_rbtree_max |
87 | | |
88 | | void *ogs_rbtree_first(const ogs_rbtree_t *tree); |
89 | | void *ogs_rbtree_next(const void *node); |
90 | | void *ogs_rbtree_last(const ogs_rbtree_t *tree); |
91 | | void *ogs_rbtree_prev(const void *node); |
92 | | |
93 | | #define ogs_rbtree_for_each(tree, node) \ |
94 | 0 | for (node = ogs_rbtree_first(tree); \ |
95 | 0 | (node); node = ogs_rbtree_next(node)) |
96 | | |
97 | | #define ogs_rbtree_reverse_for_each(tree, node) \ |
98 | | for (node = ogs_rbtree_last(tree); \ |
99 | | (node); node = ogs_rbtree_prev(node)) |
100 | | |
101 | | static ogs_inline bool ogs_rbtree_empty(const ogs_rbtree_t *tree) |
102 | 0 | { |
103 | 0 | return tree->root == NULL; |
104 | 0 | } Unexecuted instantiation: nas-message-fuzz.c:ogs_rbtree_empty Unexecuted instantiation: decoder.c:ogs_rbtree_empty Unexecuted instantiation: ies.c:ogs_rbtree_empty Unexecuted instantiation: types.c:ogs_rbtree_empty Unexecuted instantiation: ogs-abort.c:ogs_rbtree_empty Unexecuted instantiation: ogs-strings.c:ogs_rbtree_empty Unexecuted instantiation: ogs-conv.c:ogs_rbtree_empty Unexecuted instantiation: ogs-log.c:ogs_rbtree_empty Unexecuted instantiation: ogs-pkbuf.c:ogs_rbtree_empty Unexecuted instantiation: ogs-memory.c:ogs_rbtree_empty Unexecuted instantiation: ogs-sockaddr.c:ogs_rbtree_empty Unexecuted instantiation: ogs-hash.c:ogs_rbtree_empty Unexecuted instantiation: ogs-core.c:ogs_rbtree_empty Unexecuted instantiation: ogs-errno.c:ogs_rbtree_empty Unexecuted instantiation: ogs-time.c:ogs_rbtree_empty Unexecuted instantiation: ogs-socket.c:ogs_rbtree_empty Unexecuted instantiation: ogs-tlv.c:ogs_rbtree_empty Unexecuted instantiation: gtp-message-fuzz.c:ogs_rbtree_empty Unexecuted instantiation: context.c:ogs_rbtree_empty Unexecuted instantiation: xact.c:ogs_rbtree_empty Unexecuted instantiation: conv.c:ogs_rbtree_empty Unexecuted instantiation: message.c:ogs_rbtree_empty Unexecuted instantiation: path.c:ogs_rbtree_empty Unexecuted instantiation: build.c:ogs_rbtree_empty Unexecuted instantiation: ogs-timer.c:ogs_rbtree_empty Unexecuted instantiation: ogs-socknode.c:ogs_rbtree_empty Unexecuted instantiation: ogs-udp.c:ogs_rbtree_empty Unexecuted instantiation: ogs-poll.c:ogs_rbtree_empty Unexecuted instantiation: ogs-tlv-msg.c:ogs_rbtree_empty Unexecuted instantiation: ogs-epoll.c:ogs_rbtree_empty Unexecuted instantiation: ogs-rbtree.c:ogs_rbtree_empty Unexecuted instantiation: ogs-sockopt.c:ogs_rbtree_empty Unexecuted instantiation: ogs-notify.c:ogs_rbtree_empty Unexecuted instantiation: ogs-yaml.c:ogs_rbtree_empty Unexecuted instantiation: ogs-context.c:ogs_rbtree_empty Unexecuted instantiation: ogs-config.c:ogs_rbtree_empty Unexecuted instantiation: ogs-init.c:ogs_rbtree_empty Unexecuted instantiation: ogs-queue.c:ogs_rbtree_empty Unexecuted instantiation: ogs-env.c:ogs_rbtree_empty |
105 | | |
106 | | static ogs_inline int ogs_rbtree_count(const ogs_rbtree_t *tree) |
107 | 0 | { |
108 | 0 | void *node; |
109 | 0 | int i = 0; |
110 | 0 | ogs_rbtree_for_each(tree, node) |
111 | 0 | i++; |
112 | 0 | return i; |
113 | 0 | } Unexecuted instantiation: nas-message-fuzz.c:ogs_rbtree_count Unexecuted instantiation: decoder.c:ogs_rbtree_count Unexecuted instantiation: ies.c:ogs_rbtree_count Unexecuted instantiation: types.c:ogs_rbtree_count Unexecuted instantiation: ogs-abort.c:ogs_rbtree_count Unexecuted instantiation: ogs-strings.c:ogs_rbtree_count Unexecuted instantiation: ogs-conv.c:ogs_rbtree_count Unexecuted instantiation: ogs-log.c:ogs_rbtree_count Unexecuted instantiation: ogs-pkbuf.c:ogs_rbtree_count Unexecuted instantiation: ogs-memory.c:ogs_rbtree_count Unexecuted instantiation: ogs-sockaddr.c:ogs_rbtree_count Unexecuted instantiation: ogs-hash.c:ogs_rbtree_count Unexecuted instantiation: ogs-core.c:ogs_rbtree_count Unexecuted instantiation: ogs-errno.c:ogs_rbtree_count Unexecuted instantiation: ogs-time.c:ogs_rbtree_count Unexecuted instantiation: ogs-socket.c:ogs_rbtree_count Unexecuted instantiation: ogs-tlv.c:ogs_rbtree_count Unexecuted instantiation: gtp-message-fuzz.c:ogs_rbtree_count Unexecuted instantiation: context.c:ogs_rbtree_count Unexecuted instantiation: xact.c:ogs_rbtree_count Unexecuted instantiation: conv.c:ogs_rbtree_count Unexecuted instantiation: message.c:ogs_rbtree_count Unexecuted instantiation: path.c:ogs_rbtree_count Unexecuted instantiation: build.c:ogs_rbtree_count Unexecuted instantiation: ogs-timer.c:ogs_rbtree_count Unexecuted instantiation: ogs-socknode.c:ogs_rbtree_count Unexecuted instantiation: ogs-udp.c:ogs_rbtree_count Unexecuted instantiation: ogs-poll.c:ogs_rbtree_count Unexecuted instantiation: ogs-tlv-msg.c:ogs_rbtree_count Unexecuted instantiation: ogs-epoll.c:ogs_rbtree_count Unexecuted instantiation: ogs-rbtree.c:ogs_rbtree_count Unexecuted instantiation: ogs-sockopt.c:ogs_rbtree_count Unexecuted instantiation: ogs-notify.c:ogs_rbtree_count Unexecuted instantiation: ogs-yaml.c:ogs_rbtree_count Unexecuted instantiation: ogs-context.c:ogs_rbtree_count Unexecuted instantiation: ogs-config.c:ogs_rbtree_count Unexecuted instantiation: ogs-init.c:ogs_rbtree_count Unexecuted instantiation: ogs-queue.c:ogs_rbtree_count Unexecuted instantiation: ogs-env.c:ogs_rbtree_count |
114 | | |
115 | | #ifdef __cplusplus |
116 | | } |
117 | | #endif |
118 | | |
119 | | #endif /* OGS_RBTREE_H */ |