diff options
Diffstat (limited to 'graph/src/labelled/binary.rs')
-rw-r--r-- | graph/src/labelled/binary.rs | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/graph/src/labelled/binary.rs b/graph/src/labelled/binary.rs index e3e1943..201dda2 100644 --- a/graph/src/labelled/binary.rs +++ b/graph/src/labelled/binary.rs @@ -551,6 +551,22 @@ impl<'a, T: GraphLabel> BuilderMut for PLGBuilderMut<'a, T> { Ok(()) } + + #[inline] + fn set_label(&mut self, node_id: usize, label: Self::Label) -> Result<(), Error> { + if !self.graph.has_node(node_id) { + return Err(Error::IndexOutOfBounds(node_id, self.nodes_len())); + } + + // node_id is now guaranteed to be valid. + + self.graph.nodes.get_mut(node_id).unwrap().label = label; + + self.graph.label_index_map.remove(&label); + self.graph.label_index_map.insert(label, node_id); + + Ok(()) + } } #[cfg(test)] |