Struct PackedArray

Source
pub struct PackedArray { /* private fields */ }
Expand description

A packed array is an array of cell (u64) with a fixed length and a varying bits length (byte size) that allows it to store multiple values in the same cell.

Its content can be modified and queried by using methods of this method, the byte size can also be changed and methods allows to replace its content in-place.

Implementations§

Source§

impl PackedArray

Source

pub fn new(length: usize, byte_size: u8, default: Option<u64>) -> Self

Create a new packed array with specific length and byte size (the bit size of each value, smallest addressable unit), the default value is 0 if None is given.

Source

pub fn from_raw(length: usize, byte_size: u8, cells: Vec<u64>) -> Option<Self>

Source

pub fn get(&self, index: usize) -> Option<u64>

Get the value at a specific index, None is returned if you are out of range.

Source

pub fn set(&mut self, index: usize, value: u64) -> u64

Set the value at a specific index.

§Panics

If the index is out of bounds or if the given value cannot fit in the current byte size.

Source

pub fn set_with_resize(&mut self, index: usize, value: u64) -> u64

Set the value at a specific index and ensure that the given value can fit into it, if not, the packed array is resized to a new byte size and the value is inserted.

Source

pub fn iter<'a>(&'a self) -> impl Iterator<Item = u64> + 'a

Source

pub fn replace(&mut self, replacer: impl FnMut(usize, u64) -> u64)

Source

pub fn resize_byte(&mut self, new_byte_size: u8)

Source

pub fn resize_byte_and_replace<F>(&mut self, new_byte_size: u8, replacer: F)
where F: FnMut(usize, u64) -> u64,

Source

pub fn len(&self) -> usize

Source

pub fn is_empty(&self) -> bool

Source

pub fn byte_size(&self) -> u8

Source

pub fn max_value(&self) -> u64

Source

pub fn cells_len(&self) -> usize

Source

pub fn get_cell(&self, index: usize) -> u64

Source

pub unsafe fn set_cell(&mut self, index: usize, cell: u64)

Source

pub unsafe fn resize_raw(&mut self, new_byte_size: u8)

Source

pub unsafe fn clear_cells(&mut self)

Source

pub fn into_inner(self) -> Vec<u64>

Source

pub fn calc_values_per_cell(byte_size: u8) -> usize

Source

pub fn calc_cells_capacity(length: usize, byte_size: u8) -> usize

Source

pub fn calc_mask(byte_size: u8) -> u64

Source

pub fn calc_min_byte_size(value: u64) -> u8

Calculate the minimum size in bits to store de given value, the special case is for value 0 which returns a bits size of 1, this special value is simpler to handle by the structure’s methods.

Auto Trait Implementations§

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where 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 T
where 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, U> TryFrom<U> for T
where U: Into<T>,

Source§

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

Source§

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.
Source§

impl<T> Component for T
where T: Send + Sync + 'static,