use std::ops::{Deref, DerefMut, Index, IndexMut};
use petgraph::graph::{EdgeIndex, IndexType, NodeIndex};
use petgraph::visit::GraphBase;
use crate::{BoundedGraph, BoundedNode};
impl<N, E, G> Deref for BoundedGraph<N, E, G> {
type Target = G;
fn deref(&self) -> &Self::Target {
&self.graph
}
}
impl<N, E, G> DerefMut for BoundedGraph<N, E, G>
where
N: crate::ImmutableEdgeBounds,
{
fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.graph
}
}
impl<N, E, G> AsRef<G> for BoundedGraph<N, E, G> {
fn as_ref(&self) -> &G {
&self.graph
}
}
impl<N, E, Ix, G> Index<EdgeIndex<Ix>> for BoundedGraph<N, E, G>
where
Ix: IndexType,
G: GraphBase<NodeId = NodeIndex<Ix>, EdgeId = EdgeIndex<Ix>> + Index<EdgeIndex<Ix>>,
{
type Output = G::Output;
fn index(&self, index: EdgeIndex<Ix>) -> &Self::Output {
&self.graph[index]
}
}
impl<N, E, Ix, G> Index<NodeIndex<Ix>> for BoundedGraph<N, E, G>
where
Ix: IndexType,
G: GraphBase<NodeId = NodeIndex<Ix>, EdgeId = EdgeIndex<Ix>> + Index<NodeIndex<Ix>>,
{
type Output = G::Output;
fn index(&self, index: NodeIndex<Ix>) -> &Self::Output {
&self.graph[index]
}
}
impl<N, E, Ix, G> IndexMut<EdgeIndex<Ix>> for BoundedGraph<N, E, G>
where
Ix: IndexType,
G: GraphBase<NodeId = NodeIndex<Ix>, EdgeId = EdgeIndex<Ix>>
+ IndexMut<EdgeIndex<Ix>, Output = E>,
{
fn index_mut(&mut self, index: EdgeIndex<Ix>) -> &mut Self::Output {
&mut self.graph[index]
}
}
impl<N, E, Ix, G> IndexMut<NodeIndex<Ix>> for BoundedGraph<N, E, G>
where
Ix: IndexType,
N: BoundedNode<Ix> + crate::ImmutableEdgeBounds,
G: GraphBase<NodeId = NodeIndex<Ix>, EdgeId = EdgeIndex<Ix>> + IndexMut<NodeIndex<Ix>>,
{
fn index_mut(&mut self, index: NodeIndex<Ix>) -> &mut Self::Output {
&mut self.graph[index]
}
}