From 69a6802bfa8878d3e9a8296c1516ff5feac77bbc Mon Sep 17 00:00:00 2001 From: Sebastian Huber Date: Fri, 17 Jun 2016 07:50:01 +0200 Subject: 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. --- cpukit/sapi/src/rbtreefind.c | 51 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 cpukit/sapi/src/rbtreefind.c (limited to 'cpukit/sapi/src/rbtreefind.c') 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_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; +} -- cgit v1.2.3