more documentation
This commit is contained in:
parent
daaa31a276
commit
d351eef6fa
6 changed files with 194 additions and 22 deletions
|
@ -1,6 +1,6 @@
|
|||
use crate::DataRef;
|
||||
|
||||
/// A vector of bits
|
||||
/// A fixed-size vector of bits
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub struct BitVec {
|
||||
size: usize,
|
||||
|
@ -8,17 +8,17 @@ pub struct BitVec {
|
|||
}
|
||||
|
||||
impl BitVec {
|
||||
/// Create a new bit vector.
|
||||
/// Create a new `BitVec`.
|
||||
///
|
||||
/// # Arguments
|
||||
///
|
||||
/// * `size`: size in bits. Must be dividable by 8.
|
||||
/// * `size`: size in bits.
|
||||
///
|
||||
/// returns: bit vector with all bits set to false.
|
||||
/// returns: `BitVec` with all bits set to false.
|
||||
///
|
||||
/// # Panics
|
||||
///
|
||||
/// When size is not a multiple of 8.
|
||||
/// When `size` is not divisible by 8.
|
||||
#[must_use]
|
||||
pub fn new(size: usize) -> BitVec {
|
||||
assert_eq!(size % 8, 0);
|
||||
|
@ -36,6 +36,10 @@ impl BitVec {
|
|||
/// * `value`: the value to set the bit to
|
||||
///
|
||||
/// returns: old value of the bit
|
||||
///
|
||||
/// # Panics
|
||||
///
|
||||
/// When accessing `index` out of bounds.
|
||||
pub fn set(&mut self, index: usize, value: bool) -> bool {
|
||||
let (byte_index, bit_mask) = self.get_indexes(index);
|
||||
|
||||
|
@ -58,6 +62,10 @@ impl BitVec {
|
|||
/// * `index`: the bit index to read
|
||||
///
|
||||
/// returns: value of the bit
|
||||
///
|
||||
/// # Panics
|
||||
///
|
||||
/// When accessing `index` out of bounds.
|
||||
#[must_use]
|
||||
pub fn get(&self, index: usize) -> bool {
|
||||
let (byte_index, bit_mask) = self.get_indexes(index);
|
||||
|
|
|
@ -52,6 +52,18 @@ impl Grid<u8> for ByteGrid {
|
|||
}
|
||||
}
|
||||
|
||||
/// Sets the value of the cell at the specified position in the `ByteGrid.
|
||||
///
|
||||
/// # Arguments
|
||||
///
|
||||
/// * `x` and `y`: position of the cell
|
||||
/// * `value`: the value to write to the cell
|
||||
///
|
||||
/// returns: old value of the cell.
|
||||
///
|
||||
/// # Panics
|
||||
///
|
||||
/// When accessing `x` or `y` out of bounds.
|
||||
fn set(&mut self, x: usize, y: usize, value: u8) -> u8 {
|
||||
self.check_indexes(x, y);
|
||||
let pos = &mut self.data[x + y * self.width];
|
||||
|
@ -60,6 +72,15 @@ impl Grid<u8> for ByteGrid {
|
|||
old_val
|
||||
}
|
||||
|
||||
/// Gets the current value at the specified position.
|
||||
///
|
||||
/// # Arguments
|
||||
///
|
||||
/// * `x` and `y`: position of the cell to read
|
||||
///
|
||||
/// # Panics
|
||||
///
|
||||
/// When accessing `x` or `y` out of bounds.
|
||||
fn get(&self, x: usize, y: usize) -> u8 {
|
||||
self.check_indexes(x, y);
|
||||
self.data[x + y * self.width]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue