#[derive(Debug, Clone, Copy)]
pub enum Granularity {
Nodes(usize),
Arcs(u64),
}
impl core::default::Default for Granularity {
fn default() -> Self {
Self::Nodes(1000)
}
}
impl Granularity {
pub fn node_granularity(&self, num_nodes: usize, num_arcs: Option<u64>) -> usize {
match self {
Self::Nodes(n) => *n,
Self::Arcs(n) => {
let average_degree = num_arcs.expect(
"You need the number of arcs to convert arc granularity to node granularity",
) as f64
/ num_nodes.max(1) as f64;
(*n as f64 / average_degree).min(usize::MAX as f64).ceil() as usize
}
}
}
pub fn arc_granularity(&self, num_nodes: usize, num_arcs: Option<u64>) -> usize {
match self {
Self::Nodes(n) => {
let average_degree = num_arcs.expect(
"You need the number of arcs to convert node granularity to arc granularity",
) as f64
/ num_nodes.max(1) as f64;
(*n as f64 * average_degree).ceil().max(1.) as usize
}
Self::Arcs(n) => *n as usize,
}
}
}