MCPcopy Create free account
hub / github.com/MegEngine/MegFlow / global_res_impl

Function global_res_impl

flow-rs/src/config/insert.rs:14–78  ·  view source on GitHub ↗
(
    name: String,
    cfg: &'a mut interlayer::Config,
    global: &[String],
    visit: &mut HashMap<String, bool>,
)

Source from the content-addressed store, hash-verified

12use std::collections::{BTreeSet, HashMap};
13
14fn global_res_impl<'a>(
15 name: String,
16 cfg: &'a mut interlayer::Config,
17 global: &[String],
18 visit: &mut HashMap<String, bool>,
19) -> Vec<String> {
20 let graph = cfg.graphs.iter().find(|graph| graph.name == name).unwrap();
21 if visit[&graph.name] {
22 return graph.global_res.clone();
23 }
24 *visit.get_mut(&graph.name).unwrap() = true;
25
26 let mut capture = BTreeSet::new();
27 let mut tmp_mapping = HashMap::new();
28
29 for node in graph.nodes.values() {
30 for ty in &node.entity.ty {
31 if !visit.contains_key(ty) {
32 node.res
33 .iter()
34 .filter(|x| global.contains(x))
35 .for_each(|x| {
36 capture.insert(x.clone());
37 });
38 }
39 }
40 }
41 for name in graph
42 .nodes
43 .values()
44 .flat_map(|x| x.entity.ty.iter())
45 .filter(|x| visit.contains_key(*x))
46 .map(|x| x.to_owned())
47 .collect::<Vec<_>>()
48 {
49 global_res_impl(name.to_owned(), cfg, global, visit)
50 .into_iter()
51 .for_each(|x| {
52 capture.insert(x.clone());
53 tmp_mapping
54 .entry(name.to_owned())
55 .or_insert_with(BTreeSet::new)
56 .insert(x);
57 });
58 }
59
60 let graph = cfg
61 .graphs
62 .iter_mut()
63 .find(|graph| graph.name == name)
64 .unwrap();
65
66 for node in graph.nodes.values_mut() {
67 for name in &node.entity.ty {
68 if visit.contains_key(name) {
69 if let Some(graph) = tmp_mapping.get(name) {
70 node.res.append(&mut graph.iter().cloned().collect());
71 }

Callers 1

global_resFunction · 0.85

Calls 7

for_eachMethod · 0.80
filterMethod · 0.80
insertMethod · 0.80
appendMethod · 0.80
cloneMethod · 0.45
get_mutMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected