source: rtems/cpukit/score/src/rbtreefind.c @ 8c25e04

5
Last change on this file since 8c25e04 was 60fe374, checked in by Sebastian Huber <sebastian.huber@…>, on 08/03/14 at 11:02:58

rbtree: Add and use RBTree_Compare_result

  • Property mode set to 100644
File size: 1.0 KB
Line 
1/**
2 * @file
3 *
4 * @brief Find the control structure of the tree containing the given node
5 * @ingroup ScoreRBTree
6 */
7
8/*
9 *  Copyright (c) 2010 Gedare Bloom.
10 *
11 *  The license and distribution terms for this file may be
12 *  found in the file LICENSE in this distribution or at
13 *  http://www.rtems.org/license/LICENSE.
14 */
15
16#if HAVE_CONFIG_H
17#include "config.h"
18#endif
19
20#include <rtems/score/rbtreeimpl.h>
21
22RBTree_Node *_RBTree_Find(
23  const RBTree_Control *the_rbtree,
24  const RBTree_Node    *the_node,
25  RBTree_Compare        compare,
26  bool                  is_unique
27)
28{
29  RBTree_Node *iter_node = the_rbtree->root;
30  RBTree_Node *found = NULL;
31
32  while ( iter_node != NULL ) {
33    RBTree_Compare_result compare_result = ( *compare )( the_node, iter_node );
34    RBTree_Direction      dir;
35
36    if ( _RBTree_Is_equal( compare_result ) ) {
37      found = iter_node;
38
39      if ( is_unique )
40        break;
41    }
42
43    dir = (RBTree_Direction) _RBTree_Is_greater( compare_result );
44    iter_node = iter_node->child[ dir ];
45  }
46
47  return found;
48}
Note: See TracBrowser for help on using the repository browser.