mmap-bitvec

Crates.iommap-bitvec
lib.rsmmap-bitvec
version0.4.1
sourcesrc
created_at2022-11-16 23:16:18.827297
updated_at2023-10-05 21:21:23.699059
descriptionA library for working with bit-vectors backed by memory-mapped files
homepage
repositoryhttps://github.com/onecodex/mmap-bitvec
max_upload_size
id716759
size46,989
Nick Greenfield (boydgreenfield)

documentation

README

mmap-bitvec

ci Crates.io Version

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.

Commit count: 44

cargo fmt