rive_rs/
dependency_sorter.rsuse std::collections::{HashSet, VecDeque};
use crate::core::Object;
use crate::Component;
#[derive(Debug, Default)]
pub struct DependencySorter {
perm: HashSet<Object<Component>>,
temp: HashSet<Object<Component>>,
}
impl DependencySorter {
pub fn sort(&mut self, root: Object<Component>, order: &mut VecDeque<Object<Component>>) {
order.clear();
self.visit(root, order);
}
fn visit(&mut self, component: Object<Component>, order: &mut VecDeque<Object<Component>>) {
if self.perm.contains(&component) {
return;
}
if self.temp.contains(&component) {
panic!("dependency cycle");
}
self.temp.insert(component.clone());
for dependent in component.as_ref().depdenents() {
self.visit(dependent, order);
}
self.perm.insert(component.clone());
order.push_front(component);
}
}