Skip to content

Commit

Permalink
Use exponential growth for O(1) amortizied complexity
Browse files Browse the repository at this point in the history
  • Loading branch information
NobodyXu authored Oct 19, 2024
1 parent 89b0efc commit 3dc2c1d
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/arena.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,10 @@ impl<T: Send + Sync, const BITARRAY_LEN: usize, const LEN: usize> Arena<T, BITAR
// reservation.
//
// We can simply restart operation, waiting for it to be done.
self.try_reserve(len + 4);
//
// Grow by 1.5 exponential to have amoritized O(1), adding +4 more in case
// there's only one element (1 * 3 / 2 evaluaes to 1 in rust).
self.try_reserve(len * 3 / 2 + 4);
}
}
}
Expand Down

0 comments on commit 3dc2c1d

Please sign in to comment.