Make BloomFilter.bitSize() public#8198
Make BloomFilter.bitSize() public#8198nickita-khylkouski wants to merge 1 commit intogoogle:masterfrom
Conversation
This change makes the existing bitSize() method public (previously package-private with @VisibleForTesting) to allow users to determine the serialization size of a BloomFilter without actually serializing it. This is useful when pre-allocating space in file formats that embed Bloom filters. The serialization size can be calculated as: bitSize() / 8 + 6 bytes (for the header). The method is documented with: - Javadoc explaining its purpose and the serialization size formula - @SInCE 35.0 annotation Also adds testBitSizeMatchesSerializationSize() test to verify that bitSize() correctly predicts the writeTo() output size. Fixes google#6866
See #8198 RELNOTES=n/a PiperOrigin-RevId: 866534945
See #8198 RELNOTES=n/a PiperOrigin-RevId: 866662371
|
I wonder if it'd be more convenient for users if we exposed an API that tells you how many bytes (instead of bits) the underlying |
|
waves I'm not convinced that More |
|
Great suggestions! I agree — returning bytes with the header included is a cleaner API. Users shouldn't need to do the For naming, a few options:
I lean toward |
Summary
This PR makes the existing
bitSize()method inBloomFilterpublic. Previously it was package-private with@VisibleForTesting.Motivation
Users who embed Bloom filters in custom file formats need to know the serialization size before writing to pre-allocate space (e.g., for memory-mapped files or fixed-size records). Currently the only way to determine the size is to actually serialize the filter, which is inefficient.
Changes
bitSize()visibility from package-private topublic@VisibleForTestingannotationbitSize() / 8 + 6bytes@since 35.0annotationTests
Added
testBitSizeMatchesSerializationSize()test that verifiesbitSize()correctly predicts thewriteTo()output size across various configurations.Test plan
testBitSizeMatchesSerializationSize()validates the size calculation formulatestBitSize()test continues to pass (now testing public API)Fixes #6866