Skip to main content

jellyflow_runtime/runtime/lookups/
mod.rs

1//! Canonical lookup maps for fast graph queries (XyFlow-style).
2//!
3//! XyFlow maintains several "lookup maps" alongside its canonical node/edge arrays:
4//! - `nodeLookup` (id -> internal node)
5//! - `edgeLookup` (id -> edge)
6//! - `connectionLookup` (node/handle -> connections)
7//!
8//! In Jellyflow the serialized document (`core::Graph`) is already map-based, but a first-class,
9//! headless-safe lookup surface is still useful for:
10//! - consistent adjacency queries (node/port -> incident edges),
11//! - avoiding repeated full scans in editor shells,
12//! - providing a stable substrate for B-layer tooling and middleware.
13
14mod apply;
15mod connections;
16mod parents;
17mod rebuild;
18mod types;
19
20use std::collections::HashMap;
21
22use jellyflow_core::core::{EdgeId, NodeId};
23
24pub use self::types::{
25    ConnectionLookupKey, ConnectionSide, EdgeLookupEntry, HandleConnection, NodeLookupEntry,
26};
27
28#[derive(Debug, Default)]
29pub struct NodeGraphLookups {
30    pub(crate) node_lookup: HashMap<NodeId, NodeLookupEntry>,
31    pub(crate) edge_lookup: HashMap<EdgeId, EdgeLookupEntry>,
32    pub(crate) connection_lookup: HashMap<ConnectionLookupKey, HashMap<EdgeId, HandleConnection>>,
33}
34
35impl NodeGraphLookups {
36    pub fn node_count(&self) -> usize {
37        self.node_lookup.len()
38    }
39
40    pub fn edge_count(&self) -> usize {
41        self.edge_lookup.len()
42    }
43
44    pub fn is_empty(&self) -> bool {
45        self.node_lookup.is_empty()
46            && self.edge_lookup.is_empty()
47            && self.connection_lookup.is_empty()
48    }
49}