zhangstar333 commented on code in PR #11936: URL: https://github.com/apache/doris/pull/11936#discussion_r950981024
########## be/src/util/bitmap_intersect.h: ########## @@ -242,4 +266,91 @@ struct BitmapIntersect { std::map<T, BitmapValue> _bitmaps; }; +template <> +struct BitmapIntersect<std::string_view> { +public: + BitmapIntersect() = default; + + explicit BitmapIntersect(const char* src) { deserialize(src); } + + void add_key(const std::string_view key) { + BitmapValue empty_bitmap; + _bitmaps[key] = empty_bitmap; + } + + void update(const std::string_view& key, const BitmapValue& bitmap) { + if (_bitmaps.find(key) != _bitmaps.end()) { + _bitmaps[key] |= bitmap; + } + } + + void merge(const BitmapIntersect& other) { + for (auto& kv : other._bitmaps) { + if (_bitmaps.find(kv.first) != _bitmaps.end()) { + _bitmaps[kv.first] |= kv.second; + } else { + _bitmaps[kv.first] = kv.second; + } + } + } + + // intersection + BitmapValue intersect() const { + BitmapValue result; + auto it = _bitmaps.begin(); + result |= it->second; + it++; + for (; it != _bitmaps.end(); it++) { + result &= it->second; + } + return result; + } + + // calculate the intersection for _bitmaps's bitmap values + int64_t intersect_count() const { + if (_bitmaps.empty()) { + return 0; + } + return intersect().cardinality(); + } + + // the serialize size + size_t size() { + size_t size = 4; + for (auto& kv : _bitmaps) { + size += detail::Helper::serialize_size(kv.first); + size += kv.second.getSizeInBytes(); + } + return size; + } + + //must call size() first + void serialize(char* dest) { + char* writer = dest; + *(int32_t*)writer = _bitmaps.size(); + writer += 4; + for (auto& kv : _bitmaps) { + writer = detail::Helper::write_to(kv.first, writer); + kv.second.write(writer); + writer += kv.second.getSizeInBytes(); + } + } + + void deserialize(const char* src) { + const char* reader = src; + int32_t bitmaps_size = *(int32_t*)reader; + reader += 4; + for (int32_t i = 0; i < bitmaps_size; i++) { + std::string key; + detail::Helper::read_from(&reader, &key); + BitmapValue bitmap(reader); + reader += bitmap.getSizeInBytes(); + _bitmaps[key] = bitmap; + } + } + +private: + phmap::flat_hash_map<std::string, BitmapValue> _bitmaps; Review Comment: Is the ASAN error caused by the stringValue stored here as Key? -- 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: commits-unsubscr...@doris.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For additional commands, e-mail: commits-h...@doris.apache.org