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

Method new

flow-rs/src/node/shared.rs:47–111  ·  view source on GitHub ↗
(
        local_key: u64,
        rx: ReceiverT<SharedConns>,
        cfg: &crate::config::interlayer::Node,
        graphs: &crate::config::interlayer::Config,
    )

Source from the content-addressed store, hash-verified

45
46impl Shared {
47 pub fn new(
48 local_key: u64,
49 rx: ReceiverT<SharedConns>,
50 cfg: &crate::config::interlayer::Node,
51 graphs: &crate::config::interlayer::Config,
52 ) -> Result<Shared> {
53 let mut nodes = load_static(local_key, cfg)?;
54 let mut inputs = HashMap::new();
55 let mut outputs = HashMap::new();
56
57 let find_cap =
58 |port| {
59 let mut cap = 0usize;
60 for graph in graphs
61 .graphs
62 .iter()
63 .filter(|graph| !graph.nodes.keys().any(|node| node == &cfg.entity.name))
64 {
65 cap =
66 std::cmp::max(
67 cap,
68 graph
69 .connections
70 .values()
71 .map(|conn| {
72 if conn.rx.iter().chain(conn.tx.iter()).any(|p| {
73 p.node_name == cfg.entity.name && &p.port_name == port
74 }) {
75 conn.cap
76 } else {
77 0
78 }
79 })
80 .max()
81 .expect("unused port in shared nodes"),
82 );
83 }
84 cap
85 };
86
87 for input in &cfg.inputs {
88 let cap = find_cap(input);
89 let chan = ChannelStorage::bound(cap);
90 for node in &mut nodes {
91 node.set_port(input.as_str(), None, &chan);
92 }
93 inputs.insert(input.clone(), Arc::new(chan.sender()));
94 }
95
96 for output in &cfg.outputs {
97 let cap = find_cap(output);
98 let chan = ChannelStorage::bound(cap);
99 for node in &mut nodes {
100 node.set_port(output.as_str(), None, &chan);
101 }
102 outputs.insert(output.clone(), chan.receiver());
103 }
104

Callers

nothing calls this directly

Calls 12

load_staticFunction · 0.85
filterMethod · 0.80
chainMethod · 0.80
insertMethod · 0.80
senderMethod · 0.80
receiverMethod · 0.80
firstMethod · 0.80
inputsFunction · 0.70
outputsFunction · 0.70
keysMethod · 0.45
set_portMethod · 0.45
cloneMethod · 0.45

Tested by

no test coverage detected