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
extern crate rand;
extern crate rand_seeder;
extern crate rand_xoshiro;
extern crate rustc_hash;
extern crate serde;
mod network;
mod algorithms;
mod flag;
mod node;
pub use algorithms::*;
pub use flag::Flag;
pub use network::{Network, Model, Weight};
pub use node::Node;
pub mod cn {
pub trait Iter<I>: DoubleEndedIterator<Item = I> + ExactSizeIterator<Item = I> {}
impl<T: DoubleEndedIterator + ExactSizeIterator + Iterator<Item = I>, I> Iter<I> for T {}
#[derive(Debug, PartialEq)]
pub enum Err {
NoSuchNode(usize),
BadWeight(f64),
LinkToSelf(usize),
BadProbability(f64),
NodeExists(usize),
}
impl std::fmt::Display for Err {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
let message = match self {
Err::NoSuchNode(i) => format!("No such node {}", i),
Err::BadWeight(w) => format!("Link weight cannot be {}", w),
Err::LinkToSelf(i) => format!("Attempted linking node {} to itself", i),
Err::BadProbability(p) => format!("Probability cannot be {}", p),
Err::NodeExists(i) => format!("Node {} already exists", i),
};
write!(f, "{}", message)
}
}
impl std::error::Error for Err {}
}