use std::collections::HashMap;
use rustc_hash::FxHashMap;
use crate::{
annostorage::inmemory::AnnoStorageImpl,
types::{Edge, NodeID, NumValue},
};
use super::{
GraphStatistic,
linear::RelativePosition,
prepost::{OrderVecEntry, PrePost},
};
#[derive(Serialize, Deserialize, Clone)]
pub(crate) struct GraphStatisticV1 {
pub cyclic: bool,
pub rooted_tree: bool,
pub nodes: usize,
pub avg_fan_out: f64,
pub fan_out_99_percentile: usize,
pub inverse_fan_out_99_percentile: usize,
pub max_fan_out: usize,
pub max_depth: usize,
pub dfs_visit_ratio: f64,
}
impl From<GraphStatisticV1> for GraphStatistic {
fn from(value: GraphStatisticV1) -> Self {
let root_nodes = if value.nodes > 0 { 1 } else { 0 };
Self {
cyclic: value.cyclic,
rooted_tree: value.rooted_tree,
nodes: value.nodes,
root_nodes,
avg_fan_out: value.avg_fan_out,
fan_out_99_percentile: value.fan_out_99_percentile,
inverse_fan_out_99_percentile: value.inverse_fan_out_99_percentile,
max_fan_out: value.max_fan_out,
max_depth: value.max_depth,
dfs_visit_ratio: value.dfs_visit_ratio,
}
}
}
#[derive(Serialize, Deserialize, Clone)]
pub(crate) struct AdjacencyListStorageV1 {
pub(crate) edges: HashMap<NodeID, Vec<NodeID>>,
pub(crate) inverse_edges: HashMap<NodeID, Vec<NodeID>>,
pub(crate) annos: AnnoStorageImpl<Edge>,
pub(crate) stats: Option<GraphStatisticV1>,
}
#[derive(Serialize, Deserialize, Clone)]
pub(crate) struct DenseAdjacencyListStorageV1 {
pub(crate) edges: Vec<Option<NodeID>>,
pub(crate) inverse_edges: HashMap<NodeID, Vec<NodeID>>,
pub(crate) annos: AnnoStorageImpl<Edge>,
pub(crate) stats: Option<GraphStatisticV1>,
}
#[derive(Serialize, Deserialize, Clone)]
pub(crate) struct LinearGraphStorageV1<PosT: NumValue> {
pub(crate) node_to_pos: HashMap<NodeID, RelativePosition<PosT>>,
pub(crate) node_chains: HashMap<NodeID, Vec<NodeID>>,
pub(crate) annos: AnnoStorageImpl<Edge>,
pub(crate) stats: Option<GraphStatisticV1>,
}
#[derive(Serialize, Deserialize, Clone)]
pub(crate) struct PrePostOrderStorageV1<OrderT: NumValue, LevelT: NumValue> {
pub(crate) node_to_order: FxHashMap<NodeID, Vec<PrePost<OrderT, LevelT>>>,
pub(crate) order_to_node: Vec<OrderVecEntry<OrderT, LevelT>>,
pub(crate) annos: AnnoStorageImpl<Edge>,
pub(crate) stats: Option<GraphStatisticV1>,
}