Skip to content

Commit

Permalink
feat: reserve (#44)
Browse files Browse the repository at this point in the history
* feat: reserve

* fix: take currently free slots into account
  • Loading branch information
zxch3n authored Oct 22, 2023
1 parent cfea6b6 commit 9e0a6dc
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/arena.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,13 @@ impl<T> Arena<T> {
self.storage.capacity()
}

/// Reserve capacity for at least `additional` more elements to be inserted
pub fn reserve(&mut self, additional: usize) {
let currently_free = self.storage.len().saturating_sub(self.len as usize);
let to_reserve = additional.saturating_sub(currently_free);
self.storage.reserve(to_reserve);
}

/// Returns whether the arena is empty.
pub const fn is_empty(&self) -> bool {
self.len == 0
Expand Down

0 comments on commit 9e0a6dc

Please sign in to comment.