diff options
author | Sebastian Huber <sebastian.huber@embedded-brains.de> | 2016-03-31 13:30:38 +0200 |
---|---|---|
committer | Sebastian Huber <sebastian.huber@embedded-brains.de> | 2016-04-01 07:35:18 +0200 |
commit | 97127aa119176be3533d1165d66966b74d226f82 (patch) | |
tree | 194aad4b0e1f58303527084cff91aa207748599d /cpukit/score/include/rtems/score/rbtree.h | |
parent | score: _User_extensions_Remove_set() (diff) | |
download | rtems-97127aa119176be3533d1165d66966b74d226f82.tar.bz2 |
score: Add and use _RBTree_Find_inline()
Diffstat (limited to 'cpukit/score/include/rtems/score/rbtree.h')
-rw-r--r-- | cpukit/score/include/rtems/score/rbtree.h | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/cpukit/score/include/rtems/score/rbtree.h b/cpukit/score/include/rtems/score/rbtree.h index 7e41c7a4c5..111b231500 100644 --- a/cpukit/score/include/rtems/score/rbtree.h +++ b/cpukit/score/include/rtems/score/rbtree.h @@ -483,6 +483,47 @@ void _RBTree_Replace_node( RBTree_Node *replacement ); +/** + * @brief Finds a node in the red-black tree with the specified key. + * + * @param the_rbtree The red-black tree control. + * @param key The key to look after. + * @param equal Must return true if the specified key equals the key of the + * node, otherwise false. + * @param less Must return true if the specified key is less than the key of + * the node, otherwise false. + * + * @retval node A node with the specified key. + * @retval NULL No node with the specified key exists in the red-black tree. + */ +RTEMS_INLINE_ROUTINE RBTree_Node *_RBTree_Find_inline( + RBTree_Control *the_rbtree, + const void *key, + bool ( *equal )( const void *, const RBTree_Node * ), + bool ( *less )( const void *, const RBTree_Node * ) +) +{ + RBTree_Node **link; + RBTree_Node *parent; + + link = _RBTree_Root_reference( the_rbtree ); + parent = NULL; + + while ( *link != NULL ) { + parent = *link; + + if ( ( *equal )( key, parent ) ) { + return parent; + } else if ( ( *less )( key, parent ) ) { + link = _RBTree_Left_reference( parent ); + } else { + link = _RBTree_Right_reference( parent ); + } + } + + return NULL; +} + /**@}*/ #ifdef __cplusplus |