diff --git a/Cargo.toml b/Cargo.toml index 3f4951d..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" @@ -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/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`, diff --git a/src/map.rs b/src/map.rs index 8a057b6..91804a1 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) @@ -737,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). @@ -748,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). @@ -759,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, @@ -767,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 @@ -777,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, @@ -784,6 +790,21 @@ where self.inner.get_mut(key) } + /// 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)> + where + Q: ?Sized + Hash + Equivalent, + { + 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, 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)