mod debug;
mod dot;
#[doc(hidden)]
pub mod hyperedges;
mod shared;
mod utils;
#[doc(hidden)]
pub mod vertices;
use debug::ExtendedDebug;
use dot::render_to_graphviz_dot;
use indexmap::{IndexMap, IndexSet};
use std::{
fmt::{Debug, Formatter, Result},
hash::Hash,
};
pub type HyperedgeVertices = Vec<usize>;
pub type HyperedgeIndex = usize;
pub type WeightedHyperedgeIndex = [usize; 2];
pub type VertexIndex = usize;
pub struct Hypergraph<V, HE> {
pub vertices: IndexMap<V, IndexSet<HyperedgeVertices>>,
pub hyperedges: IndexMap<HyperedgeVertices, IndexSet<HE>>,
}
impl<V: Eq + Hash + Debug, HE: Debug> Debug for Hypergraph<V, HE> {
fn fmt(&self, f: &mut Formatter<'_>) -> Result {
self.vertices.fmt(f)
}
}
pub trait SharedTrait: Copy + Debug + Eq + Hash {}
impl<T> SharedTrait for T where T: Copy + Debug + Eq + Hash {}
impl<'a, V, HE> Default for Hypergraph<V, HE>
where
V: SharedTrait + ExtendedDebug<'a>,
HE: SharedTrait + ExtendedDebug<'a>,
{
fn default() -> Self {
Hypergraph::new()
}
}
impl<V, HE> Hypergraph<V, HE>
where
V: SharedTrait,
HE: SharedTrait,
{
pub fn new() -> Self {
Hypergraph::with_capacity(0, 0)
}
pub fn with_capacity(vertices: usize, hyperedges: usize) -> Self {
Hypergraph {
vertices: IndexMap::with_capacity(vertices),
hyperedges: IndexMap::with_capacity(hyperedges),
}
}
pub fn render_to_graphviz_dot(&self) {
println!("{}", render_to_graphviz_dot(&self));
}
}