linrrzqqq commented on code in PR #70774:
URL: https://github.com/apache/doris/pull/70774#discussion_r4794724779
##########
be/src/core/value/bitmap_value.h:
##########
@@ -1035,6 +1041,351 @@ class Roaring64Map {
*bytes_read = (is_v1 ? 0 : 1) + readbytes;
return r;
}
+
+ // From CRoaring `ra_portable_header_size()` (`roaring_array.c`): header
size with run_bitset.
+ static size_t portable_header_size(int32_t size) {
+ if (size <= 0) {
+ return sizeof(uint32_t) * 2;
+ }
+ const size_t n = static_cast<size_t>(size);
+ // Always include run_bitset since cookie is fixed to SERIAL_COOKIE
(12347).
+ const size_t run_bitset_bytes = (n + 7) / 8;
+ const size_t base = sizeof(uint32_t) + run_bitset_bytes + n *
sizeof(uint32_t);
+ return (size < roaring::internal::NO_OFFSET_THRESHOLD) ? base
+ : (base + n *
sizeof(uint32_t));
+ }
+
+ // Upper bound for fixed-12347 serialization (+ ceil(n/8)-4 bytes when
n>32 without RUN yet).
+ static size_t max_serialized_size(const roaring::Roaring& src, bool is_v1)
{
+ const auto& ra = src.roaring.high_low_container;
+ if (ra.size <= 0 || (ra.flags & ROARING_FLAG_FROZEN) != 0) {
+ return src.getSizeInBytes(is_v1);
+ }
+ size_t portable_max = src.getSizeInBytes(true);
Review Comment:
设计取舍,少一次遍历,空间换时间
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]