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
impl PackedArray
Sourcepub fn new(length: usize, byte_size: u8, default: Option<u64>) -> Self
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.
pub fn from_raw(length: usize, byte_size: u8, cells: Vec<u64>) -> Option<Self>
Sourcepub fn get(&self, index: usize) -> Option<u64>
pub fn get(&self, index: usize) -> Option<u64>
Get the value at a specific index, None
is returned if you are out of range.
Sourcepub fn set(&mut self, index: usize, value: u64) -> u64
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.
Sourcepub fn set_with_resize(&mut self, index: usize, value: u64) -> u64
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.
pub fn iter<'a>(&'a self) -> impl Iterator<Item = u64> + 'a
pub fn replace(&mut self, replacer: impl FnMut(usize, u64) -> u64)
pub fn resize_byte(&mut self, new_byte_size: u8)
pub fn resize_byte_and_replace<F>(&mut self, new_byte_size: u8, replacer: F)
pub fn len(&self) -> usize
pub fn is_empty(&self) -> bool
pub fn byte_size(&self) -> u8
pub fn max_value(&self) -> u64
pub fn cells_len(&self) -> usize
pub fn get_cell(&self, index: usize) -> u64
pub unsafe fn set_cell(&mut self, index: usize, cell: u64)
pub unsafe fn resize_raw(&mut self, new_byte_size: u8)
pub unsafe fn clear_cells(&mut self)
pub fn into_inner(self) -> Vec<u64>
pub fn calc_values_per_cell(byte_size: u8) -> usize
pub fn calc_cells_capacity(length: usize, byte_size: u8) -> usize
pub fn calc_mask(byte_size: u8) -> u64
Sourcepub fn calc_min_byte_size(value: u64) -> u8
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.