From 8951fb61c13ffdb461a610b39146212355c897e9 Mon Sep 17 00:00:00 2001 From: Andrew Baldwin Date: Mon, 8 Sep 2025 01:28:12 -0700 Subject: [PATCH 1/4] Remove Ord trait bound on insert_sorted_by functions. (cherry picked from commit 2be44878bee3941d7df896ff49cb7c176f06da8e) --- src/map.rs | 1 - src/map/core/entry.rs | 1 - src/set.rs | 1 - 3 files changed, 3 deletions(-) diff --git a/src/map.rs b/src/map.rs index 6e6a040..e73118a 100644 --- a/src/map.rs +++ b/src/map.rs @@ -542,7 +542,6 @@ where /// Computes in **O(n)** time (average). pub fn insert_sorted_by(&mut self, key: K, value: V, mut cmp: F) -> (usize, Option) where - K: Ord, F: FnMut(&K, &V, &K, &V) -> Ordering, { let (Ok(i) | Err(i)) = self.binary_search_by(|k, v| cmp(k, v, &key, &value)); diff --git a/src/map/core/entry.rs b/src/map/core/entry.rs index 1efd186..27f9435 100644 --- a/src/map/core/entry.rs +++ b/src/map/core/entry.rs @@ -469,7 +469,6 @@ impl<'a, K, V> VacantEntry<'a, K, V> { /// Computes in **O(n)** time (average). pub fn insert_sorted_by(self, value: V, mut cmp: F) -> (usize, &'a mut V) where - K: Ord, F: FnMut(&K, &V, &K, &V) -> Ordering, { let (Ok(i) | Err(i)) = self diff --git a/src/set.rs b/src/set.rs index 317f45f..3cc4943 100644 --- a/src/set.rs +++ b/src/set.rs @@ -464,7 +464,6 @@ where /// Computes in **O(n)** time (average). pub fn insert_sorted_by(&mut self, value: T, mut cmp: F) -> (usize, bool) where - T: Ord, F: FnMut(&T, &T) -> Ordering, { let (index, existing) = self From 52e3464e39f4362ee5bc04c16ed5276ad51e3eab Mon Sep 17 00:00:00 2001 From: ya7010 Date: Sat, 6 Sep 2025 20:07:22 +0900 Subject: [PATCH 2/4] feat: add RingMap::get_key_value_mut (cherry picked from commit cd4c1a53015aaf5e77241bddd70c523711fae090) --- src/map.rs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/map.rs b/src/map.rs index e73118a..66263d9 100644 --- a/src/map.rs +++ b/src/map.rs @@ -937,6 +937,22 @@ where } } + /// Return references to the key-value pair stored for `key`, + /// if it is present, else `None`. + /// + /// Computes in **O(1)** time (average). + pub fn get_key_value_mut(&mut self, key: &Q) -> Option<(&K, &mut V)> + where + Q: ?Sized + Hash + Equivalent, + { + if let Some(i) = self.get_index_of(key) { + let entry = &mut self.as_entries_mut()[i]; + Some((&entry.key, &mut entry.value)) + } else { + None + } + } + pub fn get_full_mut(&mut self, key: &Q) -> Option<(usize, &K, &mut V)> where Q: ?Sized + Hash + Equivalent, From 5732dc6f59e32a03721fe646d7a134a00734a321 Mon Sep 17 00:00:00 2001 From: Josh Stone Date: Mon, 8 Sep 2025 15:46:37 -0700 Subject: [PATCH 3/4] Make `RingMap::get_*` docs more consistent (cherry picked from commit 01f3ef0d4723ef297d6b27aa891b23c6a11f751b) --- src/map.rs | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/src/map.rs b/src/map.rs index 66263d9..ef2ee39 100644 --- a/src/map.rs +++ b/src/map.rs @@ -863,7 +863,7 @@ where self.get_index_of(key).is_some() } - /// Return a reference to the value stored for `key`, if it is present, + /// Return a reference to the stored value for `key`, if it is present, /// else `None`. /// /// Computes in **O(1)** time (average). @@ -879,7 +879,7 @@ where } } - /// Return references to the key-value pair stored for `key`, + /// Return references to the stored key-value pair for the lookup `key`, /// if it is present, else `None`. /// /// Computes in **O(1)** time (average). @@ -895,7 +895,10 @@ where } } - /// Return item index, key and value + /// Return the index with references to the stored key-value pair for the + /// lookup `key`, if it is present, else `None`. + /// + /// Computes in **O(1)** time (average). pub fn get_full(&self, key: &Q) -> Option<(usize, &K, &V)> where Q: ?Sized + Hash + Equivalent, @@ -908,7 +911,7 @@ where } } - /// Return item index, if it exists in the map + /// Return the item index for `key`, if it is present, else `None`. /// /// Computes in **O(1)** time (average). pub fn get_index_of(&self, key: &Q) -> Option @@ -925,6 +928,10 @@ where } } + /// Return a mutable reference to the stored value for `key`, + /// if it is present, else `None`. + /// + /// Computes in **O(1)** time (average). pub fn get_mut(&mut self, key: &Q) -> Option<&mut V> where Q: ?Sized + Hash + Equivalent, @@ -937,8 +944,8 @@ where } } - /// Return references to the key-value pair stored for `key`, - /// if it is present, else `None`. + /// Return a reference and mutable references to the stored key-value pair + /// for the lookup `key`, if it is present, else `None`. /// /// Computes in **O(1)** time (average). pub fn get_key_value_mut(&mut self, key: &Q) -> Option<(&K, &mut V)> @@ -953,6 +960,10 @@ where } } + /// Return the index with a reference and mutable reference to the stored + /// key-value pair for the lookup `key`, if it is present, else `None`. + /// + /// Computes in **O(1)** time (average). pub fn get_full_mut(&mut self, key: &Q) -> Option<(usize, &K, &mut V)> where Q: ?Sized + Hash + Equivalent, From 799bf5c21ca74ab995300507ae0a4255616c6963 Mon Sep 17 00:00:00 2001 From: Josh Stone Date: Mon, 8 Sep 2025 17:25:02 -0700 Subject: [PATCH 4/4] Release 0.1.6 --- Cargo.toml | 2 +- RELEASES.md | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index b21df25..13d42a2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "ringmap" edition = "2021" -version = "0.1.5" +version = "0.1.6" documentation = "https://docs.rs/ringmap/" repository = "https://github.com/indexmap-rs/ringmap" license = "Apache-2.0 OR MIT" diff --git a/RELEASES.md b/RELEASES.md index 2b8e2b4..e97f667 100644 --- a/RELEASES.md +++ b/RELEASES.md @@ -1,5 +1,10 @@ # Releases +## 0.1.6 (2025-09-08) + +- Added a `get_key_value_mut` method to `RingMap`. +- Removed the unnecessary `Ord` bound on `insert_sorted_by` methods. + ## 0.1.5 (2025-08-22) - Added `insert_sorted_by` and `insert_sorted_by_key` methods to `RingMap`,