From 659d6347a045dfebdfd1ba2f22f117b746873ae0 Mon Sep 17 00:00:00 2001 From: stdpain <34912776+stdpain@users.noreply.github.com> Date: Sat, 22 May 2021 23:38:28 +0800 Subject: [PATCH] [BUG] fix some extra memory in bitmap operate (#5857) --- be/src/util/bitmap_value.h | 18 +++++++++--------- .../src/udaf_orthogonal_bitmap/bitmap_value.h | 18 +++++++++--------- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/be/src/util/bitmap_value.h b/be/src/util/bitmap_value.h index c228c0c88f..2b3dc4713d 100644 --- a/be/src/util/bitmap_value.h +++ b/be/src/util/bitmap_value.h @@ -316,7 +316,7 @@ public: } return std::accumulate( roarings.cbegin(), roarings.cend(), (uint64_t)0, - [](uint64_t previous, const std::pair& map_entry) { + [](uint64_t previous, const std::pair& map_entry) { return previous + map_entry.second.cardinality(); }); } @@ -326,7 +326,7 @@ public: */ bool isEmpty() const { return std::all_of(roarings.cbegin(), roarings.cend(), - [](const std::pair& map_entry) { + [](const std::pair& map_entry) { return map_entry.second.isEmpty(); }); } @@ -341,7 +341,7 @@ public: // to avoid a clash with the Windows.h header under Windows return roarings.size() == ((size_t)(std::numeric_limits::max)()) + 1 ? std::all_of(roarings.cbegin(), roarings.cend(), - [](const std::pair& roaring_map_entry) { + [](const std::pair& roaring_map_entry) { // roarings within map are saturated if cardinality // is uint32_t max + 1 return roaring_map_entry.second.cardinality() == @@ -384,7 +384,7 @@ public: // Annoyingly, VS 2017 marks std::accumulate() as [[nodiscard]] (void)std::accumulate( roarings.cbegin(), roarings.cend(), ans, - [](uint64_t* previous, const std::pair& map_entry) { + [](uint64_t* previous, const std::pair& map_entry) { for (uint32_t low_bits : map_entry.second) *previous++ = uniteBytes(map_entry.first, low_bits); return previous; @@ -527,7 +527,7 @@ public: */ void iterate(roaring_iterator64 iterator, void* ptr) const { std::for_each(roarings.begin(), roarings.cend(), - [=](const std::pair& map_entry) { + [=](const std::pair& map_entry) { roaring_iterate64(&map_entry.second.roaring, iterator, uint64_t(map_entry.first) << 32, ptr); }); @@ -595,7 +595,7 @@ public: // push map size buf = (char*)encode_varint64((uint8_t*)buf, roarings.size()); std::for_each(roarings.cbegin(), roarings.cend(), - [&buf](const std::pair& map_entry) { + [&buf](const std::pair& map_entry) { // push map key encode_fixed32_le((uint8_t*)buf, map_entry.first); buf += sizeof(uint32_t); @@ -657,7 +657,7 @@ public: // start with type code, map size and size of keys for each map entry size_t init = 1 + varint_length(roarings.size()) + roarings.size() * sizeof(uint32_t); return std::accumulate(roarings.cbegin(), roarings.cend(), init, - [=](size_t previous, const std::pair& map_entry) { + [=](size_t previous, const std::pair& map_entry) { // add in bytes used by each Roaring return previous + map_entry.second.getSizeInBytes(); }); @@ -731,7 +731,7 @@ public: }, (void*)&outer_iter_data); std::for_each( - ++map_iter, roarings.cend(), [](const std::pair& map_entry) { + ++map_iter, roarings.cend(), [](const std::pair& map_entry) { map_entry.second.iterate( [](uint32_t low_bits, void* high_bits) -> bool { std::printf(",%llu", (long long unsigned)uniteBytes( @@ -770,7 +770,7 @@ public: (void*)&outer_iter_data); std::for_each( ++map_iter, roarings.cend(), - [&outer_iter_data](const std::pair& map_entry) { + [&outer_iter_data](const std::pair& map_entry) { outer_iter_data.high_bits = map_entry.first; map_entry.second.iterate( [](uint32_t low_bits, void* inner_iter_data) -> bool { diff --git a/contrib/udf/src/udaf_orthogonal_bitmap/bitmap_value.h b/contrib/udf/src/udaf_orthogonal_bitmap/bitmap_value.h index 42640692bf..322d927890 100644 --- a/contrib/udf/src/udaf_orthogonal_bitmap/bitmap_value.h +++ b/contrib/udf/src/udaf_orthogonal_bitmap/bitmap_value.h @@ -390,7 +390,7 @@ public: } return std::accumulate( roarings.cbegin(), roarings.cend(), (uint64_t)0, - [](uint64_t previous, const std::pair& map_entry) { + [](uint64_t previous, const std::pair& map_entry) { return previous + map_entry.second.cardinality(); }); } @@ -400,7 +400,7 @@ public: */ bool isEmpty() const { return std::all_of(roarings.cbegin(), roarings.cend(), - [](const std::pair& map_entry) { + [](const std::pair& map_entry) { return map_entry.second.isEmpty(); }); } @@ -415,7 +415,7 @@ public: // to avoid a clash with the Windows.h header under Windows return roarings.size() == ((size_t)(std::numeric_limits::max)()) + 1 ? std::all_of(roarings.cbegin(), roarings.cend(), - [](const std::pair& roaring_map_entry) { + [](const std::pair& roaring_map_entry) { // roarings within map are saturated if cardinality // is uint32_t max + 1 return roaring_map_entry.second.cardinality() == @@ -458,7 +458,7 @@ public: // Annoyingly, VS 2017 marks std::accumulate() as [[nodiscard]] (void)std::accumulate( roarings.cbegin(), roarings.cend(), ans, - [](uint64_t* previous, const std::pair& map_entry) { + [](uint64_t* previous, const std::pair& map_entry) { for (uint32_t low_bits : map_entry.second) *previous++ = uniteBytes(map_entry.first, low_bits); return previous; @@ -601,7 +601,7 @@ public: */ void iterate(roaring_iterator64 iterator, void* ptr) const { std::for_each(roarings.begin(), roarings.cend(), - [=](const std::pair& map_entry) { + [=](const std::pair& map_entry) { roaring_iterate64(&map_entry.second.roaring, iterator, uint64_t(map_entry.first) << 32, ptr); }); @@ -669,7 +669,7 @@ public: // push map size buf = (char*)encode_varint64((uint8_t*)buf, roarings.size()); std::for_each(roarings.cbegin(), roarings.cend(), - [&buf](const std::pair& map_entry) { + [&buf](const std::pair& map_entry) { // push map key encode_fixed32_le((uint8_t*)buf, map_entry.first); buf += sizeof(uint32_t); @@ -731,7 +731,7 @@ public: // start with type code, map size and size of keys for each map entry size_t init = 1 + varint_length(roarings.size()) + roarings.size() * sizeof(uint32_t); return std::accumulate(roarings.cbegin(), roarings.cend(), init, - [=](size_t previous, const std::pair& map_entry) { + [=](size_t previous, const std::pair& map_entry) { // add in bytes used by each Roaring return previous + map_entry.second.getSizeInBytes(); }); @@ -805,7 +805,7 @@ public: }, (void*)&outer_iter_data); std::for_each( - ++map_iter, roarings.cend(), [](const std::pair& map_entry) { + ++map_iter, roarings.cend(), [](const std::pair& map_entry) { map_entry.second.iterate( [](uint32_t low_bits, void* high_bits) -> bool { std::printf(",%llu", (long long unsigned)uniteBytes( @@ -844,7 +844,7 @@ public: (void*)&outer_iter_data); std::for_each( ++map_iter, roarings.cend(), - [&outer_iter_data](const std::pair& map_entry) { + [&outer_iter_data](const std::pair& map_entry) { outer_iter_data.high_bits = map_entry.first; map_entry.second.iterate( [](uint32_t low_bits, void* inner_iter_data) -> bool {