13.5.3 Starting at a Found Node [ToC] [Index]     [Skip Back] [Skip Fwd]     [Prev] [Up] [Next]

To start from a particular item, we search for it in the tree. If it exists then we initialize the traverser to it. Otherwise, we initialize the traverser to the null item and return a null pointer. There are no surprises here.

507. <PBST traverser search initializer 507> =
void *
pbst_t_find (struct pbst_traverser *trav, struct pbst_table *tree, void *item)
{ struct pbst_node *p; int dir; assert (trav != NULL && tree != NULL && item != NULL); trav->pbst_table = tree; for (p = tree->pbst_root; p != NULL; p = p->pbst_link[dir])
    { int cmp = tree->pbst_compare (item, p->pbst_data, tree->pbst_param); if (cmp == 0)
        { trav->pbst_node = p; return p->pbst_data; } dir = cmp > 0; } trav->pbst_node = NULL; return NULL; }

This code is included in 504 and 548.