pub struct BitmapArch(/* private fields */);
Expand description
A bitmap of length usize.
§Examples
// Creates an empty bitmap
use fixed_bitmaps::BitmapArch;
let mut bitmap = BitmapArch::default();
// Bitmaps implement Display so you can view what the map looks like
println!("Default bitmap: {}", bitmap);
// Bitmaps also convert to their respective unsigned int versions and back again easily
// Will show 0 as the value of the bitmap
println!("Value of bitmap: {}", bitmap.to_usize());
// Let's do the same as above, but actually setting the values in the bitmap to something
bitmap |= BitmapArch::from(101);
println!("Bitmap after OR-ing with 101: {}", bitmap);
// Set the 4th index (the 5th bit) to true. Can simply unwrap the result to ignore the warning,
//as we know for certain that 4 < usize
bitmap.set(4, true).unwrap();
// Will show that 117 (101 + 2^4) is the value of the bitmap
println!("Bitmap value: {}", bitmap.to_usize());
// Or you could use the deref operator for an even easier conversion
println!("Bitmap value: {}", *bitmap);
Implementations§
Source§impl BitmapArch
impl BitmapArch
pub fn capacity() -> usize
Sourcepub fn to_usize(&self) -> usize
pub fn to_usize(&self) -> usize
Examples found in repository?
3fn main() {
4 let mut bitmap = BitmapArch::default();
5 println!("{}", bitmap);
6 // println!("Capacity: {}", BitmapArch::capacity());
7
8 bitmap.set(5, true).unwrap();
9 println!("{}", bitmap);
10 println!("Value: {}", bitmap.to_usize());
11
12 let a = BitmapArch::from(0b0001);
13 let b = BitmapArch::from(0b0010);
14 let c = BitmapArch::from(0b0100);
15 let d = BitmapArch::from(0b1000);
16
17 let set1 = a | b | c | d | d;
18 let set2 = a | b | c | d;
19
20 println!("Set 1: {}", set1);
21 println!("Set 2: {:?}", set2);
22}
Sourcepub fn new(value: bool) -> BitmapArch
pub fn new(value: bool) -> BitmapArch
Creates a new bitmap with all bits set to the given value.
§Example
use fixed_bitmaps::BitmapArch;
let a = BitmapArch::new(true);
assert_eq!(*a, usize::MAX);
let b = BitmapArch::new(false);
assert_eq!(*b, 0);
Sourcepub fn create_bit_mask(begin: usize, end: usize, value: bool) -> BitmapArch
pub fn create_bit_mask(begin: usize, end: usize, value: bool) -> BitmapArch
Create a new bitmap that has its bits set from begin
(inclusive) to end
(exclusive).
If begin is greater than the map length or end is 0, will return a bitmap with all bits set to
the opposite of value.
§Example
use fixed_bitmaps::BitmapArch;
let a = BitmapArch::create_bit_mask(3, 7, true);
assert_eq!(*a, 0b1111000);
let b = BitmapArch::create_bit_mask(3, 6, false); // Results in 1..1000111
assert_eq!(b, BitmapArch::new(true) ^ 0b111000);
Sourcepub fn from_set(index: usize) -> Option<BitmapArch>
pub fn from_set(index: usize) -> Option<BitmapArch>
Creates a new, empty BitmapArch
, and sets the desired index before returning.
use fixed_bitmaps::BitmapArch;
let a = BitmapArch::from_set(5).unwrap();
// The above is equivalent to:
let mut b = BitmapArch::from(0);
b.set(5, true);
assert_eq!(a, b);
Sourcepub fn set(&mut self, index: usize, value: bool) -> Result<(), String>
pub fn set(&mut self, index: usize, value: bool) -> Result<(), String>
Sets the desired index, to the value provided. Note that indexing starts at 0.
§Returns
Returns a Result
based on the outcome. If an Err<String>
was returned,
it was because an out-of-bounds index was attempted to be set. In that
case the bitmap’s state remains unchanged.
§Example
use fixed_bitmaps::BitmapArch;
let mut bitmap = BitmapArch::default();
assert_eq!(*bitmap, 0);
bitmap.set(4, true);
assert_eq!(*bitmap, 16);
Examples found in repository?
3fn main() {
4 let mut bitmap = BitmapArch::default();
5 println!("{}", bitmap);
6 // println!("Capacity: {}", BitmapArch::capacity());
7
8 bitmap.set(5, true).unwrap();
9 println!("{}", bitmap);
10 println!("Value: {}", bitmap.to_usize());
11
12 let a = BitmapArch::from(0b0001);
13 let b = BitmapArch::from(0b0010);
14 let c = BitmapArch::from(0b0100);
15 let d = BitmapArch::from(0b1000);
16
17 let set1 = a | b | c | d | d;
18 let set2 = a | b | c | d;
19
20 println!("Set 1: {}", set1);
21 println!("Set 2: {:?}", set2);
22}
Sourcepub fn set_range(&mut self, begin: usize, end: usize, value: bool)
pub fn set_range(&mut self, begin: usize, end: usize, value: bool)
Set bits from begin (inclusive) to end (exclusive) to the given value.
§Example
use fixed_bitmaps::BitmapArch;
let mut bitmap = BitmapArch::default();
assert_eq!(*bitmap, 0);
bitmap.set_range(2, 7, true);
assert_eq!(*bitmap, 0b1111100);
bitmap.set_range(3, 5, false);
assert_eq!(*bitmap, 0b1100100);
Sourcepub fn get(&self, index: usize) -> Result<bool, String>
pub fn get(&self, index: usize) -> Result<bool, String>
Gets the bit at the given index. Note that indexing starts at 0.
§Returns
Returns a Result
based on the outcome.
If Ok<bool>
is returned, then the contained value in ok is the state
of the given bit
If an Err<String>
was returned, it was because you tried to get
an out-of-bounds index.
§Example
use fixed_bitmaps::BitmapArch;
let bitmap = BitmapArch::from(0b1010);
assert_eq!(bitmap.get(2).unwrap(), false);
assert_eq!(bitmap.get(3).unwrap(), true);
Trait Implementations§
Source§impl Add<usize> for BitmapArch
impl Add<usize> for BitmapArch
Source§impl Add for BitmapArch
impl Add for BitmapArch
Source§impl AddAssign<usize> for BitmapArch
impl AddAssign<usize> for BitmapArch
Source§fn add_assign(&mut self, rhs: usize)
fn add_assign(&mut self, rhs: usize)
+=
operation. Read moreSource§impl AddAssign for BitmapArch
impl AddAssign for BitmapArch
Source§fn add_assign(&mut self, rhs: Self)
fn add_assign(&mut self, rhs: Self)
+=
operation. Read moreSource§impl BitAnd<usize> for BitmapArch
impl BitAnd<usize> for BitmapArch
Source§impl BitAnd for BitmapArch
impl BitAnd for BitmapArch
Source§impl BitAndAssign<usize> for BitmapArch
impl BitAndAssign<usize> for BitmapArch
Source§fn bitand_assign(&mut self, rhs: usize)
fn bitand_assign(&mut self, rhs: usize)
&=
operation. Read moreSource§impl BitAndAssign for BitmapArch
impl BitAndAssign for BitmapArch
Source§fn bitand_assign(&mut self, rhs: Self)
fn bitand_assign(&mut self, rhs: Self)
&=
operation. Read moreSource§impl BitOr<usize> for BitmapArch
impl BitOr<usize> for BitmapArch
Source§impl BitOr for BitmapArch
impl BitOr for BitmapArch
Source§impl BitOrAssign<usize> for BitmapArch
impl BitOrAssign<usize> for BitmapArch
Source§fn bitor_assign(&mut self, rhs: usize)
fn bitor_assign(&mut self, rhs: usize)
|=
operation. Read moreSource§impl BitOrAssign for BitmapArch
impl BitOrAssign for BitmapArch
Source§fn bitor_assign(&mut self, rhs: Self)
fn bitor_assign(&mut self, rhs: Self)
|=
operation. Read moreSource§impl BitXor<usize> for BitmapArch
impl BitXor<usize> for BitmapArch
Source§impl BitXor for BitmapArch
impl BitXor for BitmapArch
Source§impl BitXorAssign<usize> for BitmapArch
impl BitXorAssign<usize> for BitmapArch
Source§fn bitxor_assign(&mut self, rhs: usize)
fn bitxor_assign(&mut self, rhs: usize)
^=
operation. Read moreSource§impl BitXorAssign for BitmapArch
impl BitXorAssign for BitmapArch
Source§fn bitxor_assign(&mut self, rhs: Self)
fn bitxor_assign(&mut self, rhs: Self)
^=
operation. Read moreSource§impl BitmapSize for BitmapArch
impl BitmapSize for BitmapArch
const MAP_LENGTH: usize = 64usize
Source§impl Clone for BitmapArch
impl Clone for BitmapArch
Source§fn clone(&self) -> BitmapArch
fn clone(&self) -> BitmapArch
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreSource§impl Debug for BitmapArch
impl Debug for BitmapArch
Source§impl Default for BitmapArch
impl Default for BitmapArch
Source§fn default() -> BitmapArch
fn default() -> BitmapArch
Source§impl Deref for BitmapArch
impl Deref for BitmapArch
Source§impl<'de> Deserialize<'de> for BitmapArch
impl<'de> Deserialize<'de> for BitmapArch
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl Display for BitmapArch
impl Display for BitmapArch
Source§impl Div<usize> for BitmapArch
impl Div<usize> for BitmapArch
Source§impl Div for BitmapArch
impl Div for BitmapArch
Source§impl DivAssign<usize> for BitmapArch
impl DivAssign<usize> for BitmapArch
Source§fn div_assign(&mut self, rhs: usize)
fn div_assign(&mut self, rhs: usize)
/=
operation. Read moreSource§impl DivAssign for BitmapArch
impl DivAssign for BitmapArch
Source§fn div_assign(&mut self, rhs: Self)
fn div_assign(&mut self, rhs: Self)
/=
operation. Read moreSource§impl From<usize> for BitmapArch
impl From<usize> for BitmapArch
Source§impl Hash for BitmapArch
impl Hash for BitmapArch
Source§impl Mul<usize> for BitmapArch
impl Mul<usize> for BitmapArch
Source§impl Mul for BitmapArch
impl Mul for BitmapArch
Source§impl MulAssign<usize> for BitmapArch
impl MulAssign<usize> for BitmapArch
Source§fn mul_assign(&mut self, rhs: usize)
fn mul_assign(&mut self, rhs: usize)
*=
operation. Read moreSource§impl MulAssign for BitmapArch
impl MulAssign for BitmapArch
Source§fn mul_assign(&mut self, rhs: Self)
fn mul_assign(&mut self, rhs: Self)
*=
operation. Read moreSource§impl Not for BitmapArch
impl Not for BitmapArch
Source§impl Ord for BitmapArch
impl Ord for BitmapArch
Source§fn cmp(&self, other: &BitmapArch) -> Ordering
fn cmp(&self, other: &BitmapArch) -> Ordering
1.21.0 · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Source§impl PartialEq for BitmapArch
impl PartialEq for BitmapArch
Source§impl PartialOrd for BitmapArch
impl PartialOrd for BitmapArch
Source§impl Serialize for BitmapArch
impl Serialize for BitmapArch
Source§impl Shl<usize> for BitmapArch
impl Shl<usize> for BitmapArch
Source§impl ShlAssign<usize> for BitmapArch
impl ShlAssign<usize> for BitmapArch
Source§fn shl_assign(&mut self, rhs: usize)
fn shl_assign(&mut self, rhs: usize)
<<=
operation. Read moreSource§impl Shr<usize> for BitmapArch
impl Shr<usize> for BitmapArch
Source§impl ShrAssign<usize> for BitmapArch
impl ShrAssign<usize> for BitmapArch
Source§fn shr_assign(&mut self, rhs: usize)
fn shr_assign(&mut self, rhs: usize)
>>=
operation. Read moreSource§impl Sub<usize> for BitmapArch
impl Sub<usize> for BitmapArch
Source§impl Sub for BitmapArch
impl Sub for BitmapArch
Source§impl SubAssign<usize> for BitmapArch
impl SubAssign<usize> for BitmapArch
Source§fn sub_assign(&mut self, rhs: usize)
fn sub_assign(&mut self, rhs: usize)
-=
operation. Read moreSource§impl SubAssign for BitmapArch
impl SubAssign for BitmapArch
Source§fn sub_assign(&mut self, rhs: Self)
fn sub_assign(&mut self, rhs: Self)
-=
operation. Read more