Struct datazoo::jagged_bitset::JaggedBitset
source · pub struct JaggedBitset { /* private fields */ }
Expand description
A bit matrix similar to BitMatrix
,
but with columns of variable length like JaggedVec
.
Use jagged_bitset::Builder
to create a JaggedBitset
.
Example
use datazoo::jagged_bitset;
let jagged = jagged_bitset::Builder::with_capacity(7)
.with_row([0, 2, 4, 8])
.with_row([63, 12, 2, 3])
.with_row([1, 3, 5, 7, 9, 11])
.with_row([])
.with_row([])
.with_row([])
.with_row([1, 3])
.build();
let row_1: Vec<_> = jagged.row(1).collect();
assert_eq!(&row_1, &[2, 3, 12, 63]);
let row_3: Vec<_> = jagged.row(3).collect();
assert_eq!(&row_3, &[]);
let row_6: Vec<_> = jagged.row(6).collect();
assert_eq!(&row_6, &[1, 3]);
Implementations§
source§impl JaggedBitset
impl JaggedBitset
sourcepub fn bit(&self, x: usize, y: usize) -> bool
pub fn bit(&self, x: usize, y: usize) -> bool
True if bits at column x
and row y
is enabled. False if not, or
if (x, y)
is not within the array.
sourcepub fn get_width(&self, index: usize) -> Option<u32>
pub fn get_width(&self, index: usize) -> Option<u32>
Return the column count of index
row.
None
if index
is greater or equal to the height
.
sourcepub fn get_row(
&self,
index: usize
) -> Option<impl Iterator<Item = u32> + SortedByItem + '_>
pub fn get_row( &self, index: usize ) -> Option<impl Iterator<Item = u32> + SortedByItem + '_>
Iterate over all enabled bits in given index
row.
Returns None
if the row is out of bound.
sourcepub const fn braille_trans_display(&self) -> BrailleTransposedDisplay<'_>
pub const fn braille_trans_display(&self) -> BrailleTransposedDisplay<'_>
Like JaggedBitset::braille_display
, but with rows and columns
transposed (ie: rotated 90º clockwise and mirrored).
Example
use datazoo::jagged_bitset;
let jagged = jagged_bitset::Builder::with_capacity(10)
.with_row([ 7, 8, 9, 10, 11, 12, 13 ])
.with_row([0, 9, 10, 11, 12, 13, 14, 15, 16, 17])
.with_row([0, 1, 2, 4, 5, 6, 13, 14 ])
.with_row([ 4, 5, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17])
.with_row([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17])
.with_row([0, 1, 3, 4, 7, 8, 9, 10, 11, 15, 16, 17])
.with_row([0, 2, 4, 6, 8, 10, 12, 14, 16, 17])
.with_row([ 1, 3, 5, 7, 9, 11, 13, 15, 16 ])
.with_row([ ])
.with_row([ 11, ])
.build();
let shown = jagged.braille_trans_display().to_string();
let expected = "🭴⠈⠇⣟⢕⠀🭰\n🭴⡀⢟⣏⢕⠀🭰\n🭴⣷⢸⣿⢕⢀🭰\n🭴⢻⢾⣇⢕⠀🭰\n🭴⠘⠘⠛⠋⠀🭰";
assert_eq!(expected, &shown);
sourcepub const fn braille_display(&self) -> BrailleDisplay<'_>
pub const fn braille_display(&self) -> BrailleDisplay<'_>
Return a struct that, when printed with fmt::Display
or fmt::Debug
,
displays the jagged bitset using unicode braille characters(wikipedia).
Example
use datazoo::jagged_bitset;
let jagged = jagged_bitset::Builder::with_capacity(10)
.with_row([ 7, 8, 9, 10, 11, 12, 13 ])
.with_row([0, 9, 10, 11, 12, 13, 14, 15, 16, 17])
.with_row([0, 1, 2, 4, 5, 6, 13, 14 ])
.with_row([ 4, 5, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17])
.build();
let shown = jagged.braille_display().to_string();
let expected = "🭴⠦⠄⣤⢌⣙⣛⣻⣖⣒🭰";
assert_eq!(expected, &shown);
Trait Implementations§
source§impl Clone for JaggedBitset
impl Clone for JaggedBitset
source§fn clone(&self) -> JaggedBitset
fn clone(&self) -> JaggedBitset
Returns a copy of the value. Read more
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moresource§impl Debug for JaggedBitset
impl Debug for JaggedBitset
source§impl Default for JaggedBitset
impl Default for JaggedBitset
source§fn default() -> JaggedBitset
fn default() -> JaggedBitset
Returns the “default value” for a type. Read more
Auto Trait Implementations§
impl RefUnwindSafe for JaggedBitset
impl Send for JaggedBitset
impl Sync for JaggedBitset
impl Unpin for JaggedBitset
impl UnwindSafe for JaggedBitset
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more