Skip to content

Commit

Permalink
Automated formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
github-actions[bot] committed Oct 13, 2023
1 parent 70e17cf commit 8932554
Show file tree
Hide file tree
Showing 3 changed files with 116 additions and 139 deletions.
22 changes: 11 additions & 11 deletions src/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ pub struct Block {
next_block_index: i32,
}

const NONE_INT :i32 = -1;
const NONE_INT: i32 = -1;

impl Block {
pub fn get_n_elements(&self) -> i32 {
self.n_elements
pub fn get_n_elements(&self) -> i32 {
self.n_elements
}

pub fn set_n_elements(&mut self, n_elements: i32) {
Expand All @@ -29,30 +29,30 @@ impl Block {
pub fn grow(&mut self, increase: i32) -> Result<i32, i32> {
let new_cap = self.n_elements + increase;
if self.has_next_block() && (new_cap >= self.next_block_index) {
return Err(new_cap)
return Err(new_cap);
}
self.n_elements = new_cap;
Ok(new_cap)
}

/// Returns the new number of elements.
/// Errors if the value is shrunk to or below 0.
pub fn shrink(&mut self, decrease: i32) -> Result<i32, i32> {
pub fn shrink(&mut self, decrease: i32) -> Result<i32, i32> {
let new_cap = self.n_elements - decrease;
if new_cap <= 0 {
return Err(new_cap)
return Err(new_cap);
}
self.n_elements = new_cap;
Ok(new_cap)
}

pub fn has_next_block(&self) -> bool {
pub fn has_next_block(&self) -> bool {
self.next_block_index != NONE_INT
}

/// The block should be removed from the freelist if this is true.
pub fn is_empty(&self) -> bool {
self.n_elements == 0
pub fn is_empty(&self) -> bool {
self.n_elements == 0
}

pub fn get_next_block_index(&self) -> Option<i32> {
Expand All @@ -62,9 +62,9 @@ impl Block {
}
}

/// This basically just changes `next_block_index`, since blocks
/// This basically just changes `next_block_index`, since blocks
/// do not have references to the previous block (for now?).
pub fn connect_at(&mut self, block_index: Option<i32>) {
self.next_block_index = block_index.unwrap_or_else(|| NONE_INT)
self.next_block_index = block_index.unwrap_or_else(|| NONE_INT)
}
}
Loading

0 comments on commit 8932554

Please sign in to comment.