Crate fixed_bitmaps[][src]

Expand description

Fixed Bitmaps

This is a crate whose aim is to create the simplest bitmap structures to work with. This crate provides wrappings for Rust unsigned integers from u8 up to u128.

Note that indexing for bit access starts at 0, which allows you to know what the effect of setting a bit will be, by putting 2 to the power of the index. For example, the following example sets the 5th bit to true in an otherwise empty bitmap. This is equivalent to adding 25 () to the underlying value:

using fixed_bitmaps::Bitmap64;

let mut bitmap = Bitmap64::default;

// Set the 5th index (the 6th bit) to true.
// Can simply unwrap the result to remove the warning, as we know
// for certain that 5 < 64
bitmap.set(5, true).unwrap();

// The following will throw an error however, as the 64th index is out of bounds
// (the highest index in a `Bitmap64` is 63)

// Will print out the error thrown when trying to set an index out of bounds
match bitmap.set(64, true) {
    Ok(_) => println!("That wasn't meant to happen... something's up with my implementation!"),
    Err(error) => {
        println!("Yep, threw an error as expected. Error message is as follows:");
        eprintln!("{}", error);
    }
}

Structs

The smallest denomination of bitmap in this crate. This is simply a byte-long bitmap, useful for when only a few flags would be defined.

The next size up bitmap of length 16.

A bitmap of length 32. This would be the fastest bitmap to use on 32-bit architectures.

A bitmap of length 64. This would be the most commonly used one, and fastest on 64-bit architectures.

A bitmap of length 128.