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
/*
 * Copyright (c) 2020 Frank Fischer <frank-fischer@shadow-soft.de>
 *
 * This program is free software: you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation, either version 3 of the
 * License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see  <http://www.gnu.org/licenses/>
 */

///! Reference graph traits.
use super::{Directed, GraphSize, IndexGraph, Undirected};

/// A reference to a basic graph.
///
/// This trait contains methods with a unrestricted lifetime for `self`.
pub trait GraphSizeRef<'a>: GraphSize<'a> {
    fn nodes(&self) -> Self::NodeIter;
    fn edges(&self) -> Self::EdgeIter;
}

/// A reference to an undirected graph.
///
/// This trait contains methods with a unrestricted lifetime for `self`.
pub trait UndirectedRef<'a>: Undirected<'a> + GraphSizeRef<'a> {
    fn enodes(&self, e: Self::Edge) -> (Self::Node, Self::Node);

    fn first_neigh(&self, u: Self::Node) -> Option<Self::Neigh>;
    fn next_neigh(&self, it: Self::Neigh) -> Option<Self::Neigh>;
    fn get_neigh(&self, it: &Self::Neigh) -> (Self::Edge, Self::Node);
}

/// A reference to a digraph.
///
/// This trait contains methods with a unrestricted lifetime for `self`.
pub trait DirectedRef<'a>: Directed<'a> + UndirectedRef<'a> {
    fn src(&self, e: Self::Edge) -> Self::Node;
    fn snk(&self, e: Self::Edge) -> Self::Node;

    fn first_out(&self, u: Self::Node) -> Option<Self::OutEdge>;
    fn next_out(&self, it: Self::OutEdge) -> Option<Self::OutEdge>;
    fn get_out(&self, it: &Self::OutEdge) -> (Self::Edge, Self::Node);

    fn first_in(&self, u: Self::Node) -> Option<Self::InEdge>;
    fn next_in(&self, it: Self::InEdge) -> Option<Self::InEdge>;
    fn get_in(&self, it: &Self::InEdge) -> (Self::Edge, Self::Node);

    fn first_incident(&self, u: Self::Node) -> Option<Self::IncidentEdge>;
    fn next_incident(&self, it: Self::IncidentEdge) -> Option<Self::IncidentEdge>;
    fn get_incident(&self, it: &Self::IncidentEdge) -> (Self::DirectedEdge, Self::Node);
}

/// A reference to an indexed graph.
///
/// This trait contains methods with a unrestricted lifetime for `self`.
pub trait IndexGraphRef<'a>: IndexGraph<'a> + UndirectedRef<'a> {
    fn id2node(&self, id: usize) -> Self::Node;
    fn id2edge(&self, id: usize) -> Self::Edge;
}