pub struct RecentList<T: Copy> {
slots: Vec<T>,
}
impl<T: Copy> RecentList<T> {
pub fn new(items: Vec<T>) -> Self {
RecentList { slots: items }
}
pub fn push(&mut self, value: T) {
for i in (1..self.slots.len()).rev() {
self.slots[i] = self.slots[i - 1];
}
self.slots[0] = value;
}
pub fn promote(&mut self, index: usize) -> T {
let value = self.slots[index];
for i in (1..=index).rev() {
self.slots[i] = self.slots[i - 1];
}
self.slots[0] = value;
value
}
}