BloomFilterSerializer
Custom KSerializer for BloomFilter that chooses between two wire formats based on density, to keep delta messages O(k) instead of O(m):
Sparse (
fmt = 0): when BloomFilter.nonZeroWordCount ≤ SPARSE_THRESHOLD. Encodes only the non-zero(wordIndex: Int, wordValue: Long)pairs as two parallelIntArray+LongArray. Anadd()delta spans at most k words — k=7 for a 1%-rate filter — so the wire payload is ~84 bytes vs ~12 KB dense for n=10 000.Dense (
fmt = 1): for fully-populated states (anti-entropy FullState). Encodes the fullLongArrayas before. Crossover point: once more than SPARSE_THRESHOLD words are non-zero the overhead of the index array exceeds the savings from omitting zeros.
Wire format (struct with fmt discriminator):
{ "fmt": 0, "bc": <bitCount>, "hc": <hashCount>,
"wi": <IntArray of word indices>, "wv": <LongArray of word values> } // sparse
{ "fmt": 1, "bc": <bitCount>, "hc": <hashCount>, "bits": <LongArray> } // denseContent copied to clipboard