dyn_bitmap

Crates.iodyn_bitmap
lib.rsdyn_bitmap
version0.3.2
sourcesrc
created_at2020-10-26 14:57:37.866714
updated_at2021-02-17 16:58:00.000255
descriptionDynamically sized lightweight bitmap implementation.
homepage
repositoryhttps://github.com/npatsakula/bitmap
max_upload_size
id305643
size15,986
Patsakula Nikita (npatsakula)

documentation

https://docs.rs/dyn_bitmap

README

Dynamic-sized lightweight bitmap

Explanation

Simple, fast and easy to use bitmap.

Example

use dyn_bitmap::DynBitmap;
use std::io::Write;

let source = [true, false, false].iter()
    .cycle()
    .take(256);

// You can construct bitmap from iterator with `Type = bool` or
// construct bitmap manually with `contained/1`.
//
// `DynBitmap` has high-performance `from_iter` method,
// which is preferable to `contained/1`.
let mut bitmap: DynBitmap = source.copied().collect();

// You can set value of bitmap using `set/2` function.
// It returns additional information in case of an error.
bitmap.set(true, 1).unwrap();
// You can check value of some particular bit using `get/1`.
// Note, that bit index starts from `0`.
assert_eq!(bitmap.get(1).unwrap(), true);

// You can iterate over bit values using `iter/0` function.
for (idx, value) in bitmap.iter().enumerate() {
    println!("{}: {}", idx, value);
}

let file = std::fs::File::open("foo.bin").unwrap();
// `write/1` function support writing binary bitmap representation
// to anything that implement `std::io::Write`.
bitmap.write(file).unwrap();
Commit count: 34

cargo fmt