Skip to content

Latest commit

History

47 Commits

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

mmap-bitvec

ciCrates.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};letmut 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 setlet 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.letmut 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.

About

Rust implementation of a mmap-based bit vector

Resources

Stars

6 stars

Watchers

9 watching

Forks

Releases

Packages

Used by

Contributors

Languages