use core::hash::Hash;
use std::fmt::Debug;
use std::ops::{Add, AddAssign};
pub type DefaultIndexType = usize;
pub type DefaultWeightType = usize;
pub trait IndexType: Default + Debug + Copy + Eq + Ord {}
pub trait KeyType: Default + Debug + Copy + Eq + Ord + Hash {}
pub trait ValueType: Default + Debug {}
pub trait WeightType:
Default + Debug + Copy + Eq + Ord + Add<Output=Self> + AddAssign
{
}
impl<T> IndexType for T where T: Default + Debug + Copy + Eq + Ord {}
impl<T> KeyType for T where T: Default + Debug + Copy + Eq + Ord + Hash {}
impl<T> ValueType for T where T: Default + Debug {}
impl<T> WeightType for T where
T: Default + Debug + Copy + Eq + Ord + Add<Output=Self> + AddAssign
{}
#[derive(Debug, Copy, Clone, Eq, PartialEq, PartialOrd, Ord, Hash)]
pub struct EmptyWeight;
impl Default for EmptyWeight {
fn default() -> Self {
EmptyWeight
}
}
impl Add for EmptyWeight {
type Output = EmptyWeight;
fn add(self, _other: EmptyWeight) -> EmptyWeight {
EmptyWeight
}
}
impl AddAssign for EmptyWeight {
fn add_assign(&mut self, _other: EmptyWeight) {}
}
#[derive(Copy, Clone, Debug, Default, PartialEq, PartialOrd, Eq, Ord, Hash)]
pub struct NodeIndex<Ix = DefaultIndexType>(pub Ix);
impl<Ix> NodeIndex<Ix>
where
Ix: IndexType,
{
#[inline]
pub fn index(&self) -> Ix {
self.0
}
}
impl<Ix> From<Ix> for NodeIndex<Ix>
where
Ix: IndexType,
{
fn from(ix: Ix) -> Self {
NodeIndex(ix)
}
}
#[derive(Copy, Clone, Debug, Default, PartialEq, PartialOrd, Eq, Ord, Hash)]
pub struct VertexIndex<Ix = DefaultIndexType>(pub Ix);
impl<Ix> VertexIndex<Ix>
where
Ix: IndexType,
{
#[inline]
pub fn index(&self) -> Ix {
self.0
}
}
impl<Ix> From<Ix> for VertexIndex<Ix>
where
Ix: IndexType,
{
fn from(ix: Ix) -> Self {
VertexIndex(ix)
}
}
#[derive(Copy, Clone, Debug, Default, PartialEq, PartialOrd, Eq, Ord, Hash)]
pub struct Edge<Ix = DefaultIndexType> {
index: EdgeIndex<Ix>,
src: VertexIndex<Ix>,
dst: VertexIndex<Ix>,
}
impl<Ix> Edge<Ix>
where
Ix: IndexType,
{
#[inline]
pub fn new(index: EdgeIndex<Ix>, src: VertexIndex<Ix>, dst: VertexIndex<Ix>) -> Self {
Edge { index, src, dst }
}
#[inline]
pub fn index(&self) -> EdgeIndex<Ix> {
self.index
}
#[inline]
pub fn src(&self) -> VertexIndex<Ix> {
self.src
}
#[inline]
pub fn dst(&self) -> VertexIndex<Ix> {
self.dst
}
}
#[derive(Copy, Clone, Debug, Default, PartialEq, PartialOrd, Eq, Ord, Hash)]
pub struct EdgeIndex<Ix = DefaultIndexType>(pub Ix);
impl<Ix> EdgeIndex<Ix>
where
Ix: IndexType,
{
#[inline]
pub fn index(&self) -> Ix {
self.0
}
}
impl<Ix> From<Ix> for EdgeIndex<Ix>
where
Ix: IndexType,
{
fn from(ix: Ix) -> Self {
EdgeIndex(ix)
}
}
pub trait Children<'slf, Ix = DefaultIndexType>
where
Ix: IndexType,
{
fn children(&'slf self, node: NodeIndex) -> Box<dyn Iterator<Item=NodeIndex<Ix>> + 'slf>;
}
pub trait Keys<'slf, K, Ix = DefaultIndexType>
where
K: 'slf + KeyType,
Ix: IndexType,
{
fn keys(&'slf self) -> Box<dyn Iterator<Item=(NodeIndex<Ix>, &'slf K)> + 'slf>;
}
pub trait Values<'slf, V, Ix = DefaultIndexType>
where
V: 'slf + ValueType,
Ix: IndexType,
{
fn values(&'slf self) -> Box<dyn Iterator<Item=(NodeIndex<Ix>, &'slf V)> + 'slf>;
}
pub trait Vertices<'slf, Ix = DefaultIndexType>
where
Ix: IndexType,
{
fn vertices(&'slf self) -> Box<dyn Iterator<Item=VertexIndex<Ix>> + 'slf>;
}
pub trait Edges<'slf, Ix = DefaultIndexType>
where
Ix: IndexType,
{
fn edges(&'slf self) -> Box<dyn Iterator<Item=Edge<Ix>> + 'slf>;
}
pub trait Tgf {
fn to_tgf(&self) -> String;
}