Multi-ApplicationOnlineProfiling  2.1
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Binary_Tree.c
Go to the documentation of this file.
1 /* ############################ MALP License ############################## */
2 /* # Fri Jan 18 14:00:00 CET 2013 # */
3 /* # Copyright or (C) or Copr. Commissariat a l'Energie Atomique # */
4 /* # # */
5 /* # This software is governed by the CeCILL-C license under French law # */
6 /* # and abiding by the rules of distribution of free software. You can # */
7 /* # use, modify and/ or redistribute the software under the terms of # */
8 /* # the CeCILL-C license as circulated by CEA, CNRS and INRIA at the # */
9 /* # following URL http://www.cecill.info. # */
10 /* # # */
11 /* # The fact that you are presently reading this means that you have # */
12 /* # had knowledge of the CeCILL-C license and that you accept its # */
13 /* # terms. # */
14 /* # # */
15 /* # Authors: # */
16 /* # - BESNARD Jean-Baptiste jean-baptiste.besnard@cea.fr # */
17 /* # # */
18 /* ######################################################################## */
19 
20 #include "Binary_Tree.h"
21 
22 void Binary_Tree_init(struct Binary_Tree *bt, int rank, int size)
23 {
24 
25  bt->rank = rank;
26  bt->size = size;
27 
28 
29  /* Build a binary tree */
30 
31  int tree_rank = rank + 1;
32 
33  /* 0 Has no parent */
34  if( rank )
35  {
36  bt->parent = (tree_rank / 2) - 1;
37  }
38  else
39  {
40  bt->parent = -1;
41  }
42 
43  /* Is left child in limits */
44  if( ( ( tree_rank * 2 ) - 1 ) < size )
45  {
46  bt->left_child = ( ( tree_rank * 2 ) - 1 );
47  }
48  else
49  {
50  bt->left_child = -1;
51  }
52 
53  /* Is right child in limits */
54  if( ( tree_rank * 2 ) < size )
55  {
56  bt->right_child = ( tree_rank * 2 );
57  }
58  else
59  {
60  bt->right_child = -1;
61  }
62 
63 }
64 
65 
66 
68 {
69  bt->rank = -1;
70  bt->size = 0;
71  bt->parent = -1;
72  bt->left_child = -1;
73  bt->right_child = -1;
74 }
int parent
The rank of the parent.
Definition: Binary_Tree.h:42
void Binary_Tree_init(struct Binary_Tree *bt, int rank, int size)
Initialization of a binary tree.
Definition: Binary_Tree.c:22
int rank
The rank of the element.
Definition: Binary_Tree.h:38
Struct defining a binary tree.
Definition: Binary_Tree.h:36
int right_child
The rank of the right child.
Definition: Binary_Tree.h:41
void Binary_Tree_release(struct Binary_Tree *bt)
releases a binary tree
Definition: Binary_Tree.c:67
int size
The size of the element.
Definition: Binary_Tree.h:39
int left_child
The rank of the left child.
Definition: Binary_Tree.h:40