improvements to the QP iterator

- make iterators reversible: refactor dns_qpiter_next() and add a new
  dns_qpiter_prev() function to support iterating both forwards and
  backwards through a QP trie.
- added a 'name' parameter to dns_qpiter_next() (as well as _prev())
  to make it easier to retrieve the nodename while iterating, without
  having to construct it from pointer value data.
This commit is contained in:
Evan Hunt
2023-09-19 00:41:57 -07:00
parent 7f0242b8c7
commit 3bf23fadb0
8 changed files with 210 additions and 70 deletions

View File

@@ -72,8 +72,8 @@ getheight(dns_qp_t *qp, qp_node_t *n) {
return (0);
}
size_t max_height = 0;
qp_weight_t size = branch_twigs_size(n);
qp_node_t *twigs = branch_twigs(qp, n);
qp_weight_t size = branch_twigs_size(n);
for (qp_weight_t pos = 0; pos < size; pos++) {
size_t height = getheight(qp, &twigs[pos]);
max_height = ISC_MAX(max_height, height);
@@ -94,8 +94,8 @@ maxkeylen(dns_qp_t *qp, qp_node_t *n) {
return (leaf_qpkey(qp, n, key));
}
size_t max_len = 0;
qp_weight_t size = branch_twigs_size(n);
qp_node_t *twigs = branch_twigs(qp, n);
qp_weight_t size = branch_twigs_size(n);
for (qp_weight_t pos = 0; pos < size; pos++) {
size_t len = maxkeylen(qp, &twigs[pos]);
max_len = ISC_MAX(max_len, len);
@@ -263,8 +263,10 @@ qp_test_dumptrie(dns_qpreadable_t qpr) {
--sp;
}
n = ref_ptr(qp, stack[sp].ref) + stack[sp].pos;
stack[sp].pos++;
fprintf(stderr, "pos %d/%d, ref+%d\n", stack[sp].pos,
stack[sp].max, stack[sp].pos - 1);
n = ref_ptr(qp, stack[sp].ref) + stack[sp].pos - 1;
}
}
@@ -299,8 +301,8 @@ dumpdot_twig(dns_qp_t *qp, qp_node_t *n) {
}
printf("}}\"];\n");
qp_weight_t size = branch_twigs_size(n);
qp_node_t *twigs = branch_twigs(qp, n);
qp_weight_t size = branch_twigs_size(n);
for (qp_weight_t pos = 0; pos < size; pos++) {
dumpdot_name(n);