pub struct Bitmap<const BYTES: usize> { /* private fields */ }
Expand description
A size-fixed bitmap with croase-granularity (byte) and conventional interfaces.
Generics
BYTES
: ausize
, specifying the byte length of the bitmap.
Note: The actual number of flags (bits) will be BYTES * 8
.
Fields
bits
:Option<Box>
. The box holds an array ofu8
with fixed lengthBYTES
.
It is allowed to have BYTES == 0
. In this case, bits = None
.
Examples
Create a new bitmap using methods
use cbitmap::bitmap::*;
// new() will create a bitmap, init the flags to 0:
let map = Bitmap::<1>::new();
// Or use Default::default():
let map: Bitmap<1> = Default::default();
// You can init a map with a [u8; BYTES]:
let map: Bitmap<1> = [0b_10_u8; 1].into();
let map = Bitmap::<1>::from([0b_100_u8; 1]);
// You can also init a map with an unsized integer. The exact
// type of the integer can be omitted, but the `BYTES` must be
// specified:
let map: Bitmap<2> = 0b_10000000_00000001.into();
Create a new bitmap using macros (recommend)
use cbitmap::bitmap::*;
// Bitmap<0>
let map = newmap!();
// newmap!(;bits) = Bitmap<{(bits + 7) / 8}>
let map = newmap!(;35);
// newmap!(mask:literal | mask:literal | ...; bits)
let map = newmap!(1u8 | 0b100000u128; 48);
// newmap!(var | var | ...; bits)
let a = 1u64 << 34;
let b = 1u128 << 47;
let map = newmap!(a | b; 48);
// he_lang!(idx | idx | ...; bits)
let map = he_lang!(1 | 2; 8);
Use immutable methods to inspect bits and bitmap infos
use cbitmap::bitmap::*;
let map: Bitmap<1> = newmap!(0b_10000001; 8);
// bit_len() can get the length of the bitmap in bits,
// while byte_len() get it in bytes:
assert_eq!(map.bit_len(), 8);
assert_eq!(map.byte_len(), 1);
// get_bool() and get_01() can get the value of one bit:
assert_eq!(map.get_bool(0), true);
assert_eq!(map.get_01(7), 1);
// test() is a wrapper of get_bool():
assert_eq!(map.test(2), false);
// range_to_string() can format a range of bits:
let map: Bitmap<2> = newmap!(0b_01_10000000; 16);
assert_eq!(&map.range_to_string(4, 10).unwrap(), "01 1000");
Use mutable methods to manipulate bits
use cbitmap::bitmap::*;
let mut map = newmap!(;8);
// set(), reset() and flip() can modify one bit:
assert_eq!(map.test(1), false);
map.set(1);
assert_eq!(map.test(1), true);
map.reset(1);
assert_eq!(map.test(1), false);
map.flip(1);
assert_eq!(map.test(1), true);
// set_all(), reset_all() and flip_all() can modify the
// whole map:
map.set_all();
assert_eq!(&map.range_to_string(0, 8).unwrap(), "11111111");
// It is also possible to call these methods in chain:
map.reset_all().flip(1);
assert_eq!(map.test(1), true);
Use wrappers to reference single bits
use cbitmap::bitmap::*;
let mut map = newmap!(;8);
// at() can give a immutable ref of a bit, with a wrapper:
let bit0 = map.at(0);
let bit1 = map.at(1);
// Panic! Since map has already referenced by bit0 and bit1
// map.set(1);
// Use deref to peek the bit:
assert_eq!(*bit0, false);
{
let mut bitmut = map.at_mut(1);
bitmut.set();
}
assert_eq!(*map.at(1), true);
Use bitwise operators
use cbitmap::bitmap::*;
let mut map = newmap!(;8);
map |= 1u8 << 4;
assert_eq!(map.test(4), true);
map |= 0b_11000000u8;
// To use &, map shoule be in ref and be on the left:
assert_eq!(&map & 0b_11010000_u8, 0b11010000);
map &= 1u8 << 7;
assert_eq!(&map & !0u8, 1u8 << 7);
Implementations§
source§impl<const BYTES: usize> Bitmap<BYTES>
impl<const BYTES: usize> Bitmap<BYTES>
sourcepub fn range_to_string(&self, start: usize, end: usize) -> Option<String>
pub fn range_to_string(&self, start: usize, end: usize) -> Option<String>
Format a range of bits into a Option<String>
.
An array of '0'
/'1'
will show in the String. The bits are separated
by ' '
at the edge of 2 bytes.
Return
None
if the range is invalid (out of the bitmap, or length is less
than 0), [Some(String)
] otherwise.
Examples
use cbitmap::bitmap::*;
let map: Bitmap<2> = 0b_011_11001100.into();
let string = map.range_to_string(2, 11).unwrap();
assert_eq!(&string, "011 110011");
assert!(map.range_to_string(0, 100).is_none());
assert!(map.range_to_string(100, 101).is_none());
assert!(map.range_to_string(2, 1).is_none());
source§impl<const BYTES: usize> Bitmap<BYTES>
impl<const BYTES: usize> Bitmap<BYTES>
sourcepub fn at<'map>(&'map self, index: usize) -> BitRef<'map, BYTES>
pub fn at<'map>(&'map self, index: usize) -> BitRef<'map, BYTES>
Get the immutable reference of the indexed bit in the bitmap.
The bit is wrapped in BitRef
.
One can deref this reference to get the bool value of the bit.
Examples
Simple examples:
use cbitmap::bitmap::*;
let map = newmap!(0b_00001000; 8);
let bit = map.at(3);
assert_eq!(*bit, true);
Panics
Panic if index
is out of range.
sourcepub fn at_mut<'map>(&'map mut self, index: usize) -> BitRefMut<'map, BYTES>
pub fn at_mut<'map>(&'map mut self, index: usize) -> BitRefMut<'map, BYTES>
Get the mutable reference of the indexed bit in the bitmap.
The bit is wrapped in BitRefMut
.
One can deref this reference to get the bool value of the bit, or use the methods to modify the referenced bit.
Examples
Simple examples:
use cbitmap::bitmap::*;
let mut map = newmap!(0b_00001000; 8);
{
let mut bitmut = map.at_mut(3);
assert_eq!(*bitmut, true);
bitmut.reset();
assert_eq!(*bitmut, false);
}
Panics
Panic if index
is out of range.
source§impl<const BYTES: usize> Bitmap<BYTES>
impl<const BYTES: usize> Bitmap<BYTES>
sourcepub fn new() -> Self
pub fn new() -> Self
Create a Bitmap<BYTES>
whose flags are all set to 0.
Examples
use cbitmap::bitmap::Bitmap;
let map = Bitmap::<2>::new();
assert_eq!(&map.range_to_string(0, 16).unwrap(),
"00000000 00000000");
Trait Implementations§
source§impl<const BYTES: usize, const N: usize> BitAnd<[u8; N]> for &Bitmap<BYTES>
impl<const BYTES: usize, const N: usize> BitAnd<[u8; N]> for &Bitmap<BYTES>
source§fn bitand(self, rhs: [u8; N]) -> Self::Output
fn bitand(self, rhs: [u8; N]) -> Self::Output
AND the given bitmap (in ref
) to an array of u8
values.
Generics
BYTES
: the byte length of the bitmap.N
: the length of theu8
array.
Examples
A &
can AND the bitmap with a fixed-length u8
array, the results
will be store in a new array:
use cbitmap::bitmap::*;
let mut map = Bitmap::<2>::from([255u8; 2]);
let arr = [1u8; 2];
// NOTE: the bitmap shoule be in ref, and should be in left.
assert_eq!(&map & arr, [1u8; 2]);
There are also aliases for integer types:
use cbitmap::bitmap::*;
let mut map = Bitmap::<1>::from(255u8);
let arr = 1u8;
assert_eq!(&map & arr, 1u8);
See
About the asymmetry between BYTES
and N
, see
bitmap::Bitmap<BYTES>::bitand_assign
.
In general, if N > BYTES
, the
returned array will have (N - BYTES) * 8
leading zero flags.
source§impl<const BYTES: usize, const N: usize> BitAndAssign<[u8; N]> for Bitmap<BYTES>
impl<const BYTES: usize, const N: usize> BitAndAssign<[u8; N]> for Bitmap<BYTES>
source§fn bitand_assign(&mut self, rhs: [u8; N])
fn bitand_assign(&mut self, rhs: [u8; N])
AND the given bitmap with an array of u8
values.
Generics
BYTES
: the byte length of the bitmap.N
: the length of theu8
array.
Examples
A simple example:
use cbitmap::bitmap::*;
let mut map = Bitmap::<1>::from([0b_11111111_u8; 1]);
map &= [0b_11111110_u8; 1];
assert_eq!(map.test(0), false);
There are also aliases for integer types:
use cbitmap::bitmap::*;
let mut map = Bitmap::<1>::from(255u8);
map &= 0b_11111110u8;
assert_eq!(map.test(0), false);
It is also noteworthy that, if the bitmap is longer than the array, then the rest of bitmap will be set to all-zero.
use cbitmap::bitmap::*;
let mut map: Bitmap::<2> = [255u8; 2].into();
map &= 255u8;
assert_eq!(&map.range_to_string(8, 16).unwrap(), "00000000");
source§impl<const BYTES: usize> BitAndAssign<char> for Bitmap<BYTES>
impl<const BYTES: usize> BitAndAssign<char> for Bitmap<BYTES>
source§fn bitand_assign(&mut self, rhs: char)
fn bitand_assign(&mut self, rhs: char)
&=
operation. Read moresource§impl<const BYTES: usize> BitAndAssign<i128> for Bitmap<BYTES>
impl<const BYTES: usize> BitAndAssign<i128> for Bitmap<BYTES>
source§fn bitand_assign(&mut self, rhs: i128)
fn bitand_assign(&mut self, rhs: i128)
&=
operation. Read moresource§impl<const BYTES: usize> BitAndAssign<i16> for Bitmap<BYTES>
impl<const BYTES: usize> BitAndAssign<i16> for Bitmap<BYTES>
source§fn bitand_assign(&mut self, rhs: i16)
fn bitand_assign(&mut self, rhs: i16)
&=
operation. Read moresource§impl<const BYTES: usize> BitAndAssign<i32> for Bitmap<BYTES>
impl<const BYTES: usize> BitAndAssign<i32> for Bitmap<BYTES>
source§fn bitand_assign(&mut self, rhs: i32)
fn bitand_assign(&mut self, rhs: i32)
&=
operation. Read moresource§impl<const BYTES: usize> BitAndAssign<i64> for Bitmap<BYTES>
impl<const BYTES: usize> BitAndAssign<i64> for Bitmap<BYTES>
source§fn bitand_assign(&mut self, rhs: i64)
fn bitand_assign(&mut self, rhs: i64)
&=
operation. Read moresource§impl<const BYTES: usize> BitAndAssign<i8> for Bitmap<BYTES>
impl<const BYTES: usize> BitAndAssign<i8> for Bitmap<BYTES>
source§fn bitand_assign(&mut self, rhs: i8)
fn bitand_assign(&mut self, rhs: i8)
&=
operation. Read moresource§impl<const BYTES: usize> BitAndAssign<isize> for Bitmap<BYTES>
impl<const BYTES: usize> BitAndAssign<isize> for Bitmap<BYTES>
source§fn bitand_assign(&mut self, rhs: isize)
fn bitand_assign(&mut self, rhs: isize)
&=
operation. Read moresource§impl<const BYTES: usize> BitAndAssign<u128> for Bitmap<BYTES>
impl<const BYTES: usize> BitAndAssign<u128> for Bitmap<BYTES>
source§fn bitand_assign(&mut self, rhs: u128)
fn bitand_assign(&mut self, rhs: u128)
&=
operation. Read moresource§impl<const BYTES: usize> BitAndAssign<u16> for Bitmap<BYTES>
impl<const BYTES: usize> BitAndAssign<u16> for Bitmap<BYTES>
source§fn bitand_assign(&mut self, rhs: u16)
fn bitand_assign(&mut self, rhs: u16)
&=
operation. Read moresource§impl<const BYTES: usize> BitAndAssign<u32> for Bitmap<BYTES>
impl<const BYTES: usize> BitAndAssign<u32> for Bitmap<BYTES>
source§fn bitand_assign(&mut self, rhs: u32)
fn bitand_assign(&mut self, rhs: u32)
&=
operation. Read moresource§impl<const BYTES: usize> BitAndAssign<u64> for Bitmap<BYTES>
impl<const BYTES: usize> BitAndAssign<u64> for Bitmap<BYTES>
source§fn bitand_assign(&mut self, rhs: u64)
fn bitand_assign(&mut self, rhs: u64)
&=
operation. Read moresource§impl<const BYTES: usize> BitAndAssign<u8> for Bitmap<BYTES>
impl<const BYTES: usize> BitAndAssign<u8> for Bitmap<BYTES>
source§fn bitand_assign(&mut self, rhs: u8)
fn bitand_assign(&mut self, rhs: u8)
&=
operation. Read moresource§impl<const BYTES: usize> BitAndAssign<usize> for Bitmap<BYTES>
impl<const BYTES: usize> BitAndAssign<usize> for Bitmap<BYTES>
source§fn bitand_assign(&mut self, rhs: usize)
fn bitand_assign(&mut self, rhs: usize)
&=
operation. Read moresource§impl<const BYTES: usize, const N: usize> BitOrAssign<[u8; N]> for Bitmap<BYTES>
impl<const BYTES: usize, const N: usize> BitOrAssign<[u8; N]> for Bitmap<BYTES>
source§fn bitor_assign(&mut self, rhs: [u8; N])
fn bitor_assign(&mut self, rhs: [u8; N])
OR the given bitmap with an array of u8
values.
Generics
BYTES
: the byte length of the bitmap.N
: the length of theu8
array.
Examples
A simple example:
use cbitmap::bitmap::*;
let mut map = Bitmap::<1>::from([0u8; 1]);
map |= [0b_00000001_u8; 1];
assert_eq!(map.test(0), true);
There are also aliases for integer types:
use cbitmap::bitmap::*;
let mut map = Bitmap::<1>::from(0u8);
map |= 0b_00000001_u8;
assert_eq!(map.test(0), true);
source§impl<const BYTES: usize> BitOrAssign<char> for Bitmap<BYTES>
impl<const BYTES: usize> BitOrAssign<char> for Bitmap<BYTES>
source§fn bitor_assign(&mut self, rhs: char)
fn bitor_assign(&mut self, rhs: char)
|=
operation. Read moresource§impl<const BYTES: usize> BitOrAssign<i128> for Bitmap<BYTES>
impl<const BYTES: usize> BitOrAssign<i128> for Bitmap<BYTES>
source§fn bitor_assign(&mut self, rhs: i128)
fn bitor_assign(&mut self, rhs: i128)
|=
operation. Read moresource§impl<const BYTES: usize> BitOrAssign<i16> for Bitmap<BYTES>
impl<const BYTES: usize> BitOrAssign<i16> for Bitmap<BYTES>
source§fn bitor_assign(&mut self, rhs: i16)
fn bitor_assign(&mut self, rhs: i16)
|=
operation. Read moresource§impl<const BYTES: usize> BitOrAssign<i32> for Bitmap<BYTES>
impl<const BYTES: usize> BitOrAssign<i32> for Bitmap<BYTES>
source§fn bitor_assign(&mut self, rhs: i32)
fn bitor_assign(&mut self, rhs: i32)
|=
operation. Read moresource§impl<const BYTES: usize> BitOrAssign<i64> for Bitmap<BYTES>
impl<const BYTES: usize> BitOrAssign<i64> for Bitmap<BYTES>
source§fn bitor_assign(&mut self, rhs: i64)
fn bitor_assign(&mut self, rhs: i64)
|=
operation. Read moresource§impl<const BYTES: usize> BitOrAssign<i8> for Bitmap<BYTES>
impl<const BYTES: usize> BitOrAssign<i8> for Bitmap<BYTES>
source§fn bitor_assign(&mut self, rhs: i8)
fn bitor_assign(&mut self, rhs: i8)
|=
operation. Read moresource§impl<const BYTES: usize> BitOrAssign<isize> for Bitmap<BYTES>
impl<const BYTES: usize> BitOrAssign<isize> for Bitmap<BYTES>
source§fn bitor_assign(&mut self, rhs: isize)
fn bitor_assign(&mut self, rhs: isize)
|=
operation. Read moresource§impl<const BYTES: usize> BitOrAssign<u128> for Bitmap<BYTES>
impl<const BYTES: usize> BitOrAssign<u128> for Bitmap<BYTES>
source§fn bitor_assign(&mut self, rhs: u128)
fn bitor_assign(&mut self, rhs: u128)
|=
operation. Read moresource§impl<const BYTES: usize> BitOrAssign<u16> for Bitmap<BYTES>
impl<const BYTES: usize> BitOrAssign<u16> for Bitmap<BYTES>
source§fn bitor_assign(&mut self, rhs: u16)
fn bitor_assign(&mut self, rhs: u16)
|=
operation. Read moresource§impl<const BYTES: usize> BitOrAssign<u32> for Bitmap<BYTES>
impl<const BYTES: usize> BitOrAssign<u32> for Bitmap<BYTES>
source§fn bitor_assign(&mut self, rhs: u32)
fn bitor_assign(&mut self, rhs: u32)
|=
operation. Read moresource§impl<const BYTES: usize> BitOrAssign<u64> for Bitmap<BYTES>
impl<const BYTES: usize> BitOrAssign<u64> for Bitmap<BYTES>
source§fn bitor_assign(&mut self, rhs: u64)
fn bitor_assign(&mut self, rhs: u64)
|=
operation. Read moresource§impl<const BYTES: usize> BitOrAssign<u8> for Bitmap<BYTES>
impl<const BYTES: usize> BitOrAssign<u8> for Bitmap<BYTES>
source§fn bitor_assign(&mut self, rhs: u8)
fn bitor_assign(&mut self, rhs: u8)
|=
operation. Read moresource§impl<const BYTES: usize> BitOrAssign<usize> for Bitmap<BYTES>
impl<const BYTES: usize> BitOrAssign<usize> for Bitmap<BYTES>
source§fn bitor_assign(&mut self, rhs: usize)
fn bitor_assign(&mut self, rhs: usize)
|=
operation. Read moresource§impl<const BYTES: usize> BitsManage for Bitmap<BYTES>
impl<const BYTES: usize> BitsManage for Bitmap<BYTES>
source§fn find_first_one(&self) -> Option<usize>
fn find_first_one(&self) -> Option<usize>
Get the minimal index of a ‘1’ in the bitmap.
Return
Option<usize>
. None
if there is no ‘1’,
otherwise [Some(index)
].
Examples
use cbitmap::bitmap::*;
let mut map = newmap!(;16);
assert_eq!(map.find_first_one(), None);
map.set(10);
assert_eq!(map.find_first_one(), Some(10));
map.set(7);
assert_eq!(map.find_first_one(), Some(7));
map.set(0);
assert_eq!(map.find_first_one(), Some(0));
source§fn find_first_zero(&self) -> Option<usize>
fn find_first_zero(&self) -> Option<usize>
Get the minimal index of a ‘0’ in the bitmap.
Return
Option<usize>
. None
if there is no ‘0’,
otherwise [Some(index)
].
Examples
use cbitmap::bitmap::*;
let mut map = newmap!(;16);
map.set_all();
assert_eq!(map.find_first_zero(), None);
map.reset(10);
assert_eq!(map.find_first_zero(), Some(10));
map.reset(7);
assert_eq!(map.find_first_zero(), Some(7));
map.reset(0);
assert_eq!(map.find_first_zero(), Some(0));
source§fn count(&self) -> usize
fn count(&self) -> usize
Count how many ’1’s are in the bitmap.
Examples
use cbitmap::bitmap::*;
let mut map = newmap!(;64);
assert_eq!(map.count(), 0);
let some = [
0b11, 0b110, 0b101, 0b1010,
0b1111, 0b1, 0b10000, 0b01];
map.fill_prefix(some);
assert_eq!(map.count(), 15);
map.flip_all();
assert_eq!(map.count(), 49);
map.set_all();
assert_eq!(map.count(), 64);
source§fn set(&mut self, index: usize) -> &mut Self
fn set(&mut self, index: usize) -> &mut Self
Set a bit to 1 by specifying the index.
Return
&mut self
, allowing a call chain.
Examples
Examples including call chain:
use cbitmap::bitmap::*;
let mut map = newmap!(;8);
map.set(0);
assert_eq!(map.test(0), true);
map.set(1).set(2).set(3);
assert_eq!(&map.range_to_string(0, 8).unwrap(), "00001111");
source§fn reset(&mut self, index: usize) -> &mut Self
fn reset(&mut self, index: usize) -> &mut Self
Set a bit to 0 by specifying the index.
Return
&mut self
, allowing a call chain.
Examples
Examples including call chain:
use cbitmap::bitmap::*;
let mut map = newmap!(0b_11111111; 8);
map.reset(0);
assert_eq!(map.test(0), false);
map.reset(1).reset(2).reset(3);
assert_eq!(&map.range_to_string(0, 8).unwrap(), "11110000");
source§fn flip_all(&mut self) -> &mut Self
fn flip_all(&mut self) -> &mut Self
Flip the whole map.
Return
&mut self
, allowing a call chain.
Examples
Examples including call chain:
use cbitmap::bitmap::*;
let mut map = newmap!(0b_10101010; 8);
map.flip_all();
assert_eq!(&map.range_to_string(0, 8).unwrap(), "01010101");
map.flip_all().set(0);
assert_eq!(&map.range_to_string(0, 8).unwrap(), "10101011");
source§impl<const BYTES: usize> Display for Bitmap<BYTES>
impl<const BYTES: usize> Display for Bitmap<BYTES>
source§fn fmt(&self, f: &mut Formatter<'_>) -> Result
fn fmt(&self, f: &mut Formatter<'_>) -> Result
Formats a bitmap. Only shows the last 2 bytes if the bitmap is longer.
The bytes will be separated by space ' '
.
The bits will be arranged from right to left. If the bitmap is longer than
2 bytes, a "..."
will show on the left.
On the very left, a bracket tells the bit length of the map (in a form
like "[N bits]"
). A space ' '
will be between the bit contents and this
bracket.
Examples
use cbitmap::bitmap::*;
let mut map: Bitmap<3> = 0.into();
map.set(0);
map.set(8);
let str = &format!("{map}");
assert_eq!(str, "[24 bits] ...00000001 00000001");
source§impl<const BYTES: usize, const N: usize> FillPrefix<[u8; N]> for Bitmap<BYTES>
impl<const BYTES: usize, const N: usize> FillPrefix<[u8; N]> for Bitmap<BYTES>
source§fn fill_prefix(&mut self, value: [u8; N]) -> &mut Self
fn fill_prefix(&mut self, value: [u8; N]) -> &mut Self
Fill the first N bytes (N*8 bits) of a bitmap with given byte array.
Return
&mut self
, allowing a call chain.
Examples
use cbitmap::bitmap::*;
let mut map = newmap!(;16);
map.fill_prefix([0b_1010u8; 1]);
assert_eq!(map.test(1), true);
assert_eq!(map.test(3), true);
Here are some aliases:
use cbitmap::bitmap::*;
let mut map = newmap!(;128);
// aliases
map.fill_prefix(1u8 << 7);
assert_eq!(map.test(7), true);
map.fill_prefix(1u16 << 15);
assert_eq!(map.test(15), true);
// ...
map.fill_prefix(1i128 << 100);
assert_eq!(map.test(100), true);
source§impl<const BYTES: usize> FillPrefix<char> for Bitmap<BYTES>
impl<const BYTES: usize> FillPrefix<char> for Bitmap<BYTES>
fn fill_prefix(&mut self, value: char) -> &mut Self
source§impl<const BYTES: usize> FillPrefix<i128> for Bitmap<BYTES>
impl<const BYTES: usize> FillPrefix<i128> for Bitmap<BYTES>
fn fill_prefix(&mut self, value: i128) -> &mut Self
source§impl<const BYTES: usize> FillPrefix<i16> for Bitmap<BYTES>
impl<const BYTES: usize> FillPrefix<i16> for Bitmap<BYTES>
fn fill_prefix(&mut self, value: i16) -> &mut Self
source§impl<const BYTES: usize> FillPrefix<i32> for Bitmap<BYTES>
impl<const BYTES: usize> FillPrefix<i32> for Bitmap<BYTES>
fn fill_prefix(&mut self, value: i32) -> &mut Self
source§impl<const BYTES: usize> FillPrefix<i64> for Bitmap<BYTES>
impl<const BYTES: usize> FillPrefix<i64> for Bitmap<BYTES>
fn fill_prefix(&mut self, value: i64) -> &mut Self
source§impl<const BYTES: usize> FillPrefix<i8> for Bitmap<BYTES>
impl<const BYTES: usize> FillPrefix<i8> for Bitmap<BYTES>
fn fill_prefix(&mut self, value: i8) -> &mut Self
source§impl<const BYTES: usize> FillPrefix<isize> for Bitmap<BYTES>
impl<const BYTES: usize> FillPrefix<isize> for Bitmap<BYTES>
fn fill_prefix(&mut self, value: isize) -> &mut Self
source§impl<const BYTES: usize> FillPrefix<u128> for Bitmap<BYTES>
impl<const BYTES: usize> FillPrefix<u128> for Bitmap<BYTES>
fn fill_prefix(&mut self, value: u128) -> &mut Self
source§impl<const BYTES: usize> FillPrefix<u16> for Bitmap<BYTES>
impl<const BYTES: usize> FillPrefix<u16> for Bitmap<BYTES>
fn fill_prefix(&mut self, value: u16) -> &mut Self
source§impl<const BYTES: usize> FillPrefix<u32> for Bitmap<BYTES>
impl<const BYTES: usize> FillPrefix<u32> for Bitmap<BYTES>
fn fill_prefix(&mut self, value: u32) -> &mut Self
source§impl<const BYTES: usize> FillPrefix<u64> for Bitmap<BYTES>
impl<const BYTES: usize> FillPrefix<u64> for Bitmap<BYTES>
fn fill_prefix(&mut self, value: u64) -> &mut Self
source§impl<const BYTES: usize> FillPrefix<u8> for Bitmap<BYTES>
impl<const BYTES: usize> FillPrefix<u8> for Bitmap<BYTES>
fn fill_prefix(&mut self, value: u8) -> &mut Self
source§impl<const BYTES: usize> FillPrefix<usize> for Bitmap<BYTES>
impl<const BYTES: usize> FillPrefix<usize> for Bitmap<BYTES>
fn fill_prefix(&mut self, value: usize) -> &mut Self
source§impl<const BYTES: usize, const N: usize> From<[u8; N]> for Bitmap<BYTES>
impl<const BYTES: usize, const N: usize> From<[u8; N]> for Bitmap<BYTES>
source§fn from(value: [u8; N]) -> Self
fn from(value: [u8; N]) -> Self
Convert a array [u8; N]
into Bitmap<BYTES>
.
The generics N
and BYTES
has not to be equal.
If N < BYTES
, the bitmap will have BYTES - N
bytes of leading zero.
Examples
use cbitmap::bitmap::*;
let map = Bitmap::<2>::from([0u8; 2]);
There are also aliases for integer types:
use cbitmap::bitmap::*;
let map = Bitmap::<1>::from(0u8);