| 1042 | } |
| 1043 | |
| 1044 | int |
| 1045 | rn_walktree(struct radix_head *h, walktree_f_t *f, void *w) |
| 1046 | { |
| 1047 | int error; |
| 1048 | struct radix_node *base, *next; |
| 1049 | struct radix_node *rn = h->rnh_treetop; |
| 1050 | /* |
| 1051 | * This gets complicated because we may delete the node |
| 1052 | * while applying the function f to it, so we need to calculate |
| 1053 | * the successor node in advance. |
| 1054 | */ |
| 1055 | |
| 1056 | /* First time through node, go left */ |
| 1057 | while (rn->rn_bit >= 0) |
| 1058 | rn = rn->rn_left; |
| 1059 | for (;;) { |
| 1060 | base = rn; |
| 1061 | /* If at right child go back up, otherwise, go right */ |
| 1062 | while (rn->rn_parent->rn_right == rn |
| 1063 | && (rn->rn_flags & RNF_ROOT) == 0) |
| 1064 | rn = rn->rn_parent; |
| 1065 | /* Find the next *leaf* since next node might vanish, too */ |
| 1066 | for (rn = rn->rn_parent->rn_right; rn->rn_bit >= 0;) |
| 1067 | rn = rn->rn_left; |
| 1068 | next = rn; |
| 1069 | /* Process leaves */ |
| 1070 | while ((rn = base)) { |
| 1071 | base = rn->rn_dupedkey; |
| 1072 | if (!(rn->rn_flags & RNF_ROOT) |
| 1073 | && (error = (*f)(rn, w))) |
| 1074 | return (error); |
| 1075 | } |
| 1076 | rn = next; |
| 1077 | if (rn->rn_flags & RNF_ROOT) |
| 1078 | return (0); |
| 1079 | } |
| 1080 | /* NOTREACHED */ |
| 1081 | } |
| 1082 | |
| 1083 | /* |
| 1084 | * Initialize an empty tree. This has 3 nodes, which are passed |
no outgoing calls
no test coverage detected