Add a node to the graph
(&mut self, node: Node)
| 52 | |
| 53 | /// Add a node to the graph |
| 54 | pub fn add_node(&mut self, node: Node) -> Result<(), GraphError> { |
| 55 | // Check if node already exists |
| 56 | if self.nodes.contains_key(&node.id) { |
| 57 | return Err(GraphError::NodeAlreadyExists(node.id)); |
| 58 | } |
| 59 | |
| 60 | // Update label indices |
| 61 | for label in &node.labels { |
| 62 | self.node_labels |
| 63 | .entry(label.clone()) |
| 64 | .or_default() |
| 65 | .push(node.id.clone()); |
| 66 | } |
| 67 | |
| 68 | // Initialize adjacency lists for this node |
| 69 | self.adjacency_out.insert(node.id.clone(), Vec::new()); |
| 70 | self.adjacency_in.insert(node.id.clone(), Vec::new()); |
| 71 | |
| 72 | // Store the node |
| 73 | self.nodes.insert(node.id.clone(), node); |
| 74 | |
| 75 | Ok(()) |
| 76 | } |
| 77 | |
| 78 | /// Add an edge to the graph |
| 79 | pub fn add_edge(&mut self, edge: Edge) -> Result<(), GraphError> { |
no test coverage detected