diff --git a/ext/xor_singleheader b/ext/xor_singleheader index 5539876..14e12df 160000 --- a/ext/xor_singleheader +++ b/ext/xor_singleheader @@ -1 +1 @@ -Subproject commit 55398761ff07ff18596cb9b62c8d618fbe47ebdd +Subproject commit 14e12dfa2dd94007e4f0edc1f606ed2a6a6e6599 diff --git a/include/binfuse/filter.hpp b/include/binfuse/filter.hpp index e6da59b..c26e45e 100644 --- a/include/binfuse/filter.hpp +++ b/include/binfuse/filter.hpp @@ -113,7 +113,11 @@ class filter { return ftype::contains(needle, &fil_); } - [[nodiscard]] bool is_populated() const { return fil_.SegmentCount > 0; } + [[nodiscard]] std::size_t size() const { + return static_cast(fil_.Size); + } + + [[nodiscard]] bool is_populated() const { return size() > 0; } [[nodiscard]] std::size_t serialization_bytes() const { // upstream API should be const diff --git a/include/binfuse/sharded_filter.hpp b/include/binfuse/sharded_filter.hpp index 4c02d45..f0b5e5b 100644 --- a/include/binfuse/sharded_filter.hpp +++ b/include/binfuse/sharded_filter.hpp @@ -55,9 +55,9 @@ class sharded_filter : private sharded_mmap_base { } [[nodiscard]] bool contains(std::uint64_t needle) const { - auto prefix = extract_prefix(needle); + const auto prefix = extract_prefix(needle); // we know prefix is always < max_shards() by definition - auto& filter = filters[prefix]; + const auto& filter = filters[prefix]; if (!filter.is_populated()) { // this filter has not been populated. no fingerprint pointer // has been set and an upstream `contain` call will throw diff --git a/test/data/sharded_filter8_tiny.bin b/test/data/sharded_filter8_tiny.bin index 216a9bf..30ea2db 100644 Binary files a/test/data/sharded_filter8_tiny.bin and b/test/data/sharded_filter8_tiny.bin differ diff --git a/test/filter.cpp b/test/filter.cpp index 0d96692..3720484 100644 --- a/test/filter.cpp +++ b/test/filter.cpp @@ -25,6 +25,7 @@ TEST(binfuse_filter, construct_from_upstream) { // NOLINT binfuse::filter8 filter(std::move(fil)); // NOLINT not trivial EXPECT_TRUE(filter.is_populated()); + EXPECT_EQ(filter.size(), 3); EXPECT_TRUE(filter.contains(0x0000000000000000)); EXPECT_TRUE(filter.contains(0x0000000000000001)); EXPECT_TRUE(filter.contains(0x0000000000000002));