jellyflow_runtime/runtime/utils/
connections.rs1use crate::runtime::lookups::{ConnectionSide, NodeGraphLookups};
2use jellyflow_core::core::{EdgeId, NodeId};
3
4pub fn get_outgoers(lookups: &NodeGraphLookups, node: NodeId) -> Vec<NodeId> {
6 let Some(conns) = lookups.connections_for_node_side(node, ConnectionSide::Source) else {
7 return Vec::new();
8 };
9 sorted_unique(conns.values().map(|c| c.target_node).collect())
10}
11
12pub fn get_incomers(lookups: &NodeGraphLookups, node: NodeId) -> Vec<NodeId> {
14 let Some(conns) = lookups.connections_for_node_side(node, ConnectionSide::Target) else {
15 return Vec::new();
16 };
17 sorted_unique(conns.values().map(|c| c.source_node).collect())
18}
19
20pub fn get_connected_edges(lookups: &NodeGraphLookups, node: NodeId) -> Vec<EdgeId> {
22 let Some(conns) = lookups.connections_for_node(node) else {
23 return Vec::new();
24 };
25 sorted_unique(conns.values().map(|c| c.edge).collect())
26}
27
28pub fn get_connected_edges_for_nodes(
33 lookups: &NodeGraphLookups,
34 nodes: impl IntoIterator<Item = NodeId>,
35) -> Vec<EdgeId> {
36 let mut out: Vec<EdgeId> = Vec::new();
37 for node in nodes {
38 out.extend(get_connected_edges(lookups, node));
39 }
40 sorted_unique(out)
41}
42
43fn sorted_unique<T: Ord>(mut items: Vec<T>) -> Vec<T> {
44 items.sort();
45 items.dedup();
46 items
47}