- 论坛徽章:
- 0
|
回复 #10 ldap 的帖子
void init_btree32_i_walker(walker *cc)
{
if (cc == NULL) {
return;
}
cc->pos = 0;
cc->out = WALKER_OUT_INIT;
cc->beg = 0;
}
bnode32_i *walker_btree32_i(bnode32_i *node, int16 pos, void **index, int32 *key, walker *cc)
{
int16 i;
Assert(key != NULL);
Assert(pos >= 0);
Assert(cc != NULL);
if (node == NULL) {
return NULL;
}
/* enter last out scene */
if (cc->out == WALKER_OUT_LEAF)
goto leaf;
if (cc->out == WALKER_OUT_ROOT)
goto start;
cc->pos = pos;
start:
/* trace to bottom */
for(;;) {
if (node->child[0] != NULL) {
node = node->child[cc->pos];
cc->pos = 0;
continue;
}
break;
}
leaf:
/* current node must be leaf node */
for (i = cc->beg; i < node->num; i++) {
*key = node->key[i];
*index = node->index[i];
cc->out = WALKER_OUT_LEAF;
cc->beg = i + 1;
return node;
}
prev:
/* output the last key of root */
if (node->parent == NULL) {
return NULL;
}
/* output the key of previus middle node */
if (node->pos < node->parent->num) {
*key = node->parent->key[node->pos];
*index = node->parent->index[node->pos];
cc->pos = node->pos + 1;
node = node->parent;
cc->out = WALKER_OUT_ROOT;
cc->beg = 0;
return node;
}
/* have output the all key in the middle node,*/
/* so must output the up node. */
node = node->parent;
goto prev;
} |
|
|