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
71
72
//! Return an arc's weight.
//!
//! # Examples
//!
//! ```
//! use graaf::{
//! AddArcWeighted,
//! AdjacencyListWeighted,
//! ArcWeight,
//! Empty,
//! };
//!
//! let mut digraph = AdjacencyListWeighted::<usize>::empty(3);
//!
//! digraph.add_arc_weighted(0, 1, 2);
//! digraph.add_arc_weighted(0, 2, 3);
//! digraph.add_arc_weighted(1, 0, 4);
//! digraph.add_arc_weighted(2, 0, 7);
//! digraph.add_arc_weighted(2, 1, 8);
//!
//! assert_eq!(digraph.arc_weight(0, 0), None);
//! assert_eq!(digraph.arc_weight(0, 1), Some(&2));
//! assert_eq!(digraph.arc_weight(0, 2), Some(&3));
//! assert_eq!(digraph.arc_weight(1, 0), Some(&4));
//! assert_eq!(digraph.arc_weight(1, 1), None);
//! assert_eq!(digraph.arc_weight(2, 0), Some(&7));
//! assert_eq!(digraph.arc_weight(2, 1), Some(&8));
//! assert_eq!(digraph.arc_weight(2, 2), None);
//! ```
/// Arc weight
pub trait ArcWeight<Idx> {
/// The weight of an arc.
type Weight;
/// Return the weight of the arc if the arc exists in the digraph.
///
/// # Arguments
///
/// * `u`: The tail vertex.
/// * `v`: The head vertex.
///
/// # Examples
///
/// ```
/// use graaf::{
/// AddArcWeighted,
/// AdjacencyListWeighted,
/// ArcWeight,
/// Empty,
/// };
///
/// let mut digraph = AdjacencyListWeighted::<usize>::empty(3);
///
/// digraph.add_arc_weighted(0, 1, 2);
/// digraph.add_arc_weighted(0, 2, 3);
/// digraph.add_arc_weighted(1, 0, 4);
/// digraph.add_arc_weighted(2, 0, 7);
/// digraph.add_arc_weighted(2, 1, 8);
///
/// assert_eq!(digraph.arc_weight(0, 0), None);
/// assert_eq!(digraph.arc_weight(0, 1), Some(&2));
/// assert_eq!(digraph.arc_weight(0, 2), Some(&3));
/// assert_eq!(digraph.arc_weight(1, 0), Some(&4));
/// assert_eq!(digraph.arc_weight(1, 1), None);
/// assert_eq!(digraph.arc_weight(2, 0), Some(&7));
/// assert_eq!(digraph.arc_weight(2, 1), Some(&8));
/// assert_eq!(digraph.arc_weight(2, 2), None);
/// ```
#[must_use]
fn arc_weight(&self, u: Idx, v: Idx) -> Option<&Self::Weight>;
}