Commit fe686f41 authored by Daniel Salzman's avatar Daniel Salzman

hat-trie: remove sorted parameter from hattrie_iter_begin (qp-trie is always sorted)

parent 1d058c41
......@@ -71,10 +71,9 @@ inline static int hattrie_del(hattrie_t *trie, const char* key, size_t len)
return - qp_trie_del(trie, key, len, NULL);
}
inline static hattrie_iter_t* hattrie_iter_begin(const hattrie_t *trie, bool sorted)
inline static hattrie_iter_t* hattrie_iter_begin(hattrie_t *trie)
{
UNUSED(sorted); // iteration over QP is always sorted ATM
return qp_trie_it_begin(/*const-cast*/(hattrie_t*)trie);
return qp_trie_it_begin(trie);
}
inline static void hattrie_iter_next(hattrie_iter_t *it)
......
......@@ -442,7 +442,7 @@ static int diff_zone_section(
return KNOT_EOK;
}
hattrie_iter_t *it = hattrie_iter_begin(conf()->io.zones, true);
hattrie_iter_t *it = hattrie_iter_begin(conf()->io.zones);
for (; !hattrie_iter_finished(it); hattrie_iter_next(it)) {
io->id = (const uint8_t *)hattrie_iter_key(it, &io->id_len);
......@@ -1399,7 +1399,7 @@ static int check_zone_section(
return KNOT_EOK;
}
hattrie_iter_t *it = hattrie_iter_begin(conf()->io.zones, true);
hattrie_iter_t *it = hattrie_iter_begin(conf()->io.zones);
for (; !hattrie_iter_finished(it); hattrie_iter_next(it)) {
size_t id_len;
const uint8_t *id = (const uint8_t *)hattrie_iter_key(it, &id_len);
......
......@@ -645,8 +645,7 @@ static int send_changeset_part(changeset_t *ch, send_ctx_t *ctx, bool from)
// Send other records.
changeset_iter_t it;
int ret = from ? changeset_iter_rem(&it, ch, true) :
changeset_iter_add(&it, ch, true);
int ret = from ? changeset_iter_rem(&it, ch) : changeset_iter_add(&it, ch);
if (ret != KNOT_EOK) {
return ret;
}
......
/* Copyright (C) 2014 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
/* Copyright (C) 2016 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
......@@ -162,9 +162,7 @@ int knot_nsec_chain_iterate_create(zone_tree_t *nodes,
assert(nodes);
assert(callback);
bool sorted = true;
hattrie_iter_t *it = hattrie_iter_begin(nodes, sorted);
hattrie_iter_t *it = hattrie_iter_begin(nodes);
if (!it) {
return KNOT_ENOMEM;
}
......
......@@ -112,7 +112,7 @@ static int shallow_copy_signature(const zone_node_t *from, zone_node_t *to)
/*!
* \brief Reuse signatatures by shallow copying them from one tree to another.
*/
static int copy_signatures(const zone_tree_t *from, zone_tree_t *to)
static int copy_signatures(zone_tree_t *from, zone_tree_t *to)
{
if (zone_tree_is_empty(from)) {
return KNOT_EOK;
......@@ -120,8 +120,7 @@ static int copy_signatures(const zone_tree_t *from, zone_tree_t *to)
assert(to);
bool sorted = false;
hattrie_iter_t *it = hattrie_iter_begin(from, sorted);
hattrie_iter_t *it = hattrie_iter_begin(from);
for (/* NOP */; !hattrie_iter_finished(it); hattrie_iter_next(it)) {
zone_node_t *node_from = (zone_node_t *)*hattrie_iter_val(it);
......@@ -155,8 +154,7 @@ static void free_nsec3_tree(zone_tree_t *nodes)
{
assert(nodes);
bool sorted = false;
hattrie_iter_t *it = hattrie_iter_begin(nodes, sorted);
hattrie_iter_t *it = hattrie_iter_begin(nodes);
for (/* NOP */; !hattrie_iter_finished(it); hattrie_iter_next(it)) {
zone_node_t *node = (zone_node_t *)*hattrie_iter_val(it);
// newly allocated NSEC3 nodes
......@@ -430,8 +428,7 @@ static int create_nsec3_nodes(const zone_contents_t *zone,
int result = KNOT_EOK;
const bool sorted = false;
hattrie_iter_t *it = hattrie_iter_begin(zone->nodes, sorted);
hattrie_iter_t *it = hattrie_iter_begin(zone->nodes);
while (!hattrie_iter_finished(it)) {
zone_node_t *node = (zone_node_t *)*hattrie_iter_val(it);
......
......@@ -97,7 +97,7 @@ static int mark_removed_nsec3(const zone_contents_t *zone, changeset_t *ch)
}
changeset_iter_t itt;
changeset_iter_rem(&itt, ch, false);
changeset_iter_rem(&itt, ch);
knot_rrset_t rr = changeset_iter_next(&itt);
while (!knot_rrset_empty(&rr)) {
......
/* Copyright (C) 2011 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
/* Copyright (C) 2016 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
......@@ -1247,7 +1247,7 @@ int knot_zone_sign_changeset(const zone_contents_t *zone,
}
changeset_iter_t itt;
changeset_iter_all(&itt, in_ch, false);
changeset_iter_all(&itt, in_ch);
knot_rrset_t rr = changeset_iter_next(&itt);
while (!knot_rrset_empty(&rr)) {
......@@ -1275,7 +1275,7 @@ int knot_zone_sign_nsecs_in_changeset(const zone_keyset_t *zone_keys,
}
changeset_iter_t itt;
changeset_iter_add(&itt, changeset, false);
changeset_iter_add(&itt, changeset);
knot_rrset_t rr = changeset_iter_next(&itt);
while (!knot_rrset_empty(&rr)) {
......
......@@ -70,7 +70,7 @@ static int axfr_process_node_tree(knot_pkt_t *pkt, const void *item,
struct axfr_proc *axfr = (struct axfr_proc*)state;
if (axfr->i == NULL) {
axfr->i = hattrie_iter_begin(item, true);
axfr->i = hattrie_iter_begin((hattrie_t *)item);
}
/* Put responses. */
......
......@@ -114,7 +114,7 @@ static int ixfr_process_changeset(knot_pkt_t *pkt, const void *item,
/* Put REMOVE RRSets. */
if (ixfr->state == IXFR_DEL) {
if (iter_empty(ixfr)) {
ret = changeset_iter_rem(&ixfr->cur, chgset, false);
ret = changeset_iter_rem(&ixfr->cur, chgset);
if (ret != KNOT_EOK) {
return ret;
}
......@@ -136,7 +136,7 @@ static int ixfr_process_changeset(knot_pkt_t *pkt, const void *item,
/* Put Add RRSets. */
if (ixfr->state == IXFR_ADD) {
if (iter_empty(ixfr)) {
ret = changeset_iter_add(&ixfr->cur, chgset, false);
ret = changeset_iter_add(&ixfr->cur, chgset);
if (ret != KNOT_EOK) {
return ret;
}
......
......@@ -785,7 +785,7 @@ static int serialize_and_store_chgset(const changeset_t *chs,
}
changeset_iter_t itt;
ret = changeset_iter_rem(&itt, chs, false);
ret = changeset_iter_rem(&itt, chs);
if (ret != KNOT_EOK) {
return ret;
}
......@@ -808,7 +808,7 @@ static int serialize_and_store_chgset(const changeset_t *chs,
}
/* Serialize RRSets from the 'add' section. */
ret = changeset_iter_add(&itt, chs, false);
ret = changeset_iter_add(&itt, chs);
if (ret != KNOT_EOK) {
return ret;
}
......
......@@ -78,7 +78,7 @@ int changeset_binary_size(const changeset_t *chgset, size_t *size)
size_t soa_from_size = rrset_binary_size(chgset->soa_from);
size_t soa_to_size = rrset_binary_size(chgset->soa_to);
changeset_iter_t itt;
changeset_iter_all(&itt, chgset, false);
changeset_iter_all(&itt, chgset);
size_t change_size = 0;
knot_rrset_t rrset = changeset_iter_next(&itt);
......
......@@ -147,7 +147,7 @@ static bool can_remove(const zone_node_t *node, const knot_rrset_t *rr)
static int apply_remove(apply_ctx_t *ctx, changeset_t *chset)
{
changeset_iter_t itt;
changeset_iter_rem(&itt, chset, false);
changeset_iter_rem(&itt, chset);
knot_rrset_t rr = changeset_iter_next(&itt);
while (!knot_rrset_empty(&rr)) {
......@@ -168,7 +168,7 @@ static int apply_remove(apply_ctx_t *ctx, changeset_t *chset)
static int apply_add(apply_ctx_t *ctx, changeset_t *chset)
{
changeset_iter_t itt;
changeset_iter_add(&itt, chset, false);
changeset_iter_add(&itt, chset);
knot_rrset_t rr = changeset_iter_next(&itt);
while(!knot_rrset_empty(&rr)) {
......
......@@ -65,8 +65,8 @@ static void cleanup_iter_list(list_t *l)
}
/*! \brief Inits changeset iterator with given HAT-tries. */
static int changeset_iter_init(changeset_iter_t *ch_it,
const changeset_t *ch, bool sorted, size_t tries, ...)
static int changeset_iter_init(changeset_iter_t *ch_it, const changeset_t *ch,
size_t tries, ...)
{
memset(ch_it, 0, sizeof(*ch_it));
init_list(&ch_it->iters);
......@@ -77,7 +77,7 @@ static int changeset_iter_init(changeset_iter_t *ch_it,
for (size_t i = 0; i < tries; ++i) {
hattrie_t *t = va_arg(args, hattrie_t *);
if (t) {
hattrie_iter_t *it = hattrie_iter_begin(t, sorted);
hattrie_iter_t *it = hattrie_iter_begin(t);
if (it == NULL) {
cleanup_iter_list(&ch_it->iters);
return KNOT_ENOMEM;
......@@ -218,7 +218,7 @@ bool changeset_empty(const changeset_t *ch)
}
changeset_iter_t itt;
changeset_iter_all(&itt, ch, false);
changeset_iter_all(&itt, ch);
knot_rrset_t rr = changeset_iter_next(&itt);
changeset_iter_clear(&itt);
......@@ -233,7 +233,7 @@ size_t changeset_size(const changeset_t *ch)
}
changeset_iter_t itt;
changeset_iter_all(&itt, ch, false);
changeset_iter_all(&itt, ch);
size_t size = 0;
knot_rrset_t rr = changeset_iter_next(&itt);
......@@ -350,7 +350,7 @@ int changeset_remove_removal(changeset_t *ch, const knot_rrset_t *rrset)
int changeset_merge(changeset_t *ch1, const changeset_t *ch2)
{
changeset_iter_t itt;
changeset_iter_add(&itt, ch2, false);
changeset_iter_add(&itt, ch2);
knot_rrset_t rrset = changeset_iter_next(&itt);
while (!knot_rrset_empty(&rrset)) {
......@@ -363,7 +363,7 @@ int changeset_merge(changeset_t *ch1, const changeset_t *ch2)
}
changeset_iter_clear(&itt);
changeset_iter_rem(&itt, ch2, false);
changeset_iter_rem(&itt, ch2);
rrset = changeset_iter_next(&itt);
while (!knot_rrset_empty(&rrset)) {
......@@ -435,22 +435,19 @@ void changeset_free(changeset_t *ch)
free(ch);
}
int changeset_iter_add(changeset_iter_t *itt, const changeset_t *ch, bool sorted)
int changeset_iter_add(changeset_iter_t *itt, const changeset_t *ch)
{
return changeset_iter_init(itt, ch, sorted, 2,
ch->add->nodes, ch->add->nsec3_nodes);
return changeset_iter_init(itt, ch, 2, ch->add->nodes, ch->add->nsec3_nodes);
}
int changeset_iter_rem(changeset_iter_t *itt, const changeset_t *ch, bool sorted)
int changeset_iter_rem(changeset_iter_t *itt, const changeset_t *ch)
{
return changeset_iter_init(itt, ch, sorted, 2,
ch->remove->nodes, ch->remove->nsec3_nodes);
return changeset_iter_init(itt, ch, 2, ch->remove->nodes, ch->remove->nsec3_nodes);
}
int changeset_iter_all(changeset_iter_t *itt, const changeset_t *ch, bool sorted)
int changeset_iter_all(changeset_iter_t *itt, const changeset_t *ch)
{
return changeset_iter_init(itt, ch, sorted, 4,
ch->add->nodes, ch->add->nsec3_nodes,
return changeset_iter_init(itt, ch, 4, ch->add->nodes, ch->add->nsec3_nodes,
ch->remove->nodes, ch->remove->nsec3_nodes);
}
......
/* Copyright (C) 2015 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
/* Copyright (C) 2016 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
......@@ -174,35 +174,32 @@ void changeset_free(changeset_t *ch);
/*!
* \brief Inits changeset iteration structure with changeset additions.
*
* \param itt Iterator to init.
* \param ch Changeset to use.
* \param sorted Sort the iteration?
* \param itt Iterator to init.
* \param ch Changeset to use.
*
* \return KNOT_E*
*/
int changeset_iter_add(changeset_iter_t *itt, const changeset_t *ch, bool sorted);
int changeset_iter_add(changeset_iter_t *itt, const changeset_t *ch);
/*!
* \brief Inits changeset iteration structure with changeset removals.
*
* \param itt Iterator to init.
* \param ch Changeset to use.
* \param sorted Sort the iteration?
* \param itt Iterator to init.
* \param ch Changeset to use.
*
* \return KNOT_E*
*/
int changeset_iter_rem(changeset_iter_t *itt, const changeset_t *ch, bool sorted);
int changeset_iter_rem(changeset_iter_t *itt, const changeset_t *ch);
/*!
* \brief Inits changeset iteration structure with changeset additions and removals.
*
* \param itt Iterator to init.
* \param ch Changeset to use.
* \param sorted Sort the iteration?
* \param itt Iterator to init.
* \param ch Changeset to use.
*
* \return KNOT_E*
*/
int changeset_iter_all(changeset_iter_t *itt, const changeset_t *ch, bool sorted);
int changeset_iter_all(changeset_iter_t *itt, const changeset_t *ch);
/*!
* \brief Gets next RRSet from changeset iterator.
......
......@@ -636,14 +636,12 @@ int zone_update_commit(conf_t *conf, zone_update_t *update)
static int iter_init_tree_iters(zone_update_iter_t *it, zone_update_t *update,
bool nsec3)
{
zone_tree_t *tree;
/* Set zone iterator. */
zone_contents_t *_contents = update->new_cont;
/* Begin iteration. We can safely assume _contents is a valid pointer. */
tree = nsec3 ? _contents->nsec3_nodes : _contents->nodes;
it->tree_it = hattrie_iter_begin(nsec3 ? _contents->nsec3_nodes : _contents->nodes, true);
zone_tree_t *tree = nsec3 ? _contents->nsec3_nodes : _contents->nodes;
it->tree_it = hattrie_iter_begin(tree);
if (it->tree_it == NULL) {
return KNOT_ENOMEM;
}
......
......@@ -672,7 +672,7 @@ static int recreate_normal_tree(const zone_contents_t *z, zone_contents_t *out)
out->apex = apex_cpy;
hattrie_iter_t *itt = hattrie_iter_begin(z->nodes, true);
hattrie_iter_t *itt = hattrie_iter_begin(z->nodes);
if (itt == NULL) {
return KNOT_ENOMEM;
}
......@@ -711,7 +711,7 @@ static int recreate_nsec3_tree(const zone_contents_t *z, zone_contents_t *out)
return KNOT_ENOMEM;
}
hattrie_iter_t *itt = hattrie_iter_begin(z->nsec3_nodes, false);
hattrie_iter_t *itt = hattrie_iter_begin(z->nsec3_nodes);
if (itt == NULL) {
return KNOT_ENOMEM;
}
......
......@@ -115,7 +115,7 @@ int zone_tree_get_less_or_equal(zone_tree_t *tree,
* cases like NSEC3, there is no such sort of thing (name wise).
*/
/*! \todo We could store rightmost node in zonetree probably. */
hattrie_iter_t *i = hattrie_iter_begin(tree, 1);
hattrie_iter_t *i = hattrie_iter_begin(tree);
*previous = *(zone_node_t **)hattrie_iter_val(i); /* leftmost */
*previous = (*previous)->prev; /* rightmost */
*found = NULL;
......
......@@ -275,7 +275,7 @@ static void mark_changed_zones(knot_zonedb_t *zonedb, hattrie_t *changed)
return;
}
hattrie_iter_t *it = hattrie_iter_begin(changed, false);
hattrie_iter_t *it = hattrie_iter_begin(changed);
for (; !hattrie_iter_finished(it); hattrie_iter_next(it)) {
size_t len;
const knot_dname_t *name =
......
......@@ -108,7 +108,6 @@ static int del(knot_db_txn_t *txn, knot_db_val_t *key)
static knot_db_iter_t *iter_begin(knot_db_txn_t *txn, unsigned flags)
{
bool is_sorted = (flags & KNOT_DB_SORTED);
flags &= ~KNOT_DB_SORTED;
/* No operations other than begin are supported right now. */
......@@ -116,7 +115,7 @@ static knot_db_iter_t *iter_begin(knot_db_txn_t *txn, unsigned flags)
return NULL;
}
return hattrie_iter_begin((hattrie_t *)txn->db, is_sorted);
return hattrie_iter_begin((hattrie_t *)txn->db);
}
static knot_db_iter_t *iter_seek(knot_db_iter_t *iter, knot_db_val_t *key, unsigned flags)
......
......@@ -118,7 +118,7 @@ int lookup_search(lookup_t *lookup, const char *str, size_t str_len)
reset_output(lookup);
size_t new_len = 0;
hattrie_iter_t *it = hattrie_iter_begin(lookup->trie, true);
hattrie_iter_t *it = hattrie_iter_begin(lookup->trie);
for (; !hattrie_iter_finished(it); hattrie_iter_next(it)) {
size_t len;
const char *key = hattrie_iter_key(it, &len);
......@@ -205,7 +205,7 @@ void lookup_list(lookup_t *lookup)
return;
}
lookup->iter.it = hattrie_iter_begin(lookup->trie, true);
lookup->iter.it = hattrie_iter_begin(lookup->trie);
while (!hattrie_iter_finished(lookup->iter.it)) {
size_t len;
const char *key = hattrie_iter_key(lookup->iter.it, &len);
......
......@@ -284,7 +284,7 @@ static void acl_next(void *scanner, const char *value)
if (extra->run == S_FIRST) {
if (trie != NULL) {
hattrie_iter_t *it = hattrie_iter_begin(*trie, false);
hattrie_iter_t *it = hattrie_iter_begin(*trie);
for (; !hattrie_iter_finished(it); hattrie_iter_next(it)) {
size_t len = 0;
const char *data = hattrie_iter_key(it, &len);
......@@ -306,7 +306,7 @@ static void acl_next(void *scanner, const char *value)
if (trie != NULL) {
bool init = true;
hattrie_iter_t *it = hattrie_iter_begin(*trie, false);
hattrie_iter_t *it = hattrie_iter_begin(*trie);
for (; !hattrie_iter_finished(it); hattrie_iter_next(it)) {
size_t len = 0;
const char *data = hattrie_iter_key(it, &len);
......
......@@ -228,7 +228,7 @@ static void acl_next(void *scanner, const char *value)
if (extra->run == S_FIRST) {
if (trie != NULL) {
hattrie_iter_t *it = hattrie_iter_begin(*trie, false);
hattrie_iter_t *it = hattrie_iter_begin(*trie);
for (; !hattrie_iter_finished(it); hattrie_iter_next(it)) {
size_t len = 0;
const char *data = hattrie_iter_key(it, &len);
......@@ -250,7 +250,7 @@ static void acl_next(void *scanner, const char *value)
if (trie != NULL) {
bool init = true;
hattrie_iter_t *it = hattrie_iter_begin(*trie, false);
hattrie_iter_t *it = hattrie_iter_begin(*trie);
for (; !hattrie_iter_finished(it); hattrie_iter_next(it)) {
size_t len = 0;
const char *data = hattrie_iter_key(it, &len);
......
......@@ -93,7 +93,7 @@ static int convert(const char *file_out, const char *file_in)
}
// Remove ifaces data.
hattrie_iter_t *it = hattrie_iter_begin(share.ifaces, false);
hattrie_iter_t *it = hattrie_iter_begin(share.ifaces);
for (; !hattrie_iter_finished(it); hattrie_iter_next(it)) {
char *data = *hattrie_iter_val(it);
free(data);
......@@ -101,7 +101,7 @@ static int convert(const char *file_out, const char *file_in)
hattrie_iter_free(it);
// Remove groups data.
it = hattrie_iter_begin(share.groups, false);
it = hattrie_iter_begin(share.groups);
for (; !hattrie_iter_finished(it); hattrie_iter_next(it)) {
hattrie_t *trie = *hattrie_iter_val(it);
hattrie_free(trie);
......
......@@ -80,7 +80,7 @@ int main(int argc, char *argv[])
// Test add traversal.
changeset_iter_t it;
ret = changeset_iter_add(&it, ch, true);
ret = changeset_iter_add(&it, ch);
ok(ret == KNOT_EOK, "changeset: create iter add");
// Order: non.terminals.test. TXT, SPF, here.come.more.non.terminals.test. TXT.
knot_rrset_t iter = changeset_iter_next(&it);
......@@ -100,7 +100,7 @@ int main(int argc, char *argv[])
changeset_add_removal(ch, apex_txt_rr, CHANGESET_CHECK);
// Test remove traversal.
ret = changeset_iter_rem(&it, ch, false);
ret = changeset_iter_rem(&it, ch);
ok(ret == KNOT_EOK, "changeset: create iter rem");
iter = changeset_iter_next(&it);
ok(knot_rrset_equal(&iter, apex_txt_rr, KNOT_RRSET_COMPARE_WHOLE),
......@@ -108,7 +108,7 @@ int main(int argc, char *argv[])
changeset_iter_clear(&it);
// Test all traversal - just count.
ret = changeset_iter_all(&it, ch, false);
ret = changeset_iter_all(&it, ch);
ok(ret == KNOT_EOK, "changest: create iter all");
size_t size = 0;
iter = changeset_iter_next(&it);
......
......@@ -170,20 +170,10 @@ int main(int argc, char *argv[])
}
ok(passed, "hattrie: find lesser or equal for all keys");
/* Unsorted iteration */
size_t iterated = 0;
hattrie_iter_t *it = hattrie_iter_begin(trie, false);
while (!hattrie_iter_finished(it)) {
++iterated;
hattrie_iter_next(it);
}
is_int(inserted, iterated, "hattrie: unsorted iteration");
hattrie_iter_free(it);
/* Sorted iteration. */
char key_buf[KEY_MAXLEN] = {'\0'};
iterated = 0;
it = hattrie_iter_begin(trie, true);
size_t iterated = 0;
hattrie_iter_t *it = hattrie_iter_begin(trie);
while (!hattrie_iter_finished(it)) {
size_t cur_key_len = 0;
const char *cur_key = hattrie_iter_key(it, &cur_key_len);
......
......@@ -125,9 +125,9 @@ static bool changesets_eq(const changeset_t *ch1, changeset_t *ch2)
}
changeset_iter_t it1;
changeset_iter_all(&it1, ch1, true);
changeset_iter_all(&it1, ch1);
changeset_iter_t it2;
changeset_iter_all(&it2, ch2, true);
changeset_iter_all(&it2, ch2);
knot_rrset_t rr1 = changeset_iter_next(&it1);
knot_rrset_t rr2 = changeset_iter_next(&it2);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment