Struct pathfinder::Network
source · Fields§
§hash_map: [Option<T>; 666]
Implementations§
source§impl Network<Node>
impl Network<Node>
sourcepub fn path<'a>(&'a self, a: &str, b: &str) -> Vec<Node>
pub fn path<'a>(&'a self, a: &str, b: &str) -> Vec<Node>
Calculates the path from node A to node B.
Examples
use pathfinder::{Coordinate, Network, Node};
let b = Node::new("B", Coordinate::new(20, 20));
let mut a = Node::new("A", Coordinate::new(0, 0));
a.link(&b);
let path = Network::new(vec![a, b]).path("A", "B");
assert_eq!(path, vec!(b, a));
use pathfinder::{Coordinate, Network, Node};
let nodes = Node::from_list(&[(0, 0), (10, 10), (20, 20), (30, 30)]);
let mut nodes = Node::linked_list(nodes);
let path = Network::new(nodes).path("D", "A");
assert_eq!(path.len(), 4);
for i in 0..path.len() {
assert_eq!(path[i].geo.x, i as i16 * 10);
}
sourcepub fn get(&self, element: &str) -> Option<Node>
pub fn get(&self, element: &str) -> Option<Node>
Returns if the given hash exists in the network.
Examples
use pathfinder::{Coordinate, Network, Node};
let nodes = Node::from_list(&[(0, 0), (10, 10), (20, 20), (30, 30), (40, 40)]);
let network = Network::new(nodes.clone());
assert!(network.get("A").is_some());
assert!(network.get("E").is_some());
assert!(network.get("F").is_none());