Get a mutable reference to the value for a key. # Arguments `key` - The key to look up # Returns A mutable reference to the value if the key exists, `None` otherwise. # Examples ``` use bplustree::BPlusTreeMap; let mut tree = BPlusTreeMap::new(16).unwrap(); tree.insert(1, "one"); if let Some(value) = tree.get_mut(&1) { value = "ONE"; } assert_eq!(tree.get(&1), Some(&"ONE")); ```
(&mut self, key: &K)
| 136 | /// assert_eq!(tree.get(&1), Some(&"ONE")); |
| 137 | /// ``` |
| 138 | pub fn get_mut(&mut self, key: &K) -> Option<&mut V> { |
| 139 | let (leaf_id, index, matched) = self.find_leaf_for_key_with_match(key)?; |
| 140 | if !matched { |
| 141 | return None; |
| 142 | } |
| 143 | self.get_leaf_mut(leaf_id)?.get_value_mut(index) |
| 144 | } |
| 145 | |
| 146 | /// Try to get a value, returning detailed error context on failure. |
| 147 | /// |