Fix a bug in the Lru

This commit is contained in:
Clément Renault 2024-09-25 16:01:08 +02:00
parent 29a7623c3f
commit 5f53935c8a
No known key found for this signature in database
GPG Key ID: F250A4C4E3AE5F5F

View File

@ -121,7 +121,7 @@ struct FixedSizeListNode<T> {
#[derive(Debug)]
struct FixedSizeList<T> {
nodes: Box<[Option<FixedSizeListNode<T>>]>,
/// The next None in the nodes.
/// The first `None` in the nodes.
next_free: usize,
// TODO Also, we probably do not need one of the front and back cursors.
front: usize,
@ -145,7 +145,7 @@ impl<T> FixedSizeList<T> {
#[inline]
fn len(&self) -> usize {
self.nodes.len() - self.next_free
self.next_free
}
#[inline]
@ -168,8 +168,9 @@ impl<T> FixedSizeList<T> {
if self.is_full() {
None
} else {
let current_free = self.next_free;
self.next_free += 1;
Some(self.next_free)
Some(current_free)
}
}