Struct dyn_bitmap::DynBitmap[][src]

pub struct DynBitmap { /* fields omitted */ }

Dynamicaly sized bitmap.

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

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

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

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, true).unwrap();
assert!(bitmap.get(0).unwrap());
assert!(!bitmap.get(1).unwrap());
Run

pub fn set(&mut self, bit_index: usize, value: bool) -> 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, true).unwrap();
assert!(bitmap.get(0).unwrap());
Run

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, true).unwrap();
bitmap.set(2, true).unwrap();
bitmap.set(4, true).unwrap();
bitmap.set(6, true).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());
Run

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

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

Bitmap bits capacity.

Example

let bitmap = dyn_bitmap::DynBitmap::contained(9);
assert_eq!(bitmap.arity(), 9);
Run

pub fn iter(&self) -> impl Iterator<Item = bool> + '_[src]

Iterate over the bitmap.

Example

use dyn_bitmap::DynBitmap;

let bitmap: DynBitmap = std::iter::repeat(true).take(128).collect();
let all: bool = bitmap.iter().all(|b| b);
Run

Trait Implementations

impl Debug for DynBitmap[src]

impl FromIterator<bool> for DynBitmap[src]

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.