use annis::db::AnnotationStorage;
use annis::db::Graph;
use annis::errors::*;
use annis::types::{AnnoKey, Annotation, Edge, NodeID};
use bincode;
use malloc_size_of::MallocSizeOf;
use serde::Deserialize;
use std;
#[derive(Serialize, Deserialize, Clone, MallocSizeOf)]
pub struct GraphStatistic {
pub cyclic: bool,
pub rooted_tree: bool,
pub nodes: usize,
pub avg_fan_out: f64,
pub fan_out_99_percentile: usize,
pub max_fan_out: usize,
pub max_depth: usize,
pub dfs_visit_ratio: f64,
}
pub trait EdgeContainer: Sync + Send + MallocSizeOf {
fn get_outgoing_edges<'a>(&'a self, node: &NodeID) -> Box<Iterator<Item = NodeID> + 'a>;
fn get_ingoing_edges<'a>(&'a self, node: &NodeID) -> Box<Iterator<Item = NodeID> + 'a>;
fn get_anno_storage(&self) -> &AnnotationStorage<Edge>;
fn get_statistics(&self) -> Option<&GraphStatistic> {
None
}
fn source_nodes<'a>(&'a self) -> Box<Iterator<Item = NodeID> + 'a>;
}
pub trait GraphStorage: EdgeContainer {
fn find_connected<'a>(
&'a self,
node: &NodeID,
min_distance: usize,
max_distance: usize,
) -> Box<Iterator<Item = NodeID> + 'a>;
fn find_connected_inverse<'a>(
&'a self,
node: &NodeID,
min_distance: usize,
max_distance: usize,
) -> Box<Iterator<Item = NodeID> + 'a>;
fn distance(&self, source: &NodeID, target: &NodeID) -> Option<usize>;
fn is_connected(
&self,
source: &NodeID,
target: &NodeID,
min_distance: usize,
max_distance: usize,
) -> bool;
fn copy(&mut self, db: &Graph, orig: &EdgeContainer);
fn as_edgecontainer(&self) -> &EdgeContainer;
fn as_writeable(&mut self) -> Option<&mut WriteableGraphStorage> {
None
}
fn inverse_has_same_cost(&self) -> bool {
false
}
fn serialization_id(&self) -> String;
fn serialize_gs(&self, writer: &mut std::io::Write) -> Result<()>;
fn deserialize_gs(input: &mut std::io::Read) -> Result<Self>
where
for<'de> Self: std::marker::Sized + Deserialize<'de>,
{
let result = bincode::deserialize_from(input)?;
Ok(result)
}
}
pub trait WriteableGraphStorage: GraphStorage {
fn add_edge(&mut self, edge: Edge);
fn add_edge_annotation(&mut self, edge: Edge, anno: Annotation);
fn delete_edge(&mut self, edge: &Edge);
fn delete_edge_annotation(&mut self, edge: &Edge, anno_key: &AnnoKey);
fn delete_node(&mut self, node: &NodeID);
fn calculate_statistics(&mut self);
}
pub mod adjacencylist;
pub mod linear;
pub mod prepost;
pub mod registry;