Perform a graph union operation
(
&self,
graphs_to_union: Vec<GraphCache>,
)
| 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> { |
no test coverage detected