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

source

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.

source

pub fn max_width(&self) -> u32

Return the width of the longest row.

0 if height == 0.

source

pub fn height(&self) -> usize

How many rows there are in this bitset matrix.

source

pub fn capacity(&self) -> usize

Return an upper bound of how many rows this jagged bitset has.

source

pub fn width(&self, index: usize) -> u32

Return the column count of index row.

Panics

If index is greater or equal to the height.

source

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.

source

pub fn row(&self, index: usize) -> impl Iterator<Item = u32> + SortedByItem + '_

Iterate over all enabled bits in given index row.

Panics

If index is greater or equal to the height.

source

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.

source

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);
source

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

source§

fn clone(&self) -> JaggedBitset

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for JaggedBitset

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Default for JaggedBitset

source§

fn default() -> JaggedBitset

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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 Twhere 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> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

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

§

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 Twhere U: TryFrom<T>,

§

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.