be/src/util/bitmap_intersect.h
Line | Count | Source |
1 | | // Licensed to the Apache Software Foundation (ASF) under one |
2 | | // or more contributor license agreements. See the NOTICE file |
3 | | // distributed with this work for additional information |
4 | | // regarding copyright ownership. The ASF licenses this file |
5 | | // to you under the Apache License, Version 2.0 (the |
6 | | // "License"); you may not use this file except in compliance |
7 | | // with the License. You may obtain a copy of the License at |
8 | | // |
9 | | // http://www.apache.org/licenses/LICENSE-2.0 |
10 | | // |
11 | | // Unless required by applicable law or agreed to in writing, |
12 | | // software distributed under the License is distributed on an |
13 | | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
14 | | // KIND, either express or implied. See the License for the |
15 | | // specific language governing permissions and limitations |
16 | | // under the License. |
17 | | #pragma once |
18 | | #include <parallel_hashmap/phmap.h> |
19 | | |
20 | | #include "common/cast_set.h" |
21 | | #include "core/string_ref.h" |
22 | | #include "core/value/bitmap_value.h" |
23 | | #include "util/unaligned.h" |
24 | | |
25 | | namespace doris { |
26 | | |
27 | | namespace detail { |
28 | | class Helper { |
29 | | public: |
30 | | static const int DATETIME_PACKED_TIME_BYTE_SIZE = 8; |
31 | | static const int DATETIME_TYPE_BYTE_SIZE = 4; |
32 | | static const int DECIMAL_BYTE_SIZE = 16; |
33 | | |
34 | | // serialize_size start |
35 | | template <typename T> |
36 | 336 | static int32_t serialize_size(const T& v) { |
37 | 336 | return sizeof(T); |
38 | 336 | } _ZN5doris6detail6Helper14serialize_sizeIaEEiRKT_ Line | Count | Source | 36 | 6 | static int32_t serialize_size(const T& v) { | 37 | 6 | return sizeof(T); | 38 | 6 | } |
_ZN5doris6detail6Helper14serialize_sizeIsEEiRKT_ Line | Count | Source | 36 | 7 | static int32_t serialize_size(const T& v) { | 37 | 7 | return sizeof(T); | 38 | 7 | } |
_ZN5doris6detail6Helper14serialize_sizeIiEEiRKT_ Line | Count | Source | 36 | 323 | static int32_t serialize_size(const T& v) { | 37 | 323 | return sizeof(T); | 38 | 323 | } |
Unexecuted instantiation: _ZN5doris6detail6Helper14serialize_sizeIlEEiRKT_ Unexecuted instantiation: _ZN5doris6detail6Helper14serialize_sizeInEEiRKT_ |
39 | | |
40 | | // write_to start |
41 | | template <typename T> |
42 | 336 | static char* write_to(const T& v, char* dest) { |
43 | 336 | size_t type_size = sizeof(T); |
44 | 336 | memcpy(dest, &v, type_size); |
45 | 336 | dest += type_size; |
46 | 336 | return dest; |
47 | 336 | } _ZN5doris6detail6Helper8write_toIaEEPcRKT_S3_ Line | Count | Source | 42 | 6 | static char* write_to(const T& v, char* dest) { | 43 | 6 | size_t type_size = sizeof(T); | 44 | 6 | memcpy(dest, &v, type_size); | 45 | 6 | dest += type_size; | 46 | 6 | return dest; | 47 | 6 | } |
_ZN5doris6detail6Helper8write_toIsEEPcRKT_S3_ Line | Count | Source | 42 | 7 | static char* write_to(const T& v, char* dest) { | 43 | 7 | size_t type_size = sizeof(T); | 44 | 7 | memcpy(dest, &v, type_size); | 45 | 7 | dest += type_size; | 46 | 7 | return dest; | 47 | 7 | } |
_ZN5doris6detail6Helper8write_toIiEEPcRKT_S3_ Line | Count | Source | 42 | 323 | static char* write_to(const T& v, char* dest) { | 43 | 323 | size_t type_size = sizeof(T); | 44 | 323 | memcpy(dest, &v, type_size); | 45 | 323 | dest += type_size; | 46 | 323 | return dest; | 47 | 323 | } |
Unexecuted instantiation: _ZN5doris6detail6Helper8write_toIlEEPcRKT_S3_ Unexecuted instantiation: _ZN5doris6detail6Helper8write_toInEEPcRKT_S3_ |
48 | | |
49 | | // read_from start |
50 | | template <typename T> |
51 | 257 | static void read_from(const char** src, T* result) { |
52 | 257 | size_t type_size = sizeof(T); |
53 | 257 | memcpy(result, *src, type_size); |
54 | 257 | *src += type_size; |
55 | 257 | } _ZN5doris6detail6Helper9read_fromIaEEvPPKcPT_ Line | Count | Source | 51 | 6 | static void read_from(const char** src, T* result) { | 52 | 6 | size_t type_size = sizeof(T); | 53 | 6 | memcpy(result, *src, type_size); | 54 | 6 | *src += type_size; | 55 | 6 | } |
_ZN5doris6detail6Helper9read_fromIsEEvPPKcPT_ Line | Count | Source | 51 | 7 | static void read_from(const char** src, T* result) { | 52 | 7 | size_t type_size = sizeof(T); | 53 | 7 | memcpy(result, *src, type_size); | 54 | 7 | *src += type_size; | 55 | 7 | } |
_ZN5doris6detail6Helper9read_fromIiEEvPPKcPT_ Line | Count | Source | 51 | 244 | static void read_from(const char** src, T* result) { | 52 | 244 | size_t type_size = sizeof(T); | 53 | 244 | memcpy(result, *src, type_size); | 54 | 244 | *src += type_size; | 55 | 244 | } |
Unexecuted instantiation: _ZN5doris6detail6Helper9read_fromIlEEvPPKcPT_ Unexecuted instantiation: _ZN5doris6detail6Helper9read_fromInEEvPPKcPT_ |
56 | | }; |
57 | | |
58 | | template <> |
59 | | inline char* Helper::write_to<VecDateTimeValue>(const VecDateTimeValue& v, char* dest) { |
60 | | // dest may be arbitrarily aligned (variable-length keys precede us), use |
61 | | // memcpy-based unaligned stores instead of casted stores (UB). |
62 | | unaligned_store<int64_t>(dest, v.to_int64_datetime_packed()); |
63 | | dest += DATETIME_PACKED_TIME_BYTE_SIZE; |
64 | | unaligned_store<int>(dest, v.type()); |
65 | | dest += DATETIME_TYPE_BYTE_SIZE; |
66 | | return dest; |
67 | | } |
68 | | |
69 | | template <> |
70 | 0 | inline char* Helper::write_to<DecimalV2Value>(const DecimalV2Value& v, char* dest) { |
71 | 0 | __int128 value = v.value(); |
72 | 0 | memcpy(dest, &value, DECIMAL_BYTE_SIZE); |
73 | 0 | dest += DECIMAL_BYTE_SIZE; |
74 | 0 | return dest; |
75 | 0 | } |
76 | | |
77 | | template <> |
78 | 0 | inline char* Helper::write_to<StringRef>(const StringRef& v, char* dest) { |
79 | 0 | unaligned_store<int32_t>(dest, cast_set<int32_t>(v.size)); |
80 | 0 | dest += 4; |
81 | 0 | memcpy(dest, v.data, v.size); |
82 | 0 | dest += v.size; |
83 | 0 | return dest; |
84 | 0 | } |
85 | | |
86 | | template <> |
87 | 11 | inline char* Helper::write_to<std::string>(const std::string& v, char* dest) { |
88 | 11 | unaligned_store<uint32_t>(dest, cast_set<uint32_t>(v.size())); |
89 | 11 | dest += 4; |
90 | 11 | memcpy(dest, v.c_str(), v.size()); |
91 | 11 | dest += v.size(); |
92 | 11 | return dest; |
93 | 11 | } |
94 | | // write_to end |
95 | | |
96 | | template <> |
97 | | inline int32_t Helper::serialize_size<VecDateTimeValue>(const VecDateTimeValue& v) { |
98 | | return Helper::DATETIME_PACKED_TIME_BYTE_SIZE + Helper::DATETIME_TYPE_BYTE_SIZE; |
99 | | } |
100 | | |
101 | | template <> |
102 | 0 | inline int32_t Helper::serialize_size<DecimalV2Value>(const DecimalV2Value& v) { |
103 | 0 | return Helper::DECIMAL_BYTE_SIZE; |
104 | 0 | } |
105 | | |
106 | | template <> |
107 | 0 | inline int32_t Helper::serialize_size<StringRef>(const StringRef& v) { |
108 | 0 | return cast_set<int32_t>(v.size + 4); |
109 | 0 | } |
110 | | |
111 | | template <> |
112 | 11 | inline int32_t Helper::serialize_size<std::string>(const std::string& v) { |
113 | 11 | return cast_set<int32_t>(v.size() + 4); |
114 | 11 | } |
115 | | // serialize_size end |
116 | | |
117 | | template <> |
118 | | inline void Helper::read_from<VecDateTimeValue>(const char** src, VecDateTimeValue* result) { |
119 | | result->from_packed_time(unaligned_load<int64_t>(*src)); |
120 | | *src += DATETIME_PACKED_TIME_BYTE_SIZE; |
121 | | if (unaligned_load<int>(*src) == TIME_DATE) { |
122 | | result->cast_to_date(); |
123 | | } |
124 | | *src += DATETIME_TYPE_BYTE_SIZE; |
125 | | } |
126 | | |
127 | | template <> |
128 | 0 | inline void Helper::read_from<DecimalV2Value>(const char** src, DecimalV2Value* result) { |
129 | 0 | __int128 v = 0; |
130 | 0 | memcpy(&v, *src, DECIMAL_BYTE_SIZE); |
131 | 0 | *src += DECIMAL_BYTE_SIZE; |
132 | 0 | *result = DecimalV2Value(v); |
133 | 0 | } |
134 | | |
135 | | template <> |
136 | 0 | inline void Helper::read_from<StringRef>(const char** src, StringRef* result) { |
137 | 0 | int32_t length = unaligned_load<int32_t>(*src); |
138 | 0 | *src += 4; |
139 | 0 | *result = StringRef((char*)*src, length); |
140 | 0 | *src += length; |
141 | 0 | } |
142 | | |
143 | | template <> |
144 | 11 | inline void Helper::read_from<std::string>(const char** src, std::string* result) { |
145 | 11 | int32_t length = unaligned_load<int32_t>(*src); |
146 | 11 | *src += 4; |
147 | 11 | *result = std::string((char*)*src, length); |
148 | 11 | *src += length; |
149 | 11 | } |
150 | | // read_from end |
151 | | } // namespace detail |
152 | | |
153 | | // Calculate the intersection of two or more bitmaps |
154 | | // Usage: intersect_count(bitmap_column_to_count, filter_column, filter_values ...) |
155 | | // Example: intersect_count(user_id, event, 'A', 'B', 'C'), meaning find the intersect count of user_id in all A/B/C 3 bitmaps |
156 | | // Todo(kks) Use Array type instead of variable arguments |
157 | | template <typename T> |
158 | | struct BitmapIntersect { |
159 | | public: |
160 | 522 | BitmapIntersect() = default; _ZN5doris15BitmapIntersectINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEEC2Ev Line | Count | Source | 160 | 16 | BitmapIntersect() = default; |
_ZN5doris15BitmapIntersectIaEC2Ev Line | Count | Source | 160 | 9 | BitmapIntersect() = default; |
_ZN5doris15BitmapIntersectIsEC2Ev Line | Count | Source | 160 | 20 | BitmapIntersect() = default; |
_ZN5doris15BitmapIntersectIiEC2Ev Line | Count | Source | 160 | 326 | BitmapIntersect() = default; |
_ZN5doris15BitmapIntersectIlEC2Ev Line | Count | Source | 160 | 151 | BitmapIntersect() = default; |
Unexecuted instantiation: _ZN5doris15BitmapIntersectInEC2Ev |
161 | | |
162 | | explicit BitmapIntersect(const char* src) { deserialize(src); } |
163 | | |
164 | 285 | void add_key(const T key) { |
165 | 285 | BitmapValue empty_bitmap; |
166 | 285 | _bitmaps[key] = empty_bitmap; |
167 | 285 | } _ZN5doris15BitmapIntersectINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEE7add_keyES6_ Line | Count | Source | 164 | 9 | void add_key(const T key) { | 165 | 9 | BitmapValue empty_bitmap; | 166 | 9 | _bitmaps[key] = empty_bitmap; | 167 | 9 | } |
_ZN5doris15BitmapIntersectIaE7add_keyEa Line | Count | Source | 164 | 6 | void add_key(const T key) { | 165 | 6 | BitmapValue empty_bitmap; | 166 | 6 | _bitmaps[key] = empty_bitmap; | 167 | 6 | } |
_ZN5doris15BitmapIntersectIsE7add_keyEs Line | Count | Source | 164 | 3 | void add_key(const T key) { | 165 | 3 | BitmapValue empty_bitmap; | 166 | 3 | _bitmaps[key] = empty_bitmap; | 167 | 3 | } |
_ZN5doris15BitmapIntersectIiE7add_keyEi Line | Count | Source | 164 | 247 | void add_key(const T key) { | 165 | 247 | BitmapValue empty_bitmap; | 166 | 247 | _bitmaps[key] = empty_bitmap; | 167 | 247 | } |
_ZN5doris15BitmapIntersectIlE7add_keyEl Line | Count | Source | 164 | 20 | void add_key(const T key) { | 165 | 20 | BitmapValue empty_bitmap; | 166 | 20 | _bitmaps[key] = empty_bitmap; | 167 | 20 | } |
Unexecuted instantiation: _ZN5doris15BitmapIntersectInE7add_keyEn |
168 | | |
169 | 196 | void update(const T& key, const BitmapValue& bitmap) { |
170 | 196 | if (_bitmaps.find(key) != _bitmaps.end()) { |
171 | 67 | _bitmaps[key] |= bitmap; |
172 | 67 | } |
173 | 196 | } _ZN5doris15BitmapIntersectINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEE6updateERKS6_RKNS_11BitmapValueE Line | Count | Source | 169 | 9 | void update(const T& key, const BitmapValue& bitmap) { | 170 | 9 | if (_bitmaps.find(key) != _bitmaps.end()) { | 171 | 9 | _bitmaps[key] |= bitmap; | 172 | 9 | } | 173 | 9 | } |
_ZN5doris15BitmapIntersectIaE6updateERKaRKNS_11BitmapValueE Line | Count | Source | 169 | 15 | void update(const T& key, const BitmapValue& bitmap) { | 170 | 15 | if (_bitmaps.find(key) != _bitmaps.end()) { | 171 | 2 | _bitmaps[key] |= bitmap; | 172 | 2 | } | 173 | 15 | } |
_ZN5doris15BitmapIntersectIsE6updateERKsRKNS_11BitmapValueE Line | Count | Source | 169 | 3 | void update(const T& key, const BitmapValue& bitmap) { | 170 | 3 | if (_bitmaps.find(key) != _bitmaps.end()) { | 171 | 3 | _bitmaps[key] |= bitmap; | 172 | 3 | } | 173 | 3 | } |
_ZN5doris15BitmapIntersectIiE6updateERKiRKNS_11BitmapValueE Line | Count | Source | 169 | 141 | void update(const T& key, const BitmapValue& bitmap) { | 170 | 141 | if (_bitmaps.find(key) != _bitmaps.end()) { | 171 | 33 | _bitmaps[key] |= bitmap; | 172 | 33 | } | 173 | 141 | } |
_ZN5doris15BitmapIntersectIlE6updateERKlRKNS_11BitmapValueE Line | Count | Source | 169 | 28 | void update(const T& key, const BitmapValue& bitmap) { | 170 | 28 | if (_bitmaps.find(key) != _bitmaps.end()) { | 171 | 20 | _bitmaps[key] |= bitmap; | 172 | 20 | } | 173 | 28 | } |
Unexecuted instantiation: _ZN5doris15BitmapIntersectInE6updateERKnRKNS_11BitmapValueE |
174 | | |
175 | 127 | void merge(const BitmapIntersect& other) { |
176 | 247 | for (auto& kv : other._bitmaps) { |
177 | 247 | if (_bitmaps.find(kv.first) != _bitmaps.end()) { |
178 | 128 | _bitmaps[kv.first] |= kv.second; |
179 | 128 | } else { |
180 | 119 | _bitmaps[kv.first] = kv.second; |
181 | 119 | } |
182 | 247 | } |
183 | 127 | } _ZN5doris15BitmapIntersectIaE5mergeERKS1_ Line | Count | Source | 175 | 3 | void merge(const BitmapIntersect& other) { | 176 | 6 | for (auto& kv : other._bitmaps) { | 177 | 6 | if (_bitmaps.find(kv.first) != _bitmaps.end()) { | 178 | 4 | _bitmaps[kv.first] |= kv.second; | 179 | 4 | } else { | 180 | 2 | _bitmaps[kv.first] = kv.second; | 181 | 2 | } | 182 | 6 | } | 183 | 3 | } |
_ZN5doris15BitmapIntersectIsE5mergeERKS1_ Line | Count | Source | 175 | 7 | void merge(const BitmapIntersect& other) { | 176 | 7 | for (auto& kv : other._bitmaps) { | 177 | 7 | if (_bitmaps.find(kv.first) != _bitmaps.end()) { | 178 | 0 | _bitmaps[kv.first] |= kv.second; | 179 | 7 | } else { | 180 | 7 | _bitmaps[kv.first] = kv.second; | 181 | 7 | } | 182 | 7 | } | 183 | 7 | } |
_ZN5doris15BitmapIntersectIiE5mergeERKS1_ Line | Count | Source | 175 | 117 | void merge(const BitmapIntersect& other) { | 176 | 234 | for (auto& kv : other._bitmaps) { | 177 | 234 | if (_bitmaps.find(kv.first) != _bitmaps.end()) { | 178 | 124 | _bitmaps[kv.first] |= kv.second; | 179 | 124 | } else { | 180 | 110 | _bitmaps[kv.first] = kv.second; | 181 | 110 | } | 182 | 234 | } | 183 | 117 | } |
Unexecuted instantiation: _ZN5doris15BitmapIntersectIlE5mergeERKS1_ Unexecuted instantiation: _ZN5doris15BitmapIntersectInE5mergeERKS1_ |
184 | | |
185 | | // intersection |
186 | 39 | BitmapValue intersect() const { |
187 | 39 | BitmapValue result; |
188 | 39 | if (_bitmaps.empty()) { |
189 | 1 | return result; |
190 | 1 | } |
191 | 38 | auto it = _bitmaps.begin(); |
192 | 38 | result |= it->second; |
193 | 38 | it++; |
194 | 94 | for (; it != _bitmaps.end(); it++) { |
195 | 56 | result &= it->second; |
196 | 56 | } |
197 | 38 | return result; |
198 | 39 | } _ZNK5doris15BitmapIntersectIaE9intersectEv Line | Count | Source | 186 | 1 | BitmapValue intersect() const { | 187 | 1 | BitmapValue result; | 188 | 1 | if (_bitmaps.empty()) { | 189 | 0 | return result; | 190 | 0 | } | 191 | 1 | auto it = _bitmaps.begin(); | 192 | 1 | result |= it->second; | 193 | 1 | it++; | 194 | 2 | for (; it != _bitmaps.end(); it++) { | 195 | 1 | result &= it->second; | 196 | 1 | } | 197 | 1 | return result; | 198 | 1 | } |
_ZNK5doris15BitmapIntersectIsE9intersectEv Line | Count | Source | 186 | 3 | BitmapValue intersect() const { | 187 | 3 | BitmapValue result; | 188 | 3 | if (_bitmaps.empty()) { | 189 | 0 | return result; | 190 | 0 | } | 191 | 3 | auto it = _bitmaps.begin(); | 192 | 3 | result |= it->second; | 193 | 3 | it++; | 194 | 3 | for (; it != _bitmaps.end(); it++) { | 195 | 0 | result &= it->second; | 196 | 0 | } | 197 | 3 | return result; | 198 | 3 | } |
_ZNK5doris15BitmapIntersectIiE9intersectEv Line | Count | Source | 186 | 18 | BitmapValue intersect() const { | 187 | 18 | BitmapValue result; | 188 | 18 | if (_bitmaps.empty()) { | 189 | 0 | return result; | 190 | 0 | } | 191 | 18 | auto it = _bitmaps.begin(); | 192 | 18 | result |= it->second; | 193 | 18 | it++; | 194 | 45 | for (; it != _bitmaps.end(); it++) { | 195 | 27 | result &= it->second; | 196 | 27 | } | 197 | 18 | return result; | 198 | 18 | } |
_ZNK5doris15BitmapIntersectIlE9intersectEv Line | Count | Source | 186 | 17 | BitmapValue intersect() const { | 187 | 17 | BitmapValue result; | 188 | 17 | if (_bitmaps.empty()) { | 189 | 1 | return result; | 190 | 1 | } | 191 | 16 | auto it = _bitmaps.begin(); | 192 | 16 | result |= it->second; | 193 | 16 | it++; | 194 | 44 | for (; it != _bitmaps.end(); it++) { | 195 | 28 | result &= it->second; | 196 | 28 | } | 197 | 16 | return result; | 198 | 17 | } |
Unexecuted instantiation: _ZNK5doris15BitmapIntersectInE9intersectEv |
199 | | |
200 | | // calculate the intersection for _bitmaps's bitmap values |
201 | 36 | int64_t intersect_count() const { |
202 | 36 | if (_bitmaps.empty()) { |
203 | 4 | return 0; |
204 | 4 | } |
205 | 32 | return intersect().cardinality(); |
206 | 36 | } _ZNK5doris15BitmapIntersectIaE15intersect_countEv Line | Count | Source | 201 | 1 | int64_t intersect_count() const { | 202 | 1 | if (_bitmaps.empty()) { | 203 | 0 | return 0; | 204 | 0 | } | 205 | 1 | return intersect().cardinality(); | 206 | 1 | } |
_ZNK5doris15BitmapIntersectIsE15intersect_countEv Line | Count | Source | 201 | 3 | int64_t intersect_count() const { | 202 | 3 | if (_bitmaps.empty()) { | 203 | 0 | return 0; | 204 | 0 | } | 205 | 3 | return intersect().cardinality(); | 206 | 3 | } |
_ZNK5doris15BitmapIntersectIiE15intersect_countEv Line | Count | Source | 201 | 20 | int64_t intersect_count() const { | 202 | 20 | if (_bitmaps.empty()) { | 203 | 2 | return 0; | 204 | 2 | } | 205 | 18 | return intersect().cardinality(); | 206 | 20 | } |
_ZNK5doris15BitmapIntersectIlE15intersect_countEv Line | Count | Source | 201 | 12 | int64_t intersect_count() const { | 202 | 12 | if (_bitmaps.empty()) { | 203 | 2 | return 0; | 204 | 2 | } | 205 | 10 | return intersect().cardinality(); | 206 | 12 | } |
Unexecuted instantiation: _ZNK5doris15BitmapIntersectInE15intersect_countEv |
207 | | |
208 | | // the serialize size |
209 | 176 | size_t size() { |
210 | 176 | size_t size = 4; |
211 | 336 | for (auto& kv : _bitmaps) { |
212 | 336 | size += detail::Helper::serialize_size(kv.first); |
213 | 336 | size += kv.second.getSizeInBytes(); |
214 | 336 | } |
215 | 176 | return size; |
216 | 176 | } _ZN5doris15BitmapIntersectIaE4sizeEv Line | Count | Source | 209 | 4 | size_t size() { | 210 | 4 | size_t size = 4; | 211 | 6 | for (auto& kv : _bitmaps) { | 212 | 6 | size += detail::Helper::serialize_size(kv.first); | 213 | 6 | size += kv.second.getSizeInBytes(); | 214 | 6 | } | 215 | 4 | return size; | 216 | 4 | } |
_ZN5doris15BitmapIntersectIsE4sizeEv Line | Count | Source | 209 | 7 | size_t size() { | 210 | 7 | size_t size = 4; | 211 | 7 | for (auto& kv : _bitmaps) { | 212 | 7 | size += detail::Helper::serialize_size(kv.first); | 213 | 7 | size += kv.second.getSizeInBytes(); | 214 | 7 | } | 215 | 7 | return size; | 216 | 7 | } |
_ZN5doris15BitmapIntersectIiE4sizeEv Line | Count | Source | 209 | 165 | size_t size() { | 210 | 165 | size_t size = 4; | 211 | 323 | for (auto& kv : _bitmaps) { | 212 | 323 | size += detail::Helper::serialize_size(kv.first); | 213 | 323 | size += kv.second.getSizeInBytes(); | 214 | 323 | } | 215 | 165 | return size; | 216 | 165 | } |
Unexecuted instantiation: _ZN5doris15BitmapIntersectIlE4sizeEv Unexecuted instantiation: _ZN5doris15BitmapIntersectInE4sizeEv |
217 | | |
218 | | //must call size() first |
219 | 176 | void serialize(char* dest) { |
220 | 176 | char* writer = dest; |
221 | 176 | unaligned_store<int32_t>(writer, cast_set<int32_t>(_bitmaps.size())); |
222 | 176 | writer += 4; |
223 | 336 | for (auto& kv : _bitmaps) { |
224 | 336 | writer = detail::Helper::write_to(kv.first, writer); |
225 | 336 | kv.second.write_to(writer); |
226 | 336 | writer += kv.second.getSizeInBytes(); |
227 | 336 | } |
228 | 176 | } _ZN5doris15BitmapIntersectIaE9serializeEPc Line | Count | Source | 219 | 4 | void serialize(char* dest) { | 220 | 4 | char* writer = dest; | 221 | 4 | unaligned_store<int32_t>(writer, cast_set<int32_t>(_bitmaps.size())); | 222 | 4 | writer += 4; | 223 | 6 | for (auto& kv : _bitmaps) { | 224 | 6 | writer = detail::Helper::write_to(kv.first, writer); | 225 | 6 | kv.second.write_to(writer); | 226 | 6 | writer += kv.second.getSizeInBytes(); | 227 | 6 | } | 228 | 4 | } |
_ZN5doris15BitmapIntersectIsE9serializeEPc Line | Count | Source | 219 | 7 | void serialize(char* dest) { | 220 | 7 | char* writer = dest; | 221 | 7 | unaligned_store<int32_t>(writer, cast_set<int32_t>(_bitmaps.size())); | 222 | 7 | writer += 4; | 223 | 7 | for (auto& kv : _bitmaps) { | 224 | 7 | writer = detail::Helper::write_to(kv.first, writer); | 225 | 7 | kv.second.write_to(writer); | 226 | 7 | writer += kv.second.getSizeInBytes(); | 227 | 7 | } | 228 | 7 | } |
_ZN5doris15BitmapIntersectIiE9serializeEPc Line | Count | Source | 219 | 165 | void serialize(char* dest) { | 220 | 165 | char* writer = dest; | 221 | 165 | unaligned_store<int32_t>(writer, cast_set<int32_t>(_bitmaps.size())); | 222 | 165 | writer += 4; | 223 | 323 | for (auto& kv : _bitmaps) { | 224 | 323 | writer = detail::Helper::write_to(kv.first, writer); | 225 | 323 | kv.second.write_to(writer); | 226 | 323 | writer += kv.second.getSizeInBytes(); | 227 | 323 | } | 228 | 165 | } |
Unexecuted instantiation: _ZN5doris15BitmapIntersectIlE9serializeEPc Unexecuted instantiation: _ZN5doris15BitmapIntersectInE9serializeEPc |
229 | | |
230 | 136 | void deserialize(const char* src) { |
231 | 136 | const char* reader = src; |
232 | 136 | int32_t bitmaps_size = unaligned_load<int32_t>(reader); |
233 | 136 | reader += 4; |
234 | 393 | for (int32_t i = 0; i < bitmaps_size; i++) { |
235 | 257 | T key; |
236 | 257 | detail::Helper::read_from(&reader, &key); |
237 | 257 | BitmapValue bitmap(reader); |
238 | 257 | reader += bitmap.getSizeInBytes(); |
239 | 257 | _bitmaps[key] = bitmap; |
240 | 257 | } |
241 | 136 | } _ZN5doris15BitmapIntersectIaE11deserializeEPKc Line | Count | Source | 230 | 4 | void deserialize(const char* src) { | 231 | 4 | const char* reader = src; | 232 | 4 | int32_t bitmaps_size = unaligned_load<int32_t>(reader); | 233 | 4 | reader += 4; | 234 | 10 | for (int32_t i = 0; i < bitmaps_size; i++) { | 235 | 6 | T key; | 236 | 6 | detail::Helper::read_from(&reader, &key); | 237 | 6 | BitmapValue bitmap(reader); | 238 | 6 | reader += bitmap.getSizeInBytes(); | 239 | 6 | _bitmaps[key] = bitmap; | 240 | 6 | } | 241 | 4 | } |
_ZN5doris15BitmapIntersectIsE11deserializeEPKc Line | Count | Source | 230 | 7 | void deserialize(const char* src) { | 231 | 7 | const char* reader = src; | 232 | 7 | int32_t bitmaps_size = unaligned_load<int32_t>(reader); | 233 | 7 | reader += 4; | 234 | 14 | for (int32_t i = 0; i < bitmaps_size; i++) { | 235 | 7 | T key; | 236 | 7 | detail::Helper::read_from(&reader, &key); | 237 | 7 | BitmapValue bitmap(reader); | 238 | 7 | reader += bitmap.getSizeInBytes(); | 239 | 7 | _bitmaps[key] = bitmap; | 240 | 7 | } | 241 | 7 | } |
_ZN5doris15BitmapIntersectIiE11deserializeEPKc Line | Count | Source | 230 | 125 | void deserialize(const char* src) { | 231 | 125 | const char* reader = src; | 232 | 125 | int32_t bitmaps_size = unaligned_load<int32_t>(reader); | 233 | 125 | reader += 4; | 234 | 369 | for (int32_t i = 0; i < bitmaps_size; i++) { | 235 | 244 | T key; | 236 | 244 | detail::Helper::read_from(&reader, &key); | 237 | 244 | BitmapValue bitmap(reader); | 238 | 244 | reader += bitmap.getSizeInBytes(); | 239 | 244 | _bitmaps[key] = bitmap; | 240 | 244 | } | 241 | 125 | } |
Unexecuted instantiation: _ZN5doris15BitmapIntersectIlE11deserializeEPKc Unexecuted instantiation: _ZN5doris15BitmapIntersectInE11deserializeEPKc |
242 | | |
243 | | protected: |
244 | | std::map<T, BitmapValue> _bitmaps; |
245 | | }; |
246 | | |
247 | | template <> |
248 | | struct BitmapIntersect<std::string_view> { |
249 | | public: |
250 | 9 | BitmapIntersect() = default; |
251 | | |
252 | 0 | explicit BitmapIntersect(const char* src) { deserialize(src); } |
253 | | |
254 | 6 | void add_key(const std::string_view key) { |
255 | 6 | BitmapValue empty_bitmap; |
256 | 6 | _bitmaps[key] = empty_bitmap; |
257 | 6 | } |
258 | | |
259 | 15 | void update(const std::string_view& key, const BitmapValue& bitmap) { |
260 | 15 | if (_bitmaps.find(key) != _bitmaps.end()) { |
261 | 2 | _bitmaps[key] |= bitmap; |
262 | 2 | } |
263 | 15 | } |
264 | | |
265 | 3 | void merge(const BitmapIntersect& other) { |
266 | 6 | for (auto& kv : other._bitmaps) { |
267 | 6 | if (_bitmaps.find(kv.first) != _bitmaps.end()) { |
268 | 4 | _bitmaps[kv.first] |= kv.second; |
269 | 4 | } else { |
270 | 2 | _bitmaps[kv.first] = kv.second; |
271 | 2 | } |
272 | 6 | } |
273 | 3 | } |
274 | | |
275 | | // intersection |
276 | 1 | BitmapValue intersect() const { |
277 | 1 | BitmapValue result; |
278 | 1 | auto it = _bitmaps.begin(); |
279 | 1 | result |= it->second; |
280 | 1 | it++; |
281 | 2 | for (; it != _bitmaps.end(); it++) { |
282 | 1 | result &= it->second; |
283 | 1 | } |
284 | 1 | return result; |
285 | 1 | } |
286 | | |
287 | | // calculate the intersection for _bitmaps's bitmap values |
288 | 1 | int64_t intersect_count() const { |
289 | 1 | if (_bitmaps.empty()) { |
290 | 0 | return 0; |
291 | 0 | } |
292 | 1 | return intersect().cardinality(); |
293 | 1 | } |
294 | | |
295 | | // the serialize size |
296 | 4 | size_t size() { |
297 | 4 | size_t size = 4; |
298 | 6 | for (auto& kv : _bitmaps) { |
299 | 6 | size += detail::Helper::serialize_size(kv.first); |
300 | 6 | size += kv.second.getSizeInBytes(); |
301 | 6 | } |
302 | 4 | return size; |
303 | 4 | } |
304 | | |
305 | | //must call size() first |
306 | 4 | void serialize(char* dest) { |
307 | 4 | char* writer = dest; |
308 | 4 | unaligned_store<int32_t>(writer, cast_set<int32_t>(_bitmaps.size())); |
309 | 4 | writer += 4; |
310 | 6 | for (auto& kv : _bitmaps) { |
311 | 6 | writer = detail::Helper::write_to(kv.first, writer); |
312 | 6 | kv.second.write_to(writer); |
313 | 6 | writer += kv.second.getSizeInBytes(); |
314 | 6 | } |
315 | 4 | } |
316 | | |
317 | 4 | void deserialize(const char* src) { |
318 | 4 | const char* reader = src; |
319 | 4 | int32_t bitmaps_size = unaligned_load<int32_t>(reader); |
320 | 4 | reader += 4; |
321 | 10 | for (int32_t i = 0; i < bitmaps_size; i++) { |
322 | 6 | std::string key; |
323 | 6 | detail::Helper::read_from(&reader, &key); |
324 | 6 | BitmapValue bitmap(reader); |
325 | 6 | reader += bitmap.getSizeInBytes(); |
326 | 6 | _bitmaps[key] = bitmap; |
327 | 6 | } |
328 | 4 | } |
329 | | |
330 | | protected: |
331 | | phmap::flat_hash_map<std::string, BitmapValue> _bitmaps; |
332 | | }; |
333 | | } // namespace doris |