#bitmap #bit #bit-flags #flags

bitmac

Structure for accessing to single bits

3 releases (breaking)

0.3.0 Aug 31, 2022
0.2.0 Aug 15, 2022
0.1.0 Aug 15, 2022

#1961 in Data structures

Download history 10/week @ 2024-09-02 7/week @ 2024-09-16 20/week @ 2024-09-23 17/week @ 2024-09-30 7/week @ 2024-10-07 15/week @ 2024-10-14 1/week @ 2024-10-21 8/week @ 2024-11-04 20/week @ 2024-11-11 21/week @ 2024-12-02 45/week @ 2024-12-09

66 downloads per month

MIT/Apache

150KB
3K SLoC

bitmac

This library provides implementation of bitmap with custom bit accessing and resizing strategy.

crates.io docs.rs build

[dependencies]
bitmac = "0.3"

Features

Feature Description
bytes to implement ContainerRead trait for Bytes and ContainerRead, ContainerWrite, and Resizable traits for BytesMut
smallvec to implement ContainerRead, ContainerWrite and Resizable traits for SmallVec

Example

use bitmac::{StaticBitmap, LSB, Intersection, Union};

fn main() {
    let mut bitmap = StaticBitmap::<u16, LSB>::default();

    assert!(!bitmap.get(0));
    assert!(!bitmap.get(7));
    
    bitmap.set(0, true);
    bitmap.set(7, true);
    assert!(bitmap.get(0));
    assert!(bitmap.get(7));
    
    assert_eq!(bitmap.intersection_len(0b0000_1111_0000_0001u16), 1);
    assert_eq!(bitmap.union_len(0b0000_1111_0000_0001u16), 6);
}

License

Licensed under either of Apache License, Version 2.0 or MIT license at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in this crate by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Dependencies

~235–750KB
~17K SLoC