Esempio n. 1
0
/* traverse a tree starting at node */
static int
trbt_traversearray32_node(trbt_node_t *node, uint32_t keylen,
                          int (*callback)(void *param, void *data),
                          void *param)
{
    trbt_node_t *left = node->left;
    trbt_node_t *right = node->right;

    if (left) {
        int ret;
        ret = trbt_traversearray32_node(left, keylen, callback, param);
        if (ret != 0) {
            return ret;
        }
    }

    /* this is the smallest node in this subtree
       if keylen is 0 this means we can just call the callback
       otherwise we must pull the next subtree and traverse that one as well
    */
    if (keylen == 0) {
        int ret;

        ret = callback(param, node->data);
        if (ret != 0) {
            return ret;
        }
    } else {
        int ret;

        ret = trbt_traversearray32(node->data, keylen, callback, param);
        if (ret != 0) {
            return ret;
        }
    }

    if (right) {
        int ret;

        ret = trbt_traversearray32_node(right, keylen, callback, param);
        if (ret != 0) {
            return ret;
        }
    }

    return 0;
}
Esempio n. 2
0
/* traverse a tree starting at node */
static void 
trbt_traversearray32_node(trbt_node_t *node, uint32_t keylen, 
	void (*callback)(void *param, void *data), 
	void *param)
{
	if (node->left) {
		trbt_traversearray32_node(node->left, keylen, callback, param);
	}

	/* this is the smallest node in this subtree
	   if keylen is 0 this means we can just call the callback
	   otherwise we must pull the next subtree and traverse that one as well
	*/
	if (keylen == 0) {
		callback(param, node->data);
	} else {
		trbt_traversearray32(node->data, keylen, callback, param);
	}

	if (node->right) {
		trbt_traversearray32_node(node->right, keylen, callback, param);
	}
}
Esempio n. 3
0
/* traverse the tree using an array of uint32 as a key */
void 
trbt_traversearray32(trbt_tree_t *tree, uint32_t keylen, 
	void (*callback)(void *param, void *data), 
	void *param)
{
	trbt_node_t *node;

	if (tree == NULL) {
		return;
	}

	node=tree->root;
	if (node == NULL) {
		return;
	}

	trbt_traversearray32_node(node, keylen-1, callback, param);
}