1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
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
    }
}