use std::sync::Arc;
use crate::analysis::{
BetweennessCentrality, CondensationGraph, DegreeCentrality, GraphComponents, GraphDirection,
GraphDivergence, GraphEdgeSelection, GraphNeighbor, GraphPath, GraphSubgraph,
LayoutAssistMetadata,
};
use crate::id::GraphNodeId;
use super::storage::BoundedStore;
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub(crate) enum ProductOperation {
Neighbors {
node: GraphNodeId,
depth: u32,
direction: GraphDirection,
},
Path {
source: GraphNodeId,
target: GraphNodeId,
},
Subgraph {
seed: GraphNodeId,
depth: u32,
direction: GraphDirection,
},
Degree,
Betweenness,
Components,
Condensation,
Divergence,
Layout,
}
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub(crate) struct ProductClaim {
selection: GraphEdgeSelection,
operation: ProductOperation,
}
impl ProductClaim {
pub(crate) fn new(selection: GraphEdgeSelection, operation: ProductOperation) -> Self {
Self {
selection,
operation,
}
}
}
#[derive(Clone)]
pub(crate) enum ProductValue {
Neighbors(Arc<[GraphNeighbor]>),
Path(Option<Arc<GraphPath>>),
Subgraph(Arc<GraphSubgraph>),
Degree(Arc<[DegreeCentrality]>),
Betweenness(Arc<[BetweennessCentrality]>),
Components(Arc<GraphComponents>),
Condensation(Arc<CondensationGraph>),
Divergence(Arc<GraphDivergence>),
Layout(Arc<LayoutAssistMetadata>),
}
pub(crate) trait Product: Clone {
fn read(value: ProductValue) -> Option<Self>;
fn state(self) -> ProductValue;
}
macro_rules! stated_products {
($($variant:ident => $shape:ty,)+) => {
$(
impl Product for $shape {
fn read(value: ProductValue) -> Option<Self> {
match value {
ProductValue::$variant(held) => Some(held),
_ => None,
}
}
fn state(self) -> ProductValue {
ProductValue::$variant(self)
}
}
)+
};
}
stated_products! {
Neighbors => Arc<[GraphNeighbor]>,
Path => Option<Arc<GraphPath>>,
Subgraph => Arc<GraphSubgraph>,
Degree => Arc<[DegreeCentrality]>,
Betweenness => Arc<[BetweennessCentrality]>,
Components => Arc<GraphComponents>,
Condensation => Arc<CondensationGraph>,
Divergence => Arc<GraphDivergence>,
Layout => Arc<LayoutAssistMetadata>,
}
pub(crate) type ProductStore = BoundedStore<ProductClaim, ProductValue>;