use crate::prelude::*;
use hashbrown::HashSet;
pub trait GraphWrapper<'a>: GraphBasics<'a> {
type Inner: GraphBasics<'a>;
fn into_inner(&'a self) -> &'a Self::Inner;
}
impl<'a, G1, G2: 'a> GraphProperties<'a> for G1
where
G2: GraphBasics<
'a,
NodeIndex = G1::NodeIndex,
EdgeIndex = G1::EdgeIndex,
NodeRef = G1::NodeRef,
EdgeRef = G1::NodeRef,
> + GraphProperties<'a>,
G1: GraphWrapper<'a, Inner = G2>,
{
fn incident_edges(
&'a self,
node_index: <Self as GraphBasics<'a>>::NodeIndex,
) -> Option<HashSet<<Self as GraphBasics<'a>>::EdgeIndex>> {
self.into_inner().incident_edges(node_index)
}
fn contained_nodes(
&'a self,
edge_index: <Self as GraphBasics<'a>>::EdgeIndex,
) -> Option<HashSet<<Self as GraphBasics<'a>>::NodeIndex>> {
self.into_inner().contained_nodes(edge_index)
}
fn neighbours(
&'a self,
node_index: <Self as GraphBasics<'a>>::NodeIndex,
) -> Option<HashSet<<Self as GraphBasics<'a>>::NodeIndex>> {
self.into_inner().neighbours(node_index)
}
fn neighbour_count(&'a self, node_index: usize) -> Option<usize> {
self.into_inner().neighbour_count(node_index)
}
fn degree(&'a self, node_index: <Self as GraphBasics<'a>>::NodeIndex) -> Option<usize> {
self.into_inner().degree(node_index)
}
fn degree_by_order(
&'a self,
node_index: <Self as GraphBasics<'a>>::NodeIndex,
order: usize,
) -> Option<usize> {
self.into_inner().degree_by_order(node_index, order)
}
fn connected_components(&'a self) -> Vec<Vec<<Self as GraphBasics<'a>>::NodeIndex>> {
self.into_inner().connected_components()
}
type Subgraph = G2::Subgraph;
fn component(&'a self, node_index: usize) -> Option<Vec<usize>> {
self.into_inner().component(node_index)
}
fn extract_component(&'a self, node_index: usize) -> Option<Self::Subgraph> {
self.into_inner().extract_component(node_index)
}
}
impl<'a, G1, G2: 'a> DiGraphProperties<'a> for G1
where
G2: GraphBasics<
'a,
NodeIndex = G1::NodeIndex,
EdgeIndex = G1::EdgeIndex,
NodeRef = G1::NodeRef,
EdgeRef = G1::NodeRef,
> + DiGraphProperties<'a>,
G1: GraphWrapper<'a, Inner = G2>,
{
fn in_edges(
&'a self,
node_index: <Self as GraphBasics<'a>>::NodeIndex,
) -> Option<HashSet<<Self as GraphBasics<'a>>::EdgeIndex>> {
self.into_inner().in_edges(node_index)
}
fn in_edge_count(&'a self, node_index: <Self as GraphBasics<'a>>::NodeIndex) -> Option<usize> {
self.into_inner().in_edge_count(node_index)
}
fn out_edges(
&'a self,
node_index: <Self as GraphBasics<'a>>::NodeIndex,
) -> Option<HashSet<<Self as GraphBasics<'a>>::EdgeIndex>> {
self.into_inner().out_edges(node_index)
}
fn out_edge_count(&'a self, node_index: <Self as GraphBasics<'a>>::NodeIndex) -> Option<usize> {
self.into_inner().out_edge_count(node_index)
}
fn in_neighbours(
&'a self,
node_index: <Self as GraphBasics<'a>>::NodeIndex,
) -> Option<HashSet<<Self as GraphBasics<'a>>::NodeIndex>> {
self.into_inner().in_neighbours(node_index)
}
fn out_neighbours(
&'a self,
node_index: <Self as GraphBasics<'a>>::NodeIndex,
) -> Option<HashSet<<Self as GraphBasics<'a>>::NodeIndex>> {
self.into_inner().out_neighbours(node_index)
}
fn in_neighbour_count(
&'a self,
node_index: <Self as GraphBasics<'a>>::NodeIndex,
) -> Option<usize> {
self.into_inner().in_neighbour_count(node_index)
}
fn out_neighbour_count(
&'a self,
node_index: <Self as GraphBasics<'a>>::NodeIndex,
) -> Option<usize> {
self.into_inner().out_neighbour_count(node_index)
}
fn strongly_connected_components(&'a self) -> Vec<Vec<usize>> {
self.into_inner().strongly_connected_components()
}
fn strong_component(
&'a self,
node_index: <Self as GraphBasics<'a>>::NodeIndex,
) -> Option<Vec<usize>> {
self.into_inner().strong_component(node_index)
}
fn extract_strong_component(
&'a self,
node_index: <Self as GraphBasics<'a>>::NodeIndex,
) -> Option<Self::Subgraph> {
self.into_inner().extract_strong_component(node_index)
}
fn condense(&'a self) -> DiGraph<(), ()> {
self.into_inner().condense()
}
fn weakly_connected_components(&'a self) -> Vec<Vec<usize>> {
self.into_inner().weakly_connected_components()
}
fn weak_component(
&'a self,
node_index: <Self as GraphBasics<'a>>::NodeIndex,
) -> Option<Vec<usize>> {
self.into_inner().weak_component(node_index)
}
fn extract_weak_component(
&'a self,
node_index: <Self as GraphBasics<'a>>::NodeIndex,
) -> Option<Self::Subgraph> {
self.into_inner().extract_weak_component(node_index)
}
fn in_degree(&'a self, node_index: <Self as GraphBasics<'a>>::NodeIndex) -> Option<usize> {
self.into_inner().in_degree(node_index)
}
fn out_degree(&'a self, node_index: <Self as GraphBasics<'a>>::NodeIndex) -> Option<usize> {
self.into_inner().out_degree(node_index)
}
type Subgraph = G2::Subgraph;
fn source(
&'a self,
edge_index: <Self as GraphBasics<'a>>::EdgeIndex,
) -> Option<HashSet<<Self as GraphBasics<'a>>::NodeIndex>> {
self.into_inner().source(edge_index)
}
fn target(
&'a self,
edge_index: <Self as GraphBasics<'a>>::EdgeIndex,
) -> Option<HashSet<<Self as GraphBasics<'a>>::NodeIndex>> {
self.into_inner().target(edge_index)
}
}
impl<'a, G1, G2: 'a> HypergraphBasics<'a> for G1
where
G2: GraphBasics<
'a,
NodeIndex = G1::NodeIndex,
EdgeIndex = G1::EdgeIndex,
NodeRef = G1::NodeRef,
EdgeRef = G1::NodeRef,
> + HypergraphBasics<'a>,
G1: GraphWrapper<'a, Inner = G2>,
{
fn uniform(&'a self) -> bool {
self.into_inner().uniform()
}
type DualType = G2::DualType;
fn dual(&'a self) -> Self::DualType {
self.into_inner().dual()
}
}
impl<'a, G1, G2: 'a, N: 'a, E: 'a> DirectedHypergraphProperties<'a, N, E> for G1
where
G2: GraphBasics<
'a,
NodeIndex = G1::NodeIndex,
EdgeIndex = G1::EdgeIndex,
NodeRef = G1::NodeRef,
EdgeRef = G1::NodeRef,
> + HypergraphBasics<'a>
+ DirectedHypergraphProperties<'a, N, E>,
G1: GraphWrapper<'a, Inner = G2>,
{
fn in_order(&'a self, edge_index: <Self as GraphBasics<'a>>::EdgeIndex) -> Option<usize> {
self.into_inner().in_order(edge_index)
}
fn out_order(&'a self, edge_index: <Self as GraphBasics<'a>>::EdgeIndex) -> Option<usize> {
self.into_inner().out_order(edge_index)
}
fn digraph_view(&'a self) -> DiGraph<&'a N, &'a E> {
self.into_inner().digraph_view()
}
}
impl<'a, G1, G2: 'a, N: 'a, E: 'a> HypergraphProperties<'a, N, E> for G1
where
G2: GraphBasics<
'a,
NodeIndex = G1::NodeIndex,
EdgeIndex = G1::EdgeIndex,
NodeRef = G1::NodeRef,
EdgeRef = G1::NodeRef,
> + HypergraphBasics<'a>
+ HypergraphProperties<'a, N, E>,
G1: GraphWrapper<'a, Inner = G2>,
{
fn order(&'a self, edge_index: <Self as GraphBasics<'a>>::EdgeIndex) -> Option<usize> {
self.into_inner().order(edge_index)
}
fn graph_view(&'a self) -> Graph<&'a N, &'a E> {
self.into_inner().graph_view()
}
}