source: rtems/cpukit/score/src/rbtreefind.c @ f031df0e

4.115
Last change on this file since f031df0e was 93fb3cb0, checked in by Sebastian Huber <sebastian.huber@…>, on 07/23/13 at 08:38:11

score: Create rbtree implementation header

Move implementation specific parts of rbtree.h and rbtree.inl into new
header file rbtreeimpl.h. The rbtree.h contains now only the
application visible API.

  • Property mode set to 100644
File size: 1.3 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.com/license/LICENSE.
14 */
15
16#if HAVE_CONFIG_H
17#include "config.h"
18#endif
19
20#include <rtems/score/rbtreeimpl.h>
21#include <rtems/score/isr.h>
22
23RBTree_Node *_RBTree_Find(
24  const RBTree_Control *the_rbtree,
25  const RBTree_Node *search_node
26)
27{
28  ISR_Level          level;
29  RBTree_Node *return_node;
30
31  return_node = NULL;
32  _ISR_Disable( level );
33      return_node = _RBTree_Find_unprotected( the_rbtree, search_node );
34  _ISR_Enable( level );
35  return return_node;
36}
37
38RBTree_Node *_RBTree_Find_unprotected(
39  const RBTree_Control *the_rbtree,
40  const RBTree_Node *the_node
41)
42{
43  RBTree_Node* iter_node = the_rbtree->root;
44  RBTree_Node* found = NULL;
45  int compare_result;
46  while (iter_node) {
47    compare_result = the_rbtree->compare_function(the_node, iter_node);
48    if ( _RBTree_Is_equal( compare_result ) ) {
49      found = iter_node;
50      if ( the_rbtree->is_unique )
51        break;
52    }
53
54    RBTree_Direction dir =
55      (RBTree_Direction) _RBTree_Is_greater( compare_result );
56    iter_node = iter_node->child[dir];
57  } /* while(iter_node) */
58
59  return found;
60}
Note: See TracBrowser for help on using the repository browser.