source: rtems-docs/c-user/red_black_trees.rst @ 969e60e

5
Last change on this file since 969e60e was 6c56401, checked in by Chris Johns <chrisj@…>, on 11/12/17 at 03:34:48

c-user: Fix index locations.

Update #3229.

  • Property mode set to 100644
File size: 4.4 KB
Line 
1.. comment SPDX-License-Identifier: CC-BY-SA-4.0
2
3.. COMMENT: COPYRIGHT (c) 1988-2012.
4.. COMMENT: On-Line Applications Research Corporation (OAR).
5.. COMMENT: All rights reserved.
6
7.. index:: Red-Black Trees
8.. index:: rbtrees
9
10Red-Black Trees
11***************
12
13Introduction
14============
15
16The Red-Black Tree API is an interface to the SuperCore (score) rbtree
17implementation. Within RTEMS, red-black trees are used when a binary search
18tree is needed, including dynamic priority thread queues and non-contiguous
19heap memory. The Red-Black Tree API provided by RTEMS is:
20
21- ``rtems_rtems_rbtree_node`` - Red-Black Tree node embedded in another struct
22
23- ``rtems_rtems_rbtree_control`` - Red-Black Tree control node for an entire tree
24
25- ``rtems_rtems_rbtree_initialize`` - initialize the red-black tree with nodes
26
27- ``rtems_rtems_rbtree_initialize_empty`` - initialize the red-black tree as empty
28
29- ``rtems_rtems_rbtree_set_off_tree`` - Clear a node's links
30
31- ``rtems_rtems_rbtree_root`` - Return the red-black tree's root node
32
33- ``rtems_rtems_rbtree_min`` - Return the red-black tree's minimum node
34
35- ``rtems_rtems_rbtree_max`` - Return the red-black tree's maximum node
36
37- ``rtems_rtems_rbtree_left`` - Return a node's left child node
38
39- ``rtems_rtems_rbtree_right`` - Return a node's right child node
40
41- ``rtems_rtems_rbtree_parent`` - Return a node's parent node
42
43- ``rtems_rtems_rbtree_are_nodes_equal`` - Are the node's equal ?
44
45- ``rtems_rtems_rbtree_is_empty`` - Is the red-black tree empty ?
46
47- ``rtems_rtems_rbtree_is_min`` - Is the Node the minimum in the red-black tree ?
48
49- ``rtems_rtems_rbtree_is_max`` - Is the Node the maximum in the red-black tree ?
50
51- ``rtems_rtems_rbtree_is_root`` - Is the Node the root of the red-black tree ?
52
53- ``rtems_rtems_rbtree_find`` - Find the node with a matching key in the red-black tree
54
55- ``rtems_rtems_rbtree_predecessor`` - Return the in-order predecessor of a node.
56
57- ``rtems_rtems_rbtree_successor`` - Return the in-order successor of a node.
58
59- ``rtems_rtems_rbtree_extract`` - Remove the node from the red-black tree
60
61- ``rtems_rtems_rbtree_get_min`` - Remove the minimum node from the red-black tree
62
63- ``rtems_rtems_rbtree_get_max`` - Remove the maximum node from the red-black tree
64
65- ``rtems_rtems_rbtree_peek_min`` - Returns the minimum node from the red-black tree
66
67- ``rtems_rtems_rbtree_peek_max`` - Returns the maximum node from the red-black tree
68
69- ``rtems_rtems_rbtree_insert`` - Add the node to the red-black tree
70
71Background
72==========
73
74The Red-Black Trees API is a thin layer above the SuperCore Red-Black Trees
75implementation. A Red-Black Tree is defined by a control node with pointers to
76the root, minimum, and maximum nodes in the tree. Each node in the tree
77consists of a parent pointer, two children pointers, and a color attribute.  A
78tree is parameterized as either unique, meaning identical keys are rejected, or
79not, in which case duplicate keys are allowed.
80
81Users must provide a comparison functor that gets passed to functions that need
82to compare nodes. In addition, no internal synchronization is offered within
83the red-black tree implementation, thus users must ensure at most one thread
84accesses a red-black tree instance at a time.
85
86Nodes
87-----
88
89A red-black tree is made up from nodes that orginate from a red-black tree
90control object. A node is of type ``rtems_rtems_rbtree_node``. The node is
91designed to be part of a user data structure. To obtain the encapsulating
92structure users can use the ``RTEMS_CONTAINER_OF`` macro.  The node can be
93placed anywhere within the user's structure and the macro will calculate the
94structure's address from the node's address.
95
96Controls
97--------
98
99A red-black tree is rooted with a control object. Red-Black Tree control
100provide the user with access to the nodes on the red-black tree.  The
101implementation does not require special checks for manipulating the root of the
102red-black tree. To accomplish this the ``rtems_rtems_rbtree_control`` structure
103is treated as a ``rtems_rtems_rbtree_node`` structure with a ``NULL`` parent
104and left child pointing to the root.
105
106Operations
107==========
108
109Examples for using the red-black trees can be found in the
110``testsuites/sptests/sprbtree01/init.c`` file.
111
112Directives
113==========
114
115.. index:: rbtree doc
116
117Documentation for the Red-Black Tree Directives
118-----------------------------------------------
119
120Source documentation for the Red-Black Tree API can be found in the generated
121Doxygen output for ``cpukit/sapi``.
Note: See TracBrowser for help on using the repository browser.