use std::cell::UnsafeCell;
use crate::heap::HeapId;
pub struct FreeList {
ids: UnsafeCell<Vec<HeapId>>,
}
impl FreeList {
pub fn new() -> Self {
Self {
ids: UnsafeCell::new(Vec::new()),
}
}
pub fn pop(&self) -> Option<HeapId> {
unsafe { (*self.ids.get()).pop() }
}
pub fn push(&mut self, id: HeapId) {
self.ids.get_mut().push(id);
}
}
impl From<Vec<HeapId>> for FreeList {
fn from(ids: Vec<HeapId>) -> Self {
Self {
ids: UnsafeCell::new(ids),
}
}
}