use std::cmp::{max, min};
use std::ops::Range;
use crate::NodeIndex;
mod simple;
pub trait Edge {
fn from(&self) -> NodeIndex;
fn goto(&self) -> NodeIndex;
fn direction(&self) -> EdgeDirection;
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum EdgeDirection {
TwoWay,
Forward,
Reverse,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct UndirectedEdge {
pub from: usize,
pub goto: usize,
}
impl UndirectedEdge {
pub fn max_index(&self) -> usize {
max(self.from, self.goto)
}
pub fn min_index(&self) -> usize {
min(self.from, self.goto)
}
pub fn as_range(&self) -> Range<usize> {
self.min_index()..self.max_index()
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct DirectedEdge {
pub from: usize,
pub goto: usize,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct PureEdge<M> {
from: NodeIndex,
goto: NodeIndex,
direction: EdgeDirection,
metadata: M,
}
impl<M> Edge for PureEdge<M> {
fn from(&self) -> NodeIndex {
self.from
}
fn goto(&self) -> NodeIndex {
self.goto
}
fn direction(&self) -> EdgeDirection {
self.direction
}
}