D
David RF
Hi friends, excuse my poor english and the off-topic of not standard
function twalk (in linux <search.h>)
http://www.mkssoftware.com/docs/man3/twalk.3.asp
twalk() traverses a binary search tree, but call recursively three
times for each node,
this behavior is not required when the order does not matter
typedef struct node_t
{
/* Callers expect this to be the first element in the structure - do
not
move! */
const void *key;
struct node_t *left;
struct node_t *right;
unsigned int red:1;
} *node;
static void
internal_function
trecurse (const void *vroot, __action_fn_t action, int level)
{
const_node root = (const_node) vroot;
if (root->left == NULL && root->right == NULL)
(*action) (root, leaf, level);
else
{
(*action) (root, preorder, level);
if (root->left != NULL)
trecurse (root->left, action, level + 1);
(*action) (root, postorder, level);
if (root->right != NULL)
trecurse (root->right, action, level + 1);
(*action) (root, endorder, level);
}
}
I am surprised about this bottleneck, why don't let overload this
behavior? (perphaps declaring node_t in search.h like other does)
#ifdef _SEARCH_PRIVATE
typedef struct node {
char *key;
struct node *llink, *rlink;
} node_t;
struct que_elem {
struct que_elem *next;
struct que_elem *prev;
};
#endif
function twalk (in linux <search.h>)
http://www.mkssoftware.com/docs/man3/twalk.3.asp
twalk() traverses a binary search tree, but call recursively three
times for each node,
this behavior is not required when the order does not matter
typedef struct node_t
{
/* Callers expect this to be the first element in the structure - do
not
move! */
const void *key;
struct node_t *left;
struct node_t *right;
unsigned int red:1;
} *node;
static void
internal_function
trecurse (const void *vroot, __action_fn_t action, int level)
{
const_node root = (const_node) vroot;
if (root->left == NULL && root->right == NULL)
(*action) (root, leaf, level);
else
{
(*action) (root, preorder, level);
if (root->left != NULL)
trecurse (root->left, action, level + 1);
(*action) (root, postorder, level);
if (root->right != NULL)
trecurse (root->right, action, level + 1);
(*action) (root, endorder, level);
}
}
I am surprised about this bottleneck, why don't let overload this
behavior? (perphaps declaring node_t in search.h like other does)
#ifdef _SEARCH_PRIVATE
typedef struct node {
char *key;
struct node *llink, *rlink;
} node_t;
struct que_elem {
struct que_elem *next;
struct que_elem *prev;
};
#endif