1 | /** |
---|
2 | * @file rtems/rbtree.inl |
---|
3 | * |
---|
4 | * This include file contains all the constants and structures associated |
---|
5 | * with the RBTree API in RTEMS. The rbtree is a Red Black Tree that |
---|
6 | * is part of the Super Core. This is the published interface to that |
---|
7 | * code. |
---|
8 | * |
---|
9 | */ |
---|
10 | |
---|
11 | /* |
---|
12 | * Copyright (c) 2010 Gedare Bloom. |
---|
13 | * |
---|
14 | * The license and distribution terms for this file may be |
---|
15 | * found in the file LICENSE in this distribution or at |
---|
16 | * http://www.rtems.com/license/LICENSE. |
---|
17 | * |
---|
18 | * $Id$ |
---|
19 | */ |
---|
20 | |
---|
21 | #ifndef _RTEMS_RBTREE_H |
---|
22 | # error "Never use <rtems/rbtree.inl> directly; include <rtems/rbtree.h> instead." |
---|
23 | #endif |
---|
24 | |
---|
25 | #ifndef _RTEMS_RBTREE_INL |
---|
26 | #define _RTEMS_RBTREE_INL |
---|
27 | |
---|
28 | #include <rtems/score/rbtree.inl> |
---|
29 | |
---|
30 | /** |
---|
31 | * @brief Initialize a RBTree Header |
---|
32 | * |
---|
33 | * This routine initializes @a the_rbtree structure to manage the |
---|
34 | * contiguous array of @a number_nodes nodes which starts at |
---|
35 | * @a starting_address. Each node is of @a node_size bytes. |
---|
36 | */ |
---|
37 | RTEMS_INLINE_ROUTINE void rtems_rbtree_initialize( |
---|
38 | rtems_rbtree_control *the_rbtree, |
---|
39 | void *compare_function, |
---|
40 | void *starting_address, |
---|
41 | size_t number_nodes, |
---|
42 | size_t node_size |
---|
43 | ) |
---|
44 | { |
---|
45 | _RBTree_Initialize( the_rbtree, compare_function, starting_address, |
---|
46 | number_nodes, node_size); |
---|
47 | } |
---|
48 | |
---|
49 | /** |
---|
50 | * @brief Initialize this RBTree as Empty |
---|
51 | * |
---|
52 | * This routine initializes @a the_rbtree to contain zero nodes. |
---|
53 | */ |
---|
54 | RTEMS_INLINE_ROUTINE void rtems_rbtree_initialize_empty( |
---|
55 | rtems_rbtree_control *the_rbtree, |
---|
56 | void *compare_function |
---|
57 | ) |
---|
58 | { |
---|
59 | _RBTree_Initialize_empty( the_rbtree, compare_function ); |
---|
60 | } |
---|
61 | |
---|
62 | /** |
---|
63 | * @brief Set off rbtree |
---|
64 | * |
---|
65 | * This function sets the next and previous fields of the @a node to NULL |
---|
66 | * indicating the @a node is not part of any rbtree. |
---|
67 | */ |
---|
68 | RTEMS_INLINE_ROUTINE void rtems_rbtree_set_off_rbtree( |
---|
69 | rtems_rbtree_node *node |
---|
70 | ) |
---|
71 | { |
---|
72 | _RBTree_Set_off_rbtree( node ); |
---|
73 | } |
---|
74 | |
---|
75 | /** |
---|
76 | * @brief Is the Node off RBTree |
---|
77 | * |
---|
78 | * This function returns true if the @a node is not on a rbtree. A @a node is |
---|
79 | * off rbtree if the next and previous fields are set to NULL. |
---|
80 | */ |
---|
81 | RTEMS_INLINE_ROUTINE bool rtems_rbtree_is_node_off_rbtree( |
---|
82 | const rtems_rbtree_node *node |
---|
83 | ) |
---|
84 | { |
---|
85 | return _RBTree_Is_node_off_rbtree( node ); |
---|
86 | } |
---|
87 | |
---|
88 | /** |
---|
89 | * @brief Is the RBTree Node Pointer NULL |
---|
90 | * |
---|
91 | * This function returns true if @a the_node is NULL and false otherwise. |
---|
92 | */ |
---|
93 | RTEMS_INLINE_ROUTINE bool rtems_rbtree_is_null_node( |
---|
94 | const rtems_rbtree_node *the_node |
---|
95 | ) |
---|
96 | { |
---|
97 | return _RBTree_Is_null_node( the_node ); |
---|
98 | } |
---|
99 | |
---|
100 | /** |
---|
101 | * @brief Return pointer to RBTree Root |
---|
102 | * |
---|
103 | * This function returns a pointer to the root node of @a the_rbtree. |
---|
104 | */ |
---|
105 | RTEMS_INLINE_ROUTINE rtems_rbtree_node *rtems_rbtree_root( |
---|
106 | rtems_rbtree_control *the_rbtree |
---|
107 | ) |
---|
108 | { |
---|
109 | return _RBTree_Root( the_rbtree ); |
---|
110 | } |
---|
111 | |
---|
112 | /** |
---|
113 | * @brief Return pointer to RBTree Minimum |
---|
114 | * |
---|
115 | * This function returns a pointer to the minimum node of @a the_rbtree. |
---|
116 | */ |
---|
117 | RTEMS_INLINE_ROUTINE rtems_rbtree_node *rtems_rbtree_min( |
---|
118 | rtems_rbtree_control *the_rbtree |
---|
119 | ) |
---|
120 | { |
---|
121 | return _RBTree_First( the_rbtree, RBT_LEFT ); |
---|
122 | } |
---|
123 | |
---|
124 | /** |
---|
125 | * @brief Return pointer to RBTree Maximum |
---|
126 | * |
---|
127 | * This function returns a pointer to the maximum node of @a the_rbtree. |
---|
128 | */ |
---|
129 | RTEMS_INLINE_ROUTINE rtems_rbtree_node *rtems_rbtree_max( |
---|
130 | rtems_rbtree_control *the_rbtree |
---|
131 | ) |
---|
132 | { |
---|
133 | return _RBTree_First( the_rbtree, RBT_RIGHT ); |
---|
134 | } |
---|
135 | |
---|
136 | /** |
---|
137 | * @brief Return pointer to the left child node from this node |
---|
138 | * |
---|
139 | * This function returns a pointer to the left child node of @a the_node. |
---|
140 | */ |
---|
141 | RTEMS_INLINE_ROUTINE rtems_rbtree_node *rtems_rbtree_left( |
---|
142 | rtems_rbtree_node *the_node |
---|
143 | ) |
---|
144 | { |
---|
145 | return _RBTree_Left( the_node ); |
---|
146 | } |
---|
147 | |
---|
148 | /** |
---|
149 | * @brief Return pointer to the right child node from this node |
---|
150 | * |
---|
151 | * This function returns a pointer to the right child node of @a the_node. |
---|
152 | */ |
---|
153 | RTEMS_INLINE_ROUTINE rtems_rbtree_node *rtems_rbtree_right( |
---|
154 | rtems_rbtree_node *the_node |
---|
155 | ) |
---|
156 | { |
---|
157 | return _RBTree_Right( the_node ); |
---|
158 | } |
---|
159 | |
---|
160 | /** |
---|
161 | * @brief Return pointer to the parent child node from this node |
---|
162 | * |
---|
163 | * This function returns a pointer to the parent node of @a the_node. |
---|
164 | */ |
---|
165 | RTEMS_INLINE_ROUTINE rtems_rbtree_node *rtems_rbtree_parent( |
---|
166 | rtems_rbtree_node *the_node |
---|
167 | ) |
---|
168 | { |
---|
169 | return _RBTree_Parent( the_node ); |
---|
170 | } |
---|
171 | |
---|
172 | /** |
---|
173 | * @brief Are Two Nodes Equal |
---|
174 | * |
---|
175 | * This function returns true if @a left and @a right are equal, |
---|
176 | * and false otherwise. |
---|
177 | */ |
---|
178 | RTEMS_INLINE_ROUTINE bool rtems_rbtree_are_nodes_equal( |
---|
179 | const rtems_rbtree_node *left, |
---|
180 | const rtems_rbtree_node *right |
---|
181 | ) |
---|
182 | { |
---|
183 | return _RBTree_Are_nodes_equal( left, right ); |
---|
184 | } |
---|
185 | |
---|
186 | /** |
---|
187 | * @brief Is the RBTree Empty |
---|
188 | * |
---|
189 | * This function returns true if there a no nodes on @a the_rbtree and |
---|
190 | * false otherwise. |
---|
191 | */ |
---|
192 | RTEMS_INLINE_ROUTINE bool rtems_rbtree_is_empty( |
---|
193 | rtems_rbtree_control *the_rbtree |
---|
194 | ) |
---|
195 | { |
---|
196 | return _RBTree_Is_empty( the_rbtree ); |
---|
197 | } |
---|
198 | |
---|
199 | /** |
---|
200 | * @brief Is this the Minimum Node on the RBTree |
---|
201 | * |
---|
202 | * This function returns true if @a the_node is the min node on @a the_rbtree |
---|
203 | * and false otherwise. |
---|
204 | */ |
---|
205 | RTEMS_INLINE_ROUTINE bool rtems_rbtree_is_min( |
---|
206 | rtems_rbtree_control *the_rbtree, |
---|
207 | const rtems_rbtree_node *the_node |
---|
208 | ) |
---|
209 | { |
---|
210 | return _RBTree_Is_first( the_rbtree, the_node, RBT_LEFT ); |
---|
211 | } |
---|
212 | |
---|
213 | /** |
---|
214 | * @brief Is this the Maximum Node on the RBTree |
---|
215 | * |
---|
216 | * This function returns true if @a the_node is the max node on @a the_rbtree |
---|
217 | * and false otherwise. |
---|
218 | */ |
---|
219 | RTEMS_INLINE_ROUTINE bool rtems_rbtree_is_max( |
---|
220 | rtems_rbtree_control *the_rbtree, |
---|
221 | const rtems_rbtree_node *the_node |
---|
222 | ) |
---|
223 | { |
---|
224 | return _RBTree_Is_first( the_rbtree, the_node, RBT_RIGHT ); |
---|
225 | } |
---|
226 | |
---|
227 | |
---|
228 | /** |
---|
229 | * @brief Does this RBTree have only One Node |
---|
230 | * |
---|
231 | * This function returns true if there is only one node on @a the_rbtree and |
---|
232 | * false otherwise. |
---|
233 | */ |
---|
234 | RTEMS_INLINE_ROUTINE bool rtems_rbtree_has_only_one_node( |
---|
235 | const rtems_rbtree_control *the_rbtree |
---|
236 | ) |
---|
237 | { |
---|
238 | return _RBTree_Has_only_one_node( the_rbtree ); |
---|
239 | } |
---|
240 | |
---|
241 | /** |
---|
242 | * @brief Is this Node the RBTree Root |
---|
243 | * |
---|
244 | * This function returns true if @a the_node is the root of @a the_rbtree and |
---|
245 | * false otherwise. |
---|
246 | */ |
---|
247 | RTEMS_INLINE_ROUTINE bool rtems_rbtree_is_root( |
---|
248 | rtems_rbtree_control *the_rbtree, |
---|
249 | const rtems_rbtree_node *the_node |
---|
250 | ) |
---|
251 | { |
---|
252 | return _RBTree_Is_root( the_rbtree, the_node ); |
---|
253 | } |
---|
254 | |
---|
255 | /** @brief Find the node with given key in the tree |
---|
256 | * |
---|
257 | * This function returns a pointer to the node having key equal to the key |
---|
258 | * of @a the_node if it exists within @a the_rbtree, and NULL if not. |
---|
259 | * @a the_node has to be made up before a search. |
---|
260 | */ |
---|
261 | RTEMS_INLINE_ROUTINE rtems_rbtree_node* rtems_rbtree_find( |
---|
262 | rtems_rbtree_control *the_rbtree, |
---|
263 | rtems_rbtree_node *the_node |
---|
264 | ) |
---|
265 | { |
---|
266 | return _RBTree_Find( the_rbtree, the_node ); |
---|
267 | } |
---|
268 | |
---|
269 | /** @brief Find the node's in-order predecessor |
---|
270 | * |
---|
271 | * This function returns a pointer to the in-order predecessor |
---|
272 | * of @a the_node if it exists, and NULL if not. |
---|
273 | */ |
---|
274 | RTEMS_INLINE_ROUTINE rtems_rbtree_node* rtems_rbtree_predecessor( |
---|
275 | rtems_rbtree_node *the_node |
---|
276 | ) |
---|
277 | { |
---|
278 | return _RBTree_Predecessor( the_node ); |
---|
279 | } |
---|
280 | |
---|
281 | /** @brief Find the node's in-order successor |
---|
282 | * |
---|
283 | * This function returns a pointer to the in-order successor |
---|
284 | * of @a the_node if it exists, and NULL if not. |
---|
285 | */ |
---|
286 | RTEMS_INLINE_ROUTINE rtems_rbtree_node* rtems_rbtree_successor( |
---|
287 | rtems_rbtree_node *the_node |
---|
288 | ) |
---|
289 | { |
---|
290 | return _RBTree_Successor( the_node ); |
---|
291 | } |
---|
292 | |
---|
293 | /** |
---|
294 | * @brief Extract the specified node from a rbtree |
---|
295 | * |
---|
296 | * This routine extracts @a the_node from @a the_rbtree on which it resides. |
---|
297 | * It disables interrupts to ensure the atomicity of the extract operation. |
---|
298 | */ |
---|
299 | RTEMS_INLINE_ROUTINE void rtems_rbtree_extract( |
---|
300 | rtems_rbtree_control *the_rbtree, |
---|
301 | rtems_rbtree_node *the_node |
---|
302 | ) |
---|
303 | { |
---|
304 | _RBTree_Extract( the_rbtree, the_node ); |
---|
305 | } |
---|
306 | |
---|
307 | /** |
---|
308 | * @brief Obtain the min node on a rbtree |
---|
309 | * |
---|
310 | * This function removes the min node from @a the_rbtree and returns |
---|
311 | * a pointer to that node. If @a the_rbtree is empty, then NULL is returned. |
---|
312 | * It disables interrupts to ensure the atomicity of the get operation. |
---|
313 | */ |
---|
314 | RTEMS_INLINE_ROUTINE rtems_rbtree_node *rtems_rbtree_get_min( |
---|
315 | rtems_rbtree_control *the_rbtree |
---|
316 | ) |
---|
317 | { |
---|
318 | return _RBTree_Get( the_rbtree, RBT_LEFT ); |
---|
319 | } |
---|
320 | |
---|
321 | /** |
---|
322 | * @brief Obtain the max node on a rbtree |
---|
323 | * |
---|
324 | * This function removes the max node from @a the_rbtree and returns |
---|
325 | * a pointer to that node. If @a the_rbtree is empty, then NULL is returned. |
---|
326 | * It disables interrupts to ensure the atomicity of the get operation. |
---|
327 | */ |
---|
328 | RTEMS_INLINE_ROUTINE rtems_rbtree_node *rtems_rbtree_get_max( |
---|
329 | rtems_rbtree_control *the_rbtree |
---|
330 | ) |
---|
331 | { |
---|
332 | return _RBTree_Get( the_rbtree, RBT_RIGHT ); |
---|
333 | } |
---|
334 | |
---|
335 | /** |
---|
336 | * @brief Peek at the min node on a rbtree |
---|
337 | * |
---|
338 | * This function returns a pointer to the min node from @a the_rbtree |
---|
339 | * without changing the tree. If @a the_rbtree is empty, |
---|
340 | * then NULL is returned. |
---|
341 | * It disables interrupts to ensure the atomicity of the peek operation. |
---|
342 | */ |
---|
343 | RTEMS_INLINE_ROUTINE rtems_rbtree_node *rtems_rbtree_peek_min( |
---|
344 | rtems_rbtree_control *the_rbtree |
---|
345 | ) |
---|
346 | { |
---|
347 | return _RBTree_Peek( the_rbtree, RBT_LEFT ); |
---|
348 | } |
---|
349 | |
---|
350 | /** |
---|
351 | * @brief Peek at the max node on a rbtree |
---|
352 | * |
---|
353 | * This function returns a pointer to the max node from @a the_rbtree |
---|
354 | * without changing the tree. If @a the_rbtree is empty, |
---|
355 | * then NULL is returned. |
---|
356 | * It disables interrupts to ensure the atomicity of the peek operation. |
---|
357 | */ |
---|
358 | RTEMS_INLINE_ROUTINE rtems_rbtree_node *rtems_rbtree_peek_max( |
---|
359 | rtems_rbtree_control *the_rbtree |
---|
360 | ) |
---|
361 | { |
---|
362 | return _RBTree_Peek( the_rbtree, RBT_RIGHT ); |
---|
363 | } |
---|
364 | |
---|
365 | |
---|
366 | /** |
---|
367 | * @brief Find the control header of the tree containing a given node. |
---|
368 | * |
---|
369 | * This routine finds the rtems_rbtree_control structure of the tree |
---|
370 | * containing @a the_node. |
---|
371 | * It disables interrupts to ensure the atomicity of the find operation. |
---|
372 | */ |
---|
373 | RTEMS_INLINE_ROUTINE rtems_rbtree_control *rtems_rbtree_find_header( |
---|
374 | rtems_rbtree_node *the_node |
---|
375 | ) |
---|
376 | { |
---|
377 | return(_RBTree_Find_header( the_node )); |
---|
378 | } |
---|
379 | |
---|
380 | /** |
---|
381 | * @brief Insert a node on a rbtree |
---|
382 | * |
---|
383 | * This routine inserts @a the_node on @a the_rbtree. |
---|
384 | * It disables interrupts to ensure the atomicity of the insert operation. |
---|
385 | */ |
---|
386 | RTEMS_INLINE_ROUTINE void rtems_rbtree_insert( |
---|
387 | rtems_rbtree_control *the_rbtree, |
---|
388 | rtems_rbtree_node *the_node |
---|
389 | ) |
---|
390 | { |
---|
391 | _RBTree_Insert( the_rbtree, the_node ); |
---|
392 | } |
---|
393 | |
---|
394 | #endif |
---|
395 | /* end of include file */ |
---|