Data Structures | |
| struct | EGeBTree_t |
| Basic structure of a tree node, note that a node in a tree is in itself a (sub)tree. More... | |
Files | |
| file | eg_ebtree.ex.c |
| file | eg_ebtree.h |
Defines | |
| #define | EG_EBTREE_LEFT 1 |
| Left Child Index. | |
| #define | EG_EBTREE_PARENT 0 |
| Parent index. | |
| #define | EG_EBTREE_RIGHT 2 |
| Right Child Index. | |
| #define | EGeBTreeAddLeft(__parent, __child) |
| Add a left __child to a node in a tree. | |
| #define | EGeBTreeAddRight(__parent, __child) |
| Add a right child to a node in a tree. | |
| #define | EGeBTreeClear(__tn) |
| Free any internal memory (not allocated by the user) related to this structure. | |
| #define | EGeBTreeCut(__member) |
| Cut the given node from the tree containing it (and so create a sub-tree). | |
| #define | EGeBTreeDel(__leaf) |
| Erase a leaf node from a tree. | |
| #define | EGeBTreeGetFirst(__node) |
| return the first node in the (sub-)tree (according to the in-order). | |
| #define | EGeBTreeGetLast(__node) |
| return the last node in the (sub-)tree (according to the in-order). | |
| #define | EGeBTreeGetLeft(__member) ((__member)->cn[EG_EBTREE_LEFT]) |
| #define | EGeBTreeGetNext(__node) |
| return the successor of the given node in it's tree according to the in-order ordering. | |
| #define | EGeBTreeGetParent(__member) ((__member)->cn[EG_EBTREE_PARENT]) |
| #define | EGeBTreeGetPrev(__node) |
| return the predecesor of the given node in it's tree according to the in-order ordering. | |
| #define | EGeBTreeGetRight(__member) ((__member)->cn[EG_EBTREE_RIGHT]) |
| #define | EGeBTreeGetRoot(__member) |
| return the root of the tree containing the given tree node. | |
| #define | EGeBTreeInit(__tn) (*(__tn) = (EGeBTree_t){{0,0,0}}) |
| Initialize a tree structure. It let it as a tree containing only itself. and allocate any internal memory (not allocated by the user). | |
| #define | EGeBTreeReplace(__old, __rep) |
| Replace a node in a tree. | |
| #define | EGeBTreeReset(__tn) EGeBTreeInit(__tn) |
| Let a tree just as after an init call. | |
Typedefs | |
| typedef struct EGeBTree_t | EGeBTree_t |
| Basic structure of a tree node, note that a node in a tree is in itself a (sub)tree. | |
Functions | |
| static int | ebt_display (EGioFile_t *out_f, EGeBTree_t *root) |
| display the given tree in-order. | |
| static int | ebt_parseargs (int argc, char **argv, unsigned int *s, unsigned int *z) |
| parse external arguments. | |
| static void | ebt_usage (char const *const program) |
| usage function, if we give the wrong number of parameters, we return an error message and print a help. | |
| int | main (int argc, char **argv) |
| Tester program for the projection structure and functions. | |
Variables | |
| static int | verbose = 0 |
Here we define a minimal implementation of binary trees, using the philosophy of embeded structures. Operations as adding nodes (in any position of the tree), deleting nodes, splicing trees, and separating sub-trees are performed in O(1) time. To obtain this running time information such as depth is not stored in the nodes of the tree.
-2005-07-08
| #define EG_EBTREE_LEFT 1 |
Left Child Index.
Definition at line 50 of file eg_ebtree.h.
| #define EG_EBTREE_PARENT 0 |
Parent index.
Definition at line 46 of file eg_ebtree.h.
| #define EG_EBTREE_RIGHT 2 |
Right Child Index.
Definition at line 54 of file eg_ebtree.h.
| #define EGeBTreeAddLeft | ( | __parent, | ||
| __child | ||||
| ) |
({\
EGeBTree_t*const __EGeparent = (__parent);\
EGeBTree_t*const __EGechild = (__child);\
__EGeparent->cn[EG_EBTREE_LEFT] ? (fprintf(stderr,"Can't add left __child to "#__parent" because it already has a left __child, in %s:%s:%d\n",__func__,__FILE__,__LINE__),1): (__EGeparent->cn[EG_EBTREE_LEFT] = __EGechild, __EGechild->cn[EG_EBTREE_PARENT] = __EGeparent, 0);})
Add a left __child to a node in a tree.
| __parent | node to wich we will add a left child | |
| __child | node to be a left child |
Definition at line 105 of file eg_ebtree.h.
Referenced by main().
| #define EGeBTreeAddRight | ( | __parent, | ||
| __child | ||||
| ) |
({\
EGeBTree_t*const __EGeparent = (__parent);\
EGeBTree_t*const __EGechild = (__child);\
__EGeparent->cn[EG_EBTREE_RIGHT] ? (fprintf(stderr,"Can't add right __child to "#__parent" because it already has a right __child, in %s:%s:%d\n",__func__,__FILE__,__LINE__),1): (__EGeparent->cn[EG_EBTREE_RIGHT] = __EGechild, __EGechild->cn[EG_EBTREE_PARENT] = __EGeparent, 0);})
Add a right child to a node in a tree.
| __parent | node to wich we will add a right child | |
| __child | node to be a right child |
Definition at line 116 of file eg_ebtree.h.
Referenced by main().
| #define EGeBTreeClear | ( | __tn | ) |
Free any internal memory (not allocated by the user) related to this structure.
| __tn | tree to be cleared. |
Definition at line 97 of file eg_ebtree.h.
| #define EGeBTreeCut | ( | __member | ) |
({\
EGeBTree_t*const __EGeroot = (__member);\
EGeBTree_t*const __EGepar = __EGeroot->cn[EG_EBTREE_PARENT];\
if(__EGepar) \
{\
__EGeroot->cn[EG_EBTREE_PARENT] = 0; \
if(__EGepar->cn[EG_EBTREE_LEFT] == __EGeroot)\
__EGepar->cn[EG_EBTREE_LEFT] = 0;\
else __EGepar->cn[EG_EBTREE_RIGHT] = 0;\
}\
0;})
Cut the given node from the tree containing it (and so create a sub-tree).
| __member |
Definition at line 292 of file eg_ebtree.h.
Referenced by main().
| #define EGeBTreeDel | ( | __leaf | ) |
({\
EGeBTree_t*const __EGelf = (__leaf);\
EGeBTree_t*const __EGepar = __EGelf->cn[EG_EBTREE_PARENT];\
int __rval = 0;\
if(__EGelf->cn[EG_EBTREE_LEFT] || __EGelf->cn[EG_EBTREE_RIGHT]) __rval = 1;\
else if(__EGepar)\
{\
if(__EGepar->cn[EG_EBTREE_LEFT] == __EGelf) \
__EGepar->cn[EG_EBTREE_LEFT] = 0;\
else __EGepar->cn[EG_EBTREE_RIGHT] = 0;\
}\
__rval;})
Erase a leaf node from a tree.
| __leaf | node to be erased from the tree. |
Definition at line 273 of file eg_ebtree.h.
Referenced by main().
| #define EGeBTreeGetFirst | ( | __node | ) |
({\
EGeBTree_t* __EGecn = (__node);\
while(__EGecn->cn[EG_EBTREE_LEFT]) __EGecn = __EGecn->cn[EG_EBTREE_LEFT];\
__EGecn;})
return the first node in the (sub-)tree (according to the in-order).
| __node | pointer to a node of the tree. |
Definition at line 252 of file eg_ebtree.h.
Referenced by ebt_display().
| #define EGeBTreeGetLast | ( | __node | ) |
({\
EGeBTree_t* __EGecn = (__node);\
while(__EGecn->cn[EG_EBTREE_RIGHT]) __EGecn = __EGecn->cn[EG_EBTREE_RIGHT];\
__EGecn;})
return the last node in the (sub-)tree (according to the in-order).
| __node | pointer to a node of the tree. |
Definition at line 262 of file eg_ebtree.h.
Referenced by ebt_display().
| #define EGeBTreeGetLeft | ( | __member | ) | ((__member)->cn[EG_EBTREE_LEFT]) |
| __member | node for wich we are looking for the left child. |
Definition at line 135 of file eg_ebtree.h.
| #define EGeBTreeGetNext | ( | __node | ) |
({\
EGeBTree_t* __EGexn = (__node);\
EGeBTree_t* __EGecn = __EGexn->cn[EG_EBTREE_RIGHT];\
if(__EGecn) while(__EGecn->cn[EG_EBTREE_LEFT])\
__EGecn = __EGecn->cn[EG_EBTREE_LEFT];\
else do __EGecn = __EGexn->cn[EG_EBTREE_PARENT]; while(__EGecn && \
__EGecn->cn[EG_EBTREE_RIGHT] == __EGexn && (__EGexn = __EGecn));\
__EGecn;})
return the successor of the given node in it's tree according to the in-order ordering.
| __node | element for wich we want the successor. |
Definition at line 204 of file eg_ebtree.h.
Referenced by ebt_display().
| #define EGeBTreeGetParent | ( | __member | ) | ((__member)->cn[EG_EBTREE_PARENT]) |
| __member | node for wich we are looking for the father. |
Definition at line 127 of file eg_ebtree.h.
| #define EGeBTreeGetPrev | ( | __node | ) |
({\
EGeBTree_t* __EGexn = (__node);\
EGeBTree_t* __EGecn = __EGexn->cn[EG_EBTREE_LEFT];\
if(__EGecn) while(__EGecn->cn[EG_EBTREE_RIGHT])\
__EGecn = __EGecn->cn[EG_EBTREE_RIGHT];\
else do __EGecn = __EGexn->cn[EG_EBTREE_PARENT]; while(__EGecn && \
__EGecn->cn[EG_EBTREE_LEFT] == __EGexn && (__EGexn = __EGecn));\
__EGecn;})
return the predecesor of the given node in it's tree according to the in-order ordering.
| __node | element for wich we want the predecesor. |
Definition at line 238 of file eg_ebtree.h.
Referenced by ebt_display().
| #define EGeBTreeGetRight | ( | __member | ) | ((__member)->cn[EG_EBTREE_RIGHT]) |
| __member | node for wich we are looking for the right child. |
Definition at line 143 of file eg_ebtree.h.
| #define EGeBTreeGetRoot | ( | __member | ) |
({\
EGeBTree_t*__EGeroot = (__member);\
while(__EGeroot->cn[EG_EBTREE_PARENT]) \
__EGeroot = __EGeroot->cn[EG_EBTREE_PARENT];\
__EGeroot;})
return the root of the tree containing the given tree node.
| __member | node for wich we are looking for the tree-root. |
Definition at line 150 of file eg_ebtree.h.
| #define EGeBTreeInit | ( | __tn | ) | (*(__tn) = (EGeBTree_t){{0,0,0}}) |
Initialize a tree structure. It let it as a tree containing only itself. and allocate any internal memory (not allocated by the user).
| __tn | tree to initialize. |
Definition at line 81 of file eg_ebtree.h.
Referenced by main().
| #define EGeBTreeReplace | ( | __old, | ||
| __rep | ||||
| ) |
({\
EGeBTree_t*const __EGeold = (__old);\
EGeBTree_t*const __EGenew = (__rep);\
EGeBTree_t*const __EGepar = __EGeold->cn[EG_EBTREE_PARENT];\
EGeBTree_t*const __EGelft = __EGeold->cn[EG_EBTREE_LEFT];\
EGeBTree_t*const __EGergt = __EGeold->cn[EG_EBTREE_RIGHT];\
*__EGenew = *__EGeold;\
if(__EGepar)\
{\
if(__EGepar->cn[EG_EBTREE_LEFT] == __EGeold)\
__EGepar->cn[EG_EBTREE_LEFT] = __EGenew;\
else __EGepar->cn[EG_EBTREE_RIGHT] = __EGenew;\
}\
if(__EGelft) __EGelft->cn[EG_EBTREE_PARENT] = __EGenew;\
if(__EGergt) __EGergt->cn[EG_EBTREE_PARENT] = __EGenew;\
0;})
Replace a node in a tree.
| __old | node to be replaced. | |
| __rep | node to be used as replacement. |
Definition at line 162 of file eg_ebtree.h.
Referenced by main().
| #define EGeBTreeReset | ( | __tn | ) | EGeBTreeInit(__tn) |
Let a tree just as after an init call.
| __tn | tree to reset. |
Definition at line 89 of file eg_ebtree.h.
| typedef struct EGeBTree_t EGeBTree_t |
Basic structure of a tree node, note that a node in a tree is in itself a (sub)tree.
| static int ebt_display | ( | EGioFile_t * | out_f, | |
| EGeBTree_t * | root | |||
| ) | [static] |
display the given tree in-order.
| out_f | output stream. | |
| root | tree to display. |
Definition at line 96 of file eg_ebtree.ex.c.
References EGeBTreeGetFirst, EGeBTreeGetLast, EGeBTreeGetNext, EGeBTreeGetPrev, EGioPrintf(), and verbose.
Referenced by main().

| static int ebt_parseargs | ( | int | argc, | |
| char ** | argv, | |||
| unsigned int * | s, | |||
| unsigned int * | z | |||
| ) | [static] |
parse external arguments.
| argc | int, number of parameters to process. | |
| argv | char**, array of the parameters. | |
| z | unsigned int*, pointer to the number of elements in the tree. | |
| s | unsigned int*, pointer to the seed. |
Definition at line 51 of file eg_ebtree.ex.c.
References ebt_usage(), and verbose.
Referenced by main().

| static void ebt_usage | ( | char const *const | program | ) | [static] |
usage function, if we give the wrong number of parameters, we return an error message and print a help.
| program | Name of the command from comand-line |
Definition at line 32 of file eg_ebtree.ex.c.
Referenced by ebt_parseargs().
| int main | ( | int | argc, | |
| char ** | argv | |||
| ) |
Tester program for the projection structure and functions.
| argc | int number of comand line options | |
| argv | char** array of strings of length argc contaianing the command line arguments. |
Definition at line 131 of file eg_ebtree.ex.c.
References CHECKRVALG, ebt_display(), ebt_parseargs(), EGeBTreeAddLeft, EGeBTreeAddRight, EGeBTreeCut, EGeBTreeDel, EGeBTreeInit, EGeBTreeReplace, EGfree, EGioClose(), EGioOpen(), EGioPrintf(), EGlib_info(), EGlib_version(), EGsetLimits(), EGsigSet, EGsMalloc, and verbose.

int verbose = 0 [static] |
Definition at line 26 of file eg_ebtree.ex.c.
Referenced by ebt_display(), ebt_parseargs(), and main().
1.7.1