#bitmap #dyn #sized #dynamically #dynamically-sized

dyn_bitmap

Dynamically sized lightweight bitmap implementation

4 releases (2 breaking)

0.3.2 Feb 17, 2021
0.3.1 Feb 4, 2021
0.1.0 Nov 15, 2020
0.0.2 Oct 26, 2020

#13 in #dynamically-sized

Download history 20/week @ 2024-01-07 115/week @ 2024-01-14 86/week @ 2024-01-21 98/week @ 2024-01-28 116/week @ 2024-02-04 145/week @ 2024-02-11 79/week @ 2024-02-18 84/week @ 2024-02-25 109/week @ 2024-03-03 56/week @ 2024-03-10 22/week @ 2024-03-17 2/week @ 2024-03-24 42/week @ 2024-03-31 21/week @ 2024-04-07 24/week @ 2024-04-14 36/week @ 2024-04-21

123 downloads per month

MIT license

15KB
235 lines

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();

Dependencies

~325–780KB
~18K SLoC