Skip to main content

RefBitmap

Struct RefBitmap 

Source
pub struct RefBitmap<const N: usize>;
Expand description

The ZST RefBitmap reference with N bits.

To create a ref-bitmap, use from_raw_ptr and from_raw_mut_ptr.

Implementations§

Source§

impl<'a, const N: usize> RefBitmap<N>

Source

pub unsafe fn from_raw_ptr(ptr: *const usize) -> &'a Self

Creates a RefBitmap from raw constant pointer.

§Safety

You must ensure ptr points to a valid buffer which has at least N bits!

Source

pub unsafe fn from_raw_mut_ptr(ptr: *mut usize) -> &'a mut Self

Creates a RefBitmap from raw mutable pointer.

§Safety

You must ensure ptr points to a valid buffer which has at least N bits!

Source§

impl<const N: usize> RefBitmap<N>

Source

pub fn test(&self, position: usize) -> Result<bool, OutOfBitmapError>

Tests if a position in the bitmap is set.
Returns Ok(bool) if position<N. The boolspecifies whether the bit is set or not. \ ReturnsErr(OutOfBitmapError) if position>=N.

§Example
use static_collections::bitmap::*;
let bmp_raw:[u64;4]=[0,1,2,4];
let bmp:&RefBitmap<256>=unsafe{RefBitmap::from_raw_ptr(bmp_raw.as_ptr().cast())};
assert_eq!(bmp.test(36),Ok(false));
assert_eq!(bmp.test(64),Ok(true));
assert_eq!(bmp.test(194),Ok(true));
assert_eq!(bmp.test(288),Err(OutOfBitmapError::new(288,256)))
Source

pub fn set(&mut self, position: usize) -> Result<bool, OutOfBitmapError>

Tests and also assigns true to a position in the bitmap and returns the previous value.
Returns Ok(bool) if position<N. The boolspecifies whether the bit is set or not. \ ReturnsErr(OutOfBitmapError) if position>=N.

§Example
use static_collections::bitmap::RefBitmap;
let mut bmp_raw:[u64;4]=[0;4];
let mut bmp:&mut RefBitmap<256>=unsafe{RefBitmap::from_raw_mut_ptr(bmp_raw.as_mut_ptr().cast())};
assert_eq!(bmp.set(36),Ok(false));
assert_eq!(bmp.test(36),Ok(true));
Source

pub fn reset(&mut self, position: usize) -> Result<bool, OutOfBitmapError>

Tests and also assigns false to a position in the bitmap and returns the previous value.
Returns Ok(bool) if position<N. The boolspecifies whether the bit is set or not. \ ReturnsErr(OutOfBitmapError) if position>=N.

§Example
use static_collections::bitmap::RefBitmap;
let mut bmp_raw:[u64;4]=[u64::MAX;4];
let mut bmp:&mut RefBitmap<256>=unsafe{RefBitmap::from_raw_mut_ptr(bmp_raw.as_mut_ptr().cast())};
assert_eq!(bmp.reset(236),Ok(true));
assert_eq!(bmp.test(236),Ok(false));
Source

pub fn complement(&mut self, position: usize) -> Result<bool, OutOfBitmapError>

Tests and also complements the bit in the position in the bitmap and returns the previous value.
Returns Ok(bool) if position<N. The boolspecifies whether the bit is set or not. \ ReturnsErr(OutOfBitmapError) if position>=N.

§Example
use static_collections::bitmap::RefBitmap;
let mut bmp_raw:[u64;4]=[0;4];
let mut bmp:&mut RefBitmap<256>=unsafe{RefBitmap::from_raw_mut_ptr(bmp_raw.as_mut_ptr().cast())};
assert_eq!(bmp.complement(123),Ok(false));
assert_eq!(bmp.complement(123),Ok(true));
Source

pub fn assign( &mut self, position: usize, value: bool, ) -> Result<bool, OutOfBitmapError>

Tests and also assigns value to the bit in the position in the bitmap and returns the previous value.
Returns Ok(bool) if position<N. The boolspecifies whether the bit is set or not. \ ReturnsErr(OutOfBitmapError) if position>=N.

§Example
use static_collections::bitmap::RefBitmap;
let mut bmp_raw:[u64;4]=[0;4];
let mut bmp:&mut RefBitmap<256>=unsafe{RefBitmap::from_raw_mut_ptr(bmp_raw.as_mut_ptr().cast())};
assert_eq!(bmp.assign(123,true),Ok(false));
assert_eq!(bmp.assign(123,true),Ok(true));
assert_eq!(bmp.assign(123,false),Ok(true));
Source

pub fn search_cleared_forward(&self) -> Option<usize>

Search for a cleared bit in the bitmap in forward direction.
Returns Some(usize) if there is a cleared bit.
Returns None if all bits in bitmap are set.

§Example
use static_collections::bitmap::RefBitmap;
let bmp_raw:[u64;4]=[u64::MAX,0x7,0,0];
let bmp:&RefBitmap<256>=unsafe{RefBitmap::from_raw_ptr(bmp_raw.as_ptr().cast())};
assert_eq!(bmp.search_cleared_forward(),Some(67));
Source

pub fn search_set_forward(&self) -> Option<usize>

Search for a set bit in the bitmap in forward direction.
Returns Some(usize) if there is a set bit.
Returns None if all bits in bitmap are cleared.

§Example
use static_collections::bitmap::RefBitmap;
let bmp_raw:[u64;4]=[0,0,1,0];
let bmp:&RefBitmap<256>=unsafe{RefBitmap::from_raw_ptr(bmp_raw.as_ptr().cast())};
assert_eq!(bmp.search_set_forward(),Some(128));
Source

pub fn search_cleared_backward(&self) -> Option<usize>

Search for a cleared bit in the bitmap in backward direction.
Returns Some(usize) if there is a cleared bit.
Returns None if all bits in bitmap are set.

§Example
use static_collections::bitmap::RefBitmap;
let bmp_raw:[u64;4]=[u64::MAX,0x7,0,u64::MAX];
let bmp:&RefBitmap<256>=unsafe{RefBitmap::from_raw_ptr(bmp_raw.as_ptr().cast())};
assert_eq!(bmp.search_cleared_backward(),Some(191));
Source

pub fn search_set_backward(&self) -> Option<usize>

Search for a set bit in the bitmap in backward direction.
Returns Some(usize) if there is a set bit.
Returns None if all bits in bitmap are cleared.

§Example
use static_collections::bitmap::RefBitmap;
let bmp_raw:[u64;4]=[0,0,1,2];
let bmp:&RefBitmap<256>=unsafe{RefBitmap::from_raw_ptr(bmp_raw.as_ptr().cast())};
assert_eq!(bmp.search_set_backward(),Some(193));

Auto Trait Implementations§

§

impl<const N: usize> Freeze for RefBitmap<N>

§

impl<const N: usize> RefUnwindSafe for RefBitmap<N>

§

impl<const N: usize> Send for RefBitmap<N>

§

impl<const N: usize> Sync for RefBitmap<N>

§

impl<const N: usize> Unpin for RefBitmap<N>

§

impl<const N: usize> UnsafeUnpin for RefBitmap<N>

§

impl<const N: usize> UnwindSafe for RefBitmap<N>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.