[][src]Function rustasim::network::routing::route_id

pub fn route_id(network: &Network, source_id: usize) -> HashMap<usize, usize>

Given network a map of nodes and their neighbours, find the routing table for the given id

This assumes all the edges have the same weight and breaks ties arbitrarely. Eventually this probably should return the cost of the path and alternatives for equal-cost multi-path.

The route to self can return arbitrary values, but will exist. Do not rely on it being 0.

Examples

use std::collections::HashMap;
use rustasim::network::routing::route_id;

// +-------+
// |       |
// 1 - 2 - 3 - 4
let mut network = HashMap::new();
network.insert(1, vec![2, 3]);
network.insert(2, vec![1, 3]);
network.insert(3, vec![1, 2, 4]);
network.insert(4, vec![3]);

// route from 1
let route = route_id(&network, 1);
assert_eq!(route[&2], 2);
assert_eq!(route[&3], 3);
assert_eq!(route[&4], 3);

// route from 2
let route = route_id(&network, 2);
assert_eq!(route[&1], 1);
assert_eq!(route[&3], 3);
assert_eq!(route[&4], 3);