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