diff options
author | Sebastian Huber <sebastian.huber@embedded-brains.de> | 2016-06-17 07:50:01 +0200 |
---|---|---|
committer | Sebastian Huber <sebastian.huber@embedded-brains.de> | 2016-06-22 14:37:11 +0200 |
commit | 69a6802bfa8878d3e9a8296c1516ff5feac77bbc (patch) | |
tree | 13b6fa37a0858315315665621e2714b4a5d1caf2 /cpukit/sapi/src | |
parent | score: Move _RBTree_Insert() (diff) | |
download | rtems-69a6802bfa8878d3e9a8296c1516ff5feac77bbc.tar.bz2 |
score: Move _RBTree_Find()
The _RBTree_Find() is no longer used in the score. Move it to sapi and
make it rtems_rbtree_find(). Move corresponding types and support
functions to sapi.
Diffstat (limited to 'cpukit/sapi/src')
-rw-r--r-- | cpukit/sapi/src/rbtreefind.c | 51 | ||||
-rw-r--r-- | cpukit/sapi/src/rbtreeinsert.c | 16 |
2 files changed, 59 insertions, 8 deletions
diff --git a/cpukit/sapi/src/rbtreefind.c b/cpukit/sapi/src/rbtreefind.c new file mode 100644 index 0000000000..d3f67a6462 --- /dev/null +++ b/cpukit/sapi/src/rbtreefind.c @@ -0,0 +1,51 @@ +/** + * @file + * + * @brief Find the control structure of the tree containing the given node + * @ingroup Scorertems_rbtree + */ + +/* + * Copyright (c) 2010 Gedare Bloom. + * + * The license and distribution terms for this file may be + * found in the file LICENSE in this distribution or at + * http://www.rtems.org/license/LICENSE. + */ + +#if HAVE_CONFIG_H +#include "config.h" +#endif + +#include <rtems/rbtree.h> + +rtems_rbtree_node *rtems_rbtree_find( + const rtems_rbtree_control *the_rbtree, + const rtems_rbtree_node *the_node, + rtems_rbtree_compare compare, + bool is_unique +) +{ + rtems_rbtree_node *iter_node = rtems_rbtree_root( the_rbtree ); + rtems_rbtree_node *found = NULL; + + while ( iter_node != NULL ) { + rtems_rbtree_compare_result compare_result = + ( *compare )( the_node, iter_node ); + + if ( rtems_rbtree_is_equal( compare_result ) ) { + found = iter_node; + + if ( is_unique ) + break; + } + + if ( rtems_rbtree_is_greater( compare_result ) ) { + iter_node = rtems_rbtree_right( iter_node ); + } else { + iter_node = rtems_rbtree_left( iter_node ); + } + } + + return found; +} diff --git a/cpukit/sapi/src/rbtreeinsert.c b/cpukit/sapi/src/rbtreeinsert.c index a4850ff4cf..38b2f5b4ca 100644 --- a/cpukit/sapi/src/rbtreeinsert.c +++ b/cpukit/sapi/src/rbtreeinsert.c @@ -14,19 +14,19 @@ #include <rtems/score/rbtreeimpl.h> RTEMS_STATIC_ASSERT( - sizeof( RBTree_Compare_result ) >= sizeof( intptr_t ), - RBTree_Compare_result_intptr_t + sizeof( rtems_rbtree_compare_result ) >= sizeof( intptr_t ), + rtems_rbtree_compare_result_intptr_t ); RTEMS_STATIC_ASSERT( - sizeof( RBTree_Compare_result ) >= sizeof( int32_t ), - RBTree_Compare_result_int32_t + sizeof( rtems_rbtree_compare_result ) >= sizeof( int32_t ), + rtems_rbtree_compare_result_int32_t ); rtems_rbtree_node *rtems_rbtree_insert( rtems_rbtree_control *the_rbtree, rtems_rbtree_node *the_node, - RBTree_Compare compare, + rtems_rbtree_compare compare, bool is_unique ) { @@ -34,16 +34,16 @@ rtems_rbtree_node *rtems_rbtree_insert( rtems_rbtree_node *parent = NULL; while ( *which != NULL ) { - RBTree_Compare_result compare_result; + rtems_rbtree_compare_result compare_result; parent = *which; compare_result = ( *compare )( the_node, parent ); - if ( is_unique && _RBTree_Is_equal( compare_result ) ) { + if ( is_unique && rtems_rbtree_is_equal( compare_result ) ) { return parent; } - if ( _RBTree_Is_lesser( compare_result ) ) { + if ( rtems_rbtree_is_lesser( compare_result ) ) { which = _RBTree_Left_reference( parent ); } else { which = _RBTree_Right_reference( parent ); |