enhance: Utilize "find0" in segment.find_first (#39229)

Related to #39003

Previous PR #39004 has to clone & flip bitset due to bitset does not
support find0 operator. #39176 added this feature so clone & flip could
be removed now.

Signed-off-by: Congqi Xia <congqi.xia@zilliz.com>
pull/38943/head
congqixia 2025-01-14 14:14:58 +08:00 committed by GitHub
parent 3e788f0fbd
commit da1b786ef8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 4 additions and 13 deletions

View File

@ -1255,12 +1255,8 @@ ChunkedSegmentSealedImpl::find_first(int64_t limit,
std::vector<int64_t> seg_offsets;
seg_offsets.reserve(limit);
// flip bitset since `find_next` is used to find true.
auto flipped = bitset.clone();
flipped.flip();
int64_t offset = 0;
std::optional<size_t> result = flipped.find_first();
std::optional<size_t> result = bitset.find_first(false);
while (result.has_value() && hit_num < limit) {
hit_num++;
seg_offsets.push_back(result.value());
@ -1269,7 +1265,7 @@ ChunkedSegmentSealedImpl::find_first(int64_t limit,
// In fact, this case won't happen on sealed segments.
continue;
}
result = flipped.find_next(offset);
result = bitset.find_next(offset, false);
}
return {seg_offsets, more_hit_than_limit && result.has_value()};

View File

@ -1719,13 +1719,8 @@ SegmentSealedImpl::find_first(int64_t limit, const BitsetType& bitset) const {
std::vector<int64_t> seg_offsets;
seg_offsets.reserve(limit);
// flip bitset since `find_first` & `find_next` is used to find true.
// could be optimized by support find false in bitset.
auto flipped = bitset.clone();
flipped.flip();
int64_t offset = 0;
std::optional<size_t> result = flipped.find_first();
std::optional<size_t> result = bitset.find_first(false);
while (result.has_value() && hit_num < limit) {
hit_num++;
seg_offsets.push_back(result.value());
@ -1734,7 +1729,7 @@ SegmentSealedImpl::find_first(int64_t limit, const BitsetType& bitset) const {
// In fact, this case won't happen on sealed segments.
continue;
}
result = flipped.find_next(offset);
result = bitset.find_next(offset, false);
}
return {seg_offsets, more_hit_than_limit && result.has_value()};