bool tree_iterator_first(void* Iterator) { ASSERT(Iterator != NULL); tree_iterator* iterator = Iterator; ASSERT(iterator->tree != NULL); if (iterator->tree->root) { iterator->node = tree_node_min(iterator->tree->root); return true; } return false; }
bool tr_itor_first(tr_itor* itor) { ASSERT(itor != NULL); if (itor->tree->root) { itor->node = tree_node_min(itor->tree->root); return true; } else { itor->node = NULL; return false; } }
void* tree_node_next(void* Node) { tree_node* node = Node; ASSERT(node != NULL); if (node->rlink) { return tree_node_min(node->rlink); } tree_node* parent = node->parent; while (parent && parent->rlink == node) { node = parent; parent = parent->parent; } return parent; }
size_t sp_tree_traverse(sp_tree* tree, dict_visit_func visit) { ASSERT(tree != NULL); ASSERT(visit != NULL); size_t count = 0; if (tree->root) { sp_node* node = tree_node_min(tree->root); do { ++count; if (!visit(node->key, node->datum)) break; node = tree_node_next(node); } while (node); } return count; }