use crate::ir::NodeId;
use indexmap::IndexSet;
pub struct Scheduler {
dirty_nodes: IndexSet<NodeId>,
}
impl Scheduler {
pub fn new() -> Self {
Self {
dirty_nodes: IndexSet::new(),
}
}
pub fn mark_dirty(&mut self, node_id: NodeId) {
self.dirty_nodes.insert(node_id);
}
pub fn mark_many_dirty(&mut self, node_ids: impl IntoIterator<Item = NodeId>) {
self.dirty_nodes.extend(node_ids);
}
pub fn take_dirty(&mut self) -> IndexSet<NodeId> {
std::mem::take(&mut self.dirty_nodes)
}
pub fn has_dirty(&self) -> bool {
!self.dirty_nodes.is_empty()
}
pub fn clear(&mut self) {
self.dirty_nodes.clear();
}
}
impl Default for Scheduler {
fn default() -> Self {
Self::new()
}
}