Commit 6d2a6fed authored by Daniel Salzman's avatar Daniel Salzman

libknot/rdataset: remove redundant function knot_rdataset_sort_at (rdataset is already sorted)

parent 8ffe5d7a
......@@ -359,50 +359,3 @@ int knot_rdataset_subtract(knot_rdataset_t *from, const knot_rdataset_t *what,
return KNOT_EOK;
}
_public_
int knot_rdataset_sort_at(knot_rdataset_t *rrs, uint16_t pos, knot_mm_t *mm)
{
if (rrs == NULL || rrs->count == 0 || pos >= rrs->count) {
return KNOT_EINVAL;
}
const knot_rdata_t *rr = rr_seek(rrs, pos);
knot_rdata_t *earlier_rr = NULL;
for (uint16_t i = 0; i < rrs->count; ++i) {
if (i == pos) {
// It already is at the position.
return KNOT_EOK;
}
earlier_rr = rr_seek(rrs, i);
int cmp = knot_rdata_cmp(earlier_rr, rr);
if (cmp == 0) {
// Duplicate - we need to remove this RR.
return remove_rr_at(rrs, pos, mm);
} else if (cmp > 0) {
// Found position to move.
break;
}
}
assert(earlier_rr);
// Save the RDATA to be moved.
uint8_t buf[knot_rdata_size(rr->len)];
knot_rdata_t *tmp_rr = (knot_rdata_t *)buf;
knot_rdata_init(tmp_rr, rr->len, rr->data);
// Move the array or just part of it.
assert(pos > 0);
knot_rdata_t *last_rr = rr_seek(rrs, pos - 1);
uint8_t *moved = (uint8_t *)earlier_rr + knot_rdata_size(tmp_rr->len);
assert(earlier_rr <= last_rr);
size_t len = ((uint8_t *)last_rr - (uint8_t *)earlier_rr) +
knot_rdata_size(last_rr->len);
memmove(moved, earlier_rr, len);
// Set new RDATA.
knot_rdata_init(earlier_rr, tmp_rr->len, tmp_rr->data);
return KNOT_EOK;
}
......@@ -198,17 +198,6 @@ int knot_rdataset_intersect(const knot_rdataset_t *rrs1, const knot_rdataset_t *
int knot_rdataset_subtract(knot_rdataset_t *from, const knot_rdataset_t *what,
knot_mm_t *mm);
/*!
* \brief Sorts the dataset. Removes the element if found to be duplicate.
*
* \param rrs RRS to sort.
* \param pos Position of the element to sort (counted from 0).
* \param mm Memory context used to remove the element if duplicate.
*
* \return KNOT_E*
*/
int knot_rdataset_sort_at(knot_rdataset_t *rrs, uint16_t pos, knot_mm_t *mm);
/*! \brief Check helper. */
#define KNOT_RDATASET_CHECK(rrs, pos) \
assert(rrs && rrs->rdata && rrs->count > 0 && pos < rrs->count);
......
......@@ -196,10 +196,6 @@ int main(int argc, char *argv[])
knot_rdata_init(knot_rdataset_at(&rdataset, 1), 4, (uint8_t *)"abcd");
ret = knot_rdataset_sort_at(&rdataset, 1, NULL);
bool sort_ok = ret == KNOT_EOK && knot_rdataset_eq(&rdataset, &copy);
ok(sort_ok, "rdataset: sort reserved space");
knot_rdataset_clear(&copy, NULL);
knot_rdataset_clear(&rdataset, NULL);
knot_rdataset_clear(&rdataset_lo, NULL);
......
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