From b078e13cb6c6deb8ca31540b2fba2f64b7eb3e2e Mon Sep 17 00:00:00 2001 From: James Pace Date: Sat, 20 Jun 2026 20:12:09 -0400 Subject: [PATCH] Allow setting value of a node without touching its connections. --- src/lib.rs | 10 ++++++++++ src/node.rs | 4 ++++ 2 files changed, 14 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index ee482f9..3a25c9b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -51,6 +51,16 @@ impl Graph { Ok(new_node_key) } + /// Replace the value of `key` with value `value`. + /// `key` must already exist in the graph, and no connections will be modified. + pub fn replace_value_of(&mut self, key: &Key, value: NodeValueT) -> Result<(), GraphError> { + if let Some(node) = self.nodes.get_mut(*key) { + node.set_value(value); + return Ok(()); + } + return Err(GraphError::from_msg("Can't set value of invalid key.")); + } + /// Get the value of key `key` if the key is valid. pub fn value_of(&self, key: &Key) -> Result { if key >= &self.nodes.len() { diff --git a/src/node.rs b/src/node.rs index d5cddb6..73f23a0 100644 --- a/src/node.rs +++ b/src/node.rs @@ -46,4 +46,8 @@ impl Node { pub fn value(&self) -> NodeValueT { self.value.clone() } + + pub fn set_value(&mut self, value: NodeValueT) { + self.value = value; + } }