MCPcopy Create free account
hub / github.com/GraphLite-AI/GraphLite / union_graphs

Method union_graphs

graphlite/src/storage/multi_graph.rs:120–162  ·  view source on GitHub ↗

Perform a graph union operation

(
        &self,
        graphs_to_union: Vec<GraphCache>,
    )

Source from the content-addressed store, hash-verified

118
119 /// Perform a graph union operation
120 pub fn union_graphs(
121 &self,
122 graphs_to_union: Vec<GraphCache>,
123 ) -> Result<GraphCache, StorageError> {
124 debug!("Performing graph union on {} graphs", graphs_to_union.len());
125
126 if graphs_to_union.is_empty() {
127 return Err(StorageError::InvalidOperation(
128 "Cannot union empty graph list".to_string(),
129 ));
130 }
131
132 // Start with the first graph
133 let mut result_graph = graphs_to_union[0].clone();
134
135 // Union with remaining graphs
136 for graph in graphs_to_union.iter().skip(1) {
137 // Manually union graphs by adding all nodes and edges
138 for node in graph.get_all_nodes() {
139 let has_node = result_graph
140 .has_node(&node.id)
141 .map_err(StorageError::Graph)?;
142 if !has_node {
143 result_graph
144 .add_node(node.clone())
145 .map_err(StorageError::Graph)?;
146 }
147 }
148 for edge in graph.get_all_edges() {
149 let has_edge = result_graph
150 .has_edge(&edge.id)
151 .map_err(StorageError::Graph)?;
152 if !has_edge {
153 result_graph
154 .add_edge(edge.clone())
155 .map_err(StorageError::Graph)?;
156 }
157 }
158 }
159
160 debug!("Successfully created union graph");
161 Ok(result_graph)
162 }
163
164 /// Clear all graphs
165 pub fn clear(&self) -> Result<(), StorageError> {

Callers 1

create_graph_unionMethod · 0.80

Calls 10

cloneMethod · 0.80
get_all_nodesMethod · 0.80
has_nodeMethod · 0.80
add_nodeMethod · 0.80
get_all_edgesMethod · 0.80
has_edgeMethod · 0.80
add_edgeMethod · 0.80
is_emptyMethod · 0.45
skipMethod · 0.45
iterMethod · 0.45

Tested by

no test coverage detected