2 releases
0.4.1 | Oct 5, 2023 |
---|---|
0.4.0 | Nov 16, 2022 |
#218 in Biology
44 downloads per month
Used in bfield
41KB
845 lines
mmap-bitvec
mmap-bitvec
is a library for working with bit-vectors backed by memory-mapped files. Included is a simple Bloom filter built on top of such bit-vectors.
Examples
Using a memory-mapped bit-vector:
// Build an in-memory bit-vector with a capacity of 128 bits.
use mmap_bitvec::{MmapBitVec, BitVector};
let mut bitvec = MmapBitVec::from_memory(128).unwrap();
bitvec.set(2, true);
assert!(bitvec.get(2));
assert_eq!(bitvec.get_range(0..8), 0b00100000);
// Write the bit-vector to disk, passing in `None` where an optional magic bytes arg can be set
let dir = tempfile::tempdir().unwrap();
bitvec.save_to_disk(dir.path().join("test"), None, &[])
.unwrap();
let f = MmapBitVec::open(dir.path().join("test"), None, false).unwrap();
assert_eq!(f.get(2), true);
Using the Bloom filter:
use mmap_bitvec::{BloomFilter};
// Create a Bloom filter with a capacity of 100 bits that uses 2 hash functions on each insert.
let mut filter = BloomFilter::new(Some("./test.bloom"), 100, 2).unwrap();
let (a, b) = (1, 2);
assert!(!filter.contains(a));
assert!(!filter.contains(b));
filter.insert(b);
assert!(!filter.contains(a));
assert!(filter.contains(b));
License
This project is licensed under the MIT license.
Dependencies
~180KB