Skip to main content

root

Function root 

Source
pub fn root<F>(start: &str, parent: F) -> String
where F: FnMut(&str) -> Option<String>,
Expand description

Follow parent from start until a node has none, and return that node. If the walk returns to a node it has passed, it stops there, so a cycle cannot make it run forever.

ยงExample

use publet_algorithms::graph::root;

// Each version names the one it replaces.
let replaces = |v: &str| match v {
    "v3" => Some("v2".to_string()),
    "v2" => Some("v1".to_string()),
    _ => None,
};
assert_eq!(root("v3", replaces), "v1");