From 5baea5a31ff2c3583b73c8dda4bb05e63e6766e1 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) --- Cargo.toml | 2 +- src/map.rs | 1 - src/map/entry.rs | 1 - src/set.rs | 1 - 4 files changed, 1 insertion(+), 4 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 3f4951d..b7dadca 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,7 +14,7 @@ rust-version = "1.63" bench = false [dependencies] -indexmap = { version = "2.11.0", default-features = false } +indexmap = { version = "2.11.1", default-features = false } arbitrary = { version = "1.0", optional = true, default-features = false } quickcheck = { version = "1.0", optional = true, default-features = false } diff --git a/src/map.rs b/src/map.rs index 8a057b6..34e9495 100644 --- a/src/map.rs +++ b/src/map.rs @@ -480,7 +480,6 @@ where /// Computes in **O(n)** time (average). pub fn insert_sorted_by(&mut self, key: K, value: V, cmp: F) -> (usize, Option) where - K: Ord, F: FnMut(&K, &V, &K, &V) -> Ordering, { self.inner.insert_sorted_by(key, value, cmp) diff --git a/src/map/entry.rs b/src/map/entry.rs index 759083e..08de6f3 100644 --- a/src/map/entry.rs +++ b/src/map/entry.rs @@ -338,7 +338,6 @@ impl<'a, K, V> VacantEntry<'a, K, V> { /// Computes in **O(n)** time (average). pub fn insert_sorted_by(self, value: V, cmp: F) -> (usize, &'a mut V) where - K: Ord, F: FnMut(&K, &V, &K, &V) -> Ordering, { self.inner.insert_sorted_by(value, cmp) diff --git a/src/set.rs b/src/set.rs index 0ff302a..b2d5967 100644 --- a/src/set.rs +++ b/src/set.rs @@ -419,7 +419,6 @@ where /// Computes in **O(n)** time (average). pub fn insert_sorted_by(&mut self, value: T, cmp: F) -> (usize, bool) where - T: Ord, F: FnMut(&T, &T) -> Ordering, { self.inner.insert_sorted_by(value, cmp) From 23a0264495e212e58b98d2055e4156e9707382f9 Mon Sep 17 00:00:00 2001 From: ya7010 Date: Sat, 6 Sep 2025 20:07:22 +0900 Subject: [PATCH 2/4] feat: add OrderMap::get_key_value_mut (cherry picked from commit cd4c1a53015aaf5e77241bddd70c523711fae090) --- src/map.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/map.rs b/src/map.rs index 34e9495..fb0e7cf 100644 --- a/src/map.rs +++ b/src/map.rs @@ -783,6 +783,17 @@ where self.inner.get_mut(key) } + /// 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, + { + self.inner.get_key_value_mut(key) + } + pub fn get_full_mut(&mut self, key: &Q) -> Option<(usize, &K, &mut V)> where Q: ?Sized + Hash + Equivalent, From 2bf5d71fe35a5752d07c46548f6e9f029cf496cf Mon Sep 17 00:00:00 2001 From: Josh Stone Date: Mon, 8 Sep 2025 15:46:37 -0700 Subject: [PATCH 3/4] Make `OrderMap::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 fb0e7cf..91804a1 100644 --- a/src/map.rs +++ b/src/map.rs @@ -736,7 +736,7 @@ where self.inner.contains_key(key) } - /// 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). @@ -747,7 +747,7 @@ where self.inner.get(key) } - /// 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). @@ -758,7 +758,10 @@ where self.inner.get_key_value(key) } - /// 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, @@ -766,7 +769,7 @@ where self.inner.get_full(key) } - /// 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 @@ -776,6 +779,10 @@ where self.inner.get_index_of(key) } + /// 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, @@ -783,8 +790,8 @@ where self.inner.get_mut(key) } - /// 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)> @@ -794,6 +801,10 @@ where self.inner.get_key_value_mut(key) } + /// 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 b0a15b29d39f2f1c7b08d6aa7bf4be5e29a2bb3f Mon Sep 17 00:00:00 2001 From: Josh Stone Date: Mon, 8 Sep 2025 17:31:57 -0700 Subject: [PATCH 4/4] Release 0.5.10 --- Cargo.toml | 2 +- RELEASES.md | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index b7dadca..1e5b6da 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "ordermap" edition = "2021" -version = "0.5.9" +version = "0.5.10" documentation = "https://docs.rs/ordermap/" repository = "https://github.com/indexmap-rs/ordermap" license = "Apache-2.0 OR MIT" diff --git a/RELEASES.md b/RELEASES.md index 6732bab..196251d 100644 --- a/RELEASES.md +++ b/RELEASES.md @@ -1,5 +1,10 @@ # Releases +## 0.5.10 (2025-09-08) + +- Added a `get_key_value_mut` method to `OrderMap`. +- Removed the unnecessary `Ord` bound on `insert_sorted_by` methods. + ## 0.5.9 (2025-08-22) - Added `insert_sorted_by` and `insert_sorted_by_key` methods to `OrderMap`,