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