use crate::optimizer::cost::config::DEFAULT_FANOUT;
use crate::optimizer::stats::StatsView;
pub(super) const DEFAULT_NEIGHBORHOOD_FANOUT: u64 = DEFAULT_FANOUT;
pub(super) const DEFAULT_FILTER_SELECTIVITY: f64 = 0.1;
pub(super) fn stats_fanout(stats: &StatsView, edge_types: &[String]) -> u64 {
edge_types
.iter()
.filter_map(|edge_type| {
stats
.edge_stats(edge_type)
.map(|s| (s.avg_out_degree.max(s.avg_in_degree).round().max(0.0)) as u64)
})
.max()
.filter(|fanout| *fanout > 0)
.unwrap_or(DEFAULT_NEIGHBORHOOD_FANOUT)
}
pub(super) fn stats_fanout_skewed(stats: &StatsView, edge_types: &[String]) -> u64 {
let base = stats_fanout(stats, edge_types) as f64;
let factor = edge_types
.iter()
.filter_map(|edge_type| stats.edge_stats(edge_type))
.map(|s| s.skew_row_factor())
.fold(1.0f64, f64::max);
((base * factor).round() as u64).max(1)
}