You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@datasketches.apache.org by al...@apache.org on 2019/08/01 02:26:31 UTC
[incubator-datasketches-cpp] 01/01: fixed the range of items to
destroy
This is an automated email from the ASF dual-hosted git repository.
alsay pushed a commit to branch kll_destruction_fix
in repository https://gitbox.apache.org/repos/asf/incubator-datasketches-cpp.git
commit b64773b310937ed885e4828db738e8accc1b3320
Author: AlexanderSaydakov <Al...@users.noreply.github.com>
AuthorDate: Wed Jul 31 19:26:17 2019 -0700
fixed the range of items to destroy
---
kll/include/kll_sketch.hpp | 14 +++++---------
1 file changed, 5 insertions(+), 9 deletions(-)
diff --git a/kll/include/kll_sketch.hpp b/kll/include/kll_sketch.hpp
index 61e403b..fdbe5ee 100644
--- a/kll/include/kll_sketch.hpp
+++ b/kll/include/kll_sketch.hpp
@@ -831,6 +831,7 @@ void kll_sketch<T, C, S, A>::compress_while_updating(void) {
const uint32_t adj_beg = odd_pop ? raw_beg + 1 : raw_beg;
const uint32_t adj_pop = odd_pop ? raw_pop - 1 : raw_pop;
const uint32_t half_adj_pop = adj_pop / 2;
+ const uint32_t destroy_beg = levels_[0];
// level zero might not be sorted, so we must sort it if we wish to compact it
// sort_level_zero() is not used here because of the adjustment for odd number of items
@@ -846,7 +847,7 @@ void kll_sketch<T, C, S, A>::compress_while_updating(void) {
levels_[level + 1] -= half_adj_pop; // adjust boundaries of the level above
if (odd_pop) {
levels_[level] = levels_[level + 1] - 1; // the current level now contains one item
- items_[levels_[level]] = std::move(items_[raw_beg]); // namely this leftover guy
+ if (levels_[level] != raw_beg) items_[levels_[level]] = std::move(items_[raw_beg]); // namely this leftover guy
} else {
levels_[level] = levels_[level + 1]; // the current level is now empty
}
@@ -858,15 +859,10 @@ void kll_sketch<T, C, S, A>::compress_while_updating(void) {
// so that the freed-up space can be used by level zero
if (level > 0) {
const uint32_t amount = raw_beg - levels_[0];
- const uint32_t first = levels_[0];
- uint32_t last = levels_[0] + amount;
- while (first != last) {
- --last;
- items_[last + half_adj_pop] = std::move(items_[last]);
- }
+ std::move_backward(&items_[levels_[0]], &items_[levels_[0] + amount], &items_[levels_[0] + half_adj_pop + amount]);
for (uint8_t lvl = 0; lvl < level; lvl++) levels_[lvl] += half_adj_pop;
}
- for (uint32_t i = 0; i < half_adj_pop; i++) items_[i + raw_beg].~T();
+ for (uint32_t i = 0; i < half_adj_pop; i++) items_[i + destroy_beg].~T();
}
template<typename T, typename C, typename S, typename A>
@@ -893,7 +889,7 @@ void kll_sketch<T, C, S, A>::add_empty_top_level_to_completely_full_sketch() {
// note that merging MIGHT over-grow levels_, in which case we might not have to grow it here
const uint8_t new_levels_size = num_levels_ + 2;
- if (levels_size_ < (new_levels_size)) {
+ if (levels_size_ < new_levels_size) {
uint32_t* new_levels = AllocU32().allocate(new_levels_size);
std::copy(&levels_[0], &levels_[levels_size_], new_levels);
AllocU32().deallocate(levels_, levels_size_);
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@datasketches.apache.org
For additional commands, e-mail: commits-help@datasketches.apache.org