use petgraph::graph::NodeIndex;
use std::cell::UnsafeCell;
use std::collections::VecDeque;
use std::rc::Rc;
#[derive(Debug, Clone)]
pub struct GarbageCollector {
removal_queue: Rc<UnsafeCell<VecDeque<NodeIndex>>>,
}
impl GarbageCollector {
pub(crate) fn new() -> Self {
Self {
removal_queue: Rc::new(UnsafeCell::new(VecDeque::new())),
}
}
#[inline(always)]
pub fn mark_for_sweep(&self, node: NodeIndex) {
unsafe { &mut *self.removal_queue.get() }.push_back(node);
}
#[inline(always)]
pub(crate) fn next_to_sweep(&self) -> Option<NodeIndex> {
unsafe { &mut *self.removal_queue.get() }.pop_front()
}
}