A lightweight, thread-safe, and customizable Bloom Filter library in Go — built for speed, simplicity, and scale.
- Efficient probabilistic set membership testing
- Plug-and-play with custom hash functions
- Thread-safe for concurrent use
- Bit-level control & visualization utilities
- Persist/Load from file or JSON
Note: BitBloom was built as a foundational exercise. Expect bigger, more intricate systems soon.
go get github.com/Manaswa-S/bitbloom/bitbloomimport "github.com/Manaswa-S/bitbloom/bitbloom"
// create a new instance
bloom := bitbloom.NewBitBloom(20000, 4, nil, nil)
// add an element
bloom.Add("golang")
// check for an element
exists := bloom.Contains("golang") // true (probably)// save bit array
bloom.SaveToFile("filter.bloom")
// load bit array
bloom.LoadFromFile("filter.bloom")// print internal bit array
bloom.PrintBloom()
// ones count in the bit array
fmt.Println(bloom.OnesCount())- Dynamic Resizing and Partitions
- Bit level performance optimizations
- Stats
- Custom seeding
- The bloom filter uses a simple
[]byteslice to simulate a large bit array. - Instead of using
kdifferent hash functions, BitBloom uses 2 base hashes and derives multiple positions using:
for i := 0; i < rotations; i++ {
index{i} = (hash1 + (i * hash2)) % bloomSize
}- It uses custom implementation of XxHash 64-bit and MurMur Hash 64-bit.
-
You can customize the behavior of BitBloom using the
NewBitBloom()constructor. -
BitBloom supports filter size and index rotation customatizations and plugging in custom hash functions as long as they match this signature:
func(input string, seed uint64) uint64
// also Hash seeds are to be provided separately for them, if required.- Saving writes the bloom array as it is to a file, and therefore might incur corrupt files sometimes. (this will be resolved in further revisions by implementing a checksum)
go get github.com/Manaswa-S/bitbloom- includes a 'hashing' package containing my own implementations of the MurMurHash, XxHash, FNV-1a, etc.
- Also included in 'main' is the CLI menu/tool for bitbloom for testing/trial purposes.