Skip to content

Commit 7147374

Browse files
committed
👷 Tidy up some code
1 parent bdde90f commit 7147374

File tree

2 files changed

+8
-25
lines changed

2 files changed

+8
-25
lines changed

Diff for: include/msg/detail/rle_codec.hpp

+7-23
Original file line numberDiff line numberDiff line change
@@ -16,25 +16,8 @@
1616

1717
namespace msg::detail {
1818

19-
template <std::size_t N> struct smallest_storage {
20-
// select a minimum sized type for indexing into the RLE data blob
21-
static CONSTEVAL auto select_index_storage() {
22-
if constexpr (N <= std::numeric_limits<std::uint8_t>::max()) {
23-
return std::uint8_t{};
24-
} else if constexpr (N <= std::numeric_limits<std::uint16_t>::max()) {
25-
return std::uint16_t{};
26-
} else if constexpr (N <= std::numeric_limits<std::uint32_t>::max()) {
27-
return std::uint32_t{};
28-
} else {
29-
return std::size_t{};
30-
}
31-
}
32-
33-
using type = decltype(select_index_storage());
34-
};
35-
3619
template <std::size_t N>
37-
using smallest_storage_type = typename smallest_storage<N>::type;
20+
using smallest_storage_type = decltype(stdx::detail::select_storage<N, void>());
3821

3922
// Captures RLE data for decoding and provides a mechanism to
4023
// get a single-use enumerator to step through bits in the encoded
@@ -204,11 +187,6 @@ struct rle_intersect {
204187
constexpr explicit rle_intersect(Decoders &&...decoders)
205188
: decoder_list{std::forward<Decoders>(decoders)...} {}
206189

207-
constexpr static auto min_chunk(chunk_type const &a, chunk_type const &b)
208-
-> bool {
209-
return a.bit_chunk() < b.bit_chunk();
210-
}
211-
212190
// iterate over set bits, passing them to bool (&f)(auto bit_number).
213191
// if f returns true, we abort and return true indicating early exit
214192
// otherwise return false to indicate no early abort of iteration
@@ -221,12 +199,18 @@ struct rle_intersect {
221199
chunks.push_back(d.make_chunk_enumerator());
222200
}
223201

202+
// advance all chunks by a number of bits
224203
auto advance = [&](std::size_t bits) {
225204
for (auto &c : chunks) {
226205
c.advance(bits);
227206
}
228207
};
229208

209+
// comparison of chunk bit counts
210+
auto min_chunk = [](chunk_type const &a, chunk_type const &b) -> bool {
211+
return a.bit_chunk() < b.bit_chunk();
212+
};
213+
230214
std::size_t bit{0};
231215
while (bit < num_bits) {
232216
// the min "bit_chunk" item in the chunk list is the smallest run

Diff for: include/msg/rle_indexed_handler.hpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@ struct rle_indices : IndicesT... {
1313
: IndicesT{index_args}..., storage{data} {}
1414

1515
constexpr auto operator()(auto const &data) const {
16-
// use a proxy to allow intersection without materializing a full
17-
// bitset.
16+
// proxy to allow intersection without materializing a full bitset.
1817
return detail::rle_intersect{std::forward<decltype(storage.decode(
1918
this->IndicesT::operator()(data)))>(
2019
storage.decode(this->IndicesT::operator()(data)))...};

0 commit comments

Comments
 (0)