use std::collections::HashSet;
use super::{DependencyGraph, ObjectId, Provenance};
pub(super) struct Reachability {
live: HashSet<ObjectId>,
}
impl Reachability {
pub(super) fn compute(graph: &DependencyGraph) -> Self {
let strong = graph.reach(graph.seed_indices(), Provenance::is_strong_pass_edge);
let live = graph.reach(strong.iter().copied(), Provenance::is_weak_pass_edge);
Self {
live: live
.into_iter()
.map(|idx| graph.object_at(idx).clone())
.collect(),
}
}
pub(super) fn is_live(&self, id: &ObjectId) -> bool {
self.live.contains(id)
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct UnusedObject {
pub id: ObjectId,
pub used_by: Vec<UsedBy>,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct UsedBy {
pub id: ObjectId,
pub provenance: Provenance,
pub also_unused: bool,
}