[][src]Struct dyn_bitmap::DynBitmap

pub struct DynBitmap { /* fields omitted */ }

Dynamicaly sized bitmap.

let mut bitmap = dyn_bitmap::DynBitmap::contained(3);
bitmap.set(0).unwrap();
bitmap.set(2).unwrap();
assert!(bitmap.get(0).unwrap());
assert!(!bitmap.get(1).unwrap());
assert!(bitmap.get(2).unwrap());

Implementations

impl DynBitmap[src]

pub fn contained(bits: usize) -> Self[src]

Create new bitmap that is guaranteed to hold that many bits.

Example

use dyn_bitmap::DynBitmap;
let bimap = DynBitmap::contained(13);

pub const fn bytes_required(bits: usize) -> usize[src]

Amount of bytes required for bitmap serialization.

Example

use dyn_bitmap::DynBitmap;

let bitmap = DynBitmap::contained(10);
assert_eq!(bitmap.byte_size(), DynBitmap::bytes_required(10));

pub fn get(&self, bit_index: usize) -> Result<bool, Error>[src]

Get bit value.

Example

let mut bitmap = dyn_bitmap::DynBitmap::contained(3);
bitmap.set(0).unwrap();
assert!(bitmap.get(0).unwrap());
assert!(!bitmap.get(1).unwrap());

pub fn set(&mut self, bit_index: usize) -> Result<(), Error>[src]

Set bit value as true.

Example

let mut bitmap = dyn_bitmap::DynBitmap::contained(3);
assert!(!bitmap.get(0).unwrap());
bitmap.set(0).unwrap();
assert!(bitmap.get(0).unwrap());

pub fn clear(&mut self, bit_index: usize) -> Result<(), Error>[src]

Set bit value as false.

Example

let mut bitmap = dyn_bitmap::DynBitmap::contained(3);
bitmap.set(0).unwrap();
assert!(bitmap.get(0).unwrap());
bitmap.clear(0).unwrap();
assert!(!bitmap.get(0).unwrap());

pub fn write<W: Write>(&self, writer: W) -> Result<()>[src]

Write bitmap by impl std::io::Write.

Example

let mut bitmap = dyn_bitmap::DynBitmap::contained(8);

bitmap.set(0).unwrap();
bitmap.set(2).unwrap();
bitmap.set(4).unwrap();
bitmap.set(6).unwrap();

let mut buffer: Vec<u8> = Default::default();
let mut cursor = std::io::Cursor::new(&mut buffer);
bitmap.write(cursor).unwrap();
assert_eq!(&buffer, &0b0101_0101u8.to_le_bytes());
}

pub fn byte_size(&self) -> usize[src]

Size of bitmap in bytes.

Example

let bitmap = dyn_bitmap::DynBitmap::contained(9);
assert_eq!(bitmap.byte_size(), 2);

pub fn bits_capacity(&self) -> usize[src]

Bitmap bits capacity.

Example

let bitmap = dyn_bitmap::DynBitmap::contained(9);
assert_eq!(bitmap.bits_capacity(), 16);

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.