use std::collections::{BTreeMap, BTreeSet};
use crate::app_src::AppSrcSpec;
use crate::model::names::ApplicationName;
const MIN_DEPENDENTS: usize = 2;
pub fn derive_library_apps(apps: &[AppSrcSpec]) -> Vec<ApplicationName> {
let in_tree: BTreeSet<&ApplicationName> = apps.iter().map(|a| &a.name).collect();
let mut dependents: BTreeMap<ApplicationName, usize> = BTreeMap::new();
for app in apps {
for dep in &app.applications {
if !in_tree.contains(dep) {
continue;
}
if &app.name == dep {
continue;
}
*dependents.entry(dep.clone()).or_insert(0) += 1;
}
}
dependents
.into_iter()
.filter(|(_, n)| *n >= MIN_DEPENDENTS)
.map(|(name, _)| name)
.collect()
}