| 305 | roots.sort_by(|a, b| a.name.cmp(&b.name)); |
| 306 | |
| 307 | fn visit<'a>( |
| 308 | entry: &'a ViewEntry, |
| 309 | depth: usize, |
| 310 | children: &HashMap<&str, Vec<&'a ViewEntry>>, |
| 311 | visited: &mut HashSet<&'a str>, |
| 312 | visible: &HashSet<String>, |
| 313 | ordered: &mut Vec<(usize, &'a ViewEntry)>, |
| 314 | ) { |
| 315 | if !visited.insert(entry.name.as_str()) { |
| 316 | return; // cut parent cycles |
| 317 | } |
| 318 | if visible.contains(&entry.name) { |
| 319 | ordered.push((depth, entry)); |
| 320 | } |
| 321 | if let Some(kids) = children.get(entry.name.as_str()) { |
| 322 | for kid in kids { |
| 323 | visit(kid, depth + 1, children, visited, visible, ordered); |
| 324 | } |
| 325 | } |
| 326 | } |
| 327 | |
| 328 | let mut ordered = Vec::new(); |
| 329 | let mut visited: HashSet<&str> = HashSet::new(); |