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>
impl<'a, const N: usize> RefBitmap<N>
Sourcepub unsafe fn from_raw_ptr(ptr: *const usize) -> &'a Self
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!
Sourcepub unsafe fn from_raw_mut_ptr(ptr: *mut usize) -> &'a mut Self
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>
impl<const N: usize> RefBitmap<N>
Sourcepub fn test(&self, position: usize) -> Result<bool, OutOfBitmapError>
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)))Sourcepub fn set(&mut self, position: usize) -> Result<bool, OutOfBitmapError>
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));Sourcepub fn reset(&mut self, position: usize) -> Result<bool, OutOfBitmapError>
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));Sourcepub fn complement(&mut self, position: usize) -> Result<bool, OutOfBitmapError>
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));Sourcepub fn assign(
&mut self,
position: usize,
value: bool,
) -> Result<bool, OutOfBitmapError>
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));Sourcepub fn search_cleared_forward(&self) -> Option<usize>
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));Sourcepub fn search_set_forward(&self) -> Option<usize>
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));Sourcepub fn search_cleared_backward(&self) -> Option<usize>
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));Sourcepub fn search_set_backward(&self) -> Option<usize>
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));