bt-int.h File Reference

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  bti_node

Functions

int BTI_init (struct bti_node **n)
int BTI_add (struct bti_node **n, int value)
int BTI_dump (struct bti_node **n)
int BTI_done (struct bti_node **n)


Function Documentation

int BTI_add ( struct bti_node **  n,
int  value 
)

Definition at line 17 of file bt-int.c.

References bti_node::data, data, dir, bti_node::l, MALLOC, n, NULL, p, and bti_node::r.

Referenced by OLE_follow_chain().

00018 {
00019         int collision = 0;
00020         int dir = 0;
00021         struct bti_node *p = NULL, *node = *n;
00022 
00023         /*      fprintf(stdout,"Adding %d to %p\n", value, *n);*/
00024         while (node != NULL)
00025         {
00026                 if (value > node->data) { p = node; dir=1;  node = node->r; }
00027                 else if (value < node->data) { p = node; dir=-1; node = node->l; }
00028                 else if (value == node->data) 
00029                 {
00030                         collision = 1;
00031                         break;
00032                 }
00033         }
00034 
00035         if (collision == 0)
00036         {
00037                 struct bti_node *leaf;
00038 
00039                 leaf = MALLOC(sizeof(struct bti_node));
00040                 if (leaf == NULL)
00041                 {
00042                         return -1;
00043                 }
00044 
00045                 leaf->data = value;
00046                 leaf->l = leaf->r = NULL;
00047 
00048                 if (p != NULL)
00049                 {
00050                         switch (dir) {
00051                                 case 1: 
00052                                         p->r = leaf;
00053                                         break;
00054                                 case -1: 
00055                                         p->l = leaf;
00056                                         break;
00057                         }
00058                 } else {
00059                         *n = leaf;
00060                 }
00061 
00062 
00063         }
00064 
00065         return collision;
00066 }

Here is the caller graph for this function:

int BTI_done ( struct bti_node **  n  ) 

Definition at line 83 of file bt-int.c.

References BTI_done(), FREE, bti_node::l, n, NULL, and bti_node::r.

Referenced by BTI_done(), and OLE_follow_chain().

00084 {
00085         struct bti_node *node;
00086 
00087         if (n == NULL) return 0;
00088         if (*n == NULL) return 0;
00089 
00090         node = *n;
00091         
00092         if (node->l) BTI_done(&(node->l)); 
00093         if (node->r) BTI_done(&(node->r));
00094         if (*n) { FREE(*n); *n = NULL; }
00095 
00096         return 0;
00097 }

Here is the call graph for this function:

Here is the caller graph for this function:

int BTI_dump ( struct bti_node **  n  ) 

Definition at line 69 of file bt-int.c.

References BTI_dump(), bti_node::data, bti_node::l, n, and bti_node::r.

Referenced by BTI_dump().

00070 {
00071                 struct bti_node *node;
00072 
00073         node = *n;
00074         
00075         if (node->l) BTI_dump(&(node->l)); 
00076         if (*n) { fprintf(stdout,"%d, ", node->data); }
00077         if (node->r) BTI_dump(&(node->r));
00078 
00079         return 0;
00080 
00081 }

Here is the call graph for this function:

Here is the caller graph for this function:

int BTI_init ( struct bti_node **  n  ) 

Definition at line 10 of file bt-int.c.

References n, and NULL.

Referenced by OLE_follow_chain().

00011 {
00012         *n = NULL;
00013 
00014         return 0;
00015 }

Here is the caller graph for this function:


Generated on Sun Mar 4 15:18:44 2007 for Scilab [trunk] by  doxygen 1.5.1