Skip to content

Commit 858b347

Browse files
authored
Merge pull request #13 from cuviper/release-0.1.6
Release 0.1.6
2 parents 2a9ecd4 + 799bf5c commit 858b347

File tree

5 files changed

+37
-8
lines changed

5 files changed

+37
-8
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22
name = "ringmap"
33
edition = "2021"
4-
version = "0.1.5"
4+
version = "0.1.6"
55
documentation = "https://docs.rs/ringmap/"
66
repository = "https://github.com/indexmap-rs/ringmap"
77
license = "Apache-2.0 OR MIT"

RELEASES.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# Releases
22

3+
## 0.1.6 (2025-09-08)
4+
5+
- Added a `get_key_value_mut` method to `RingMap`.
6+
- Removed the unnecessary `Ord` bound on `insert_sorted_by` methods.
7+
38
## 0.1.5 (2025-08-22)
49

510
- Added `insert_sorted_by` and `insert_sorted_by_key` methods to `RingMap`,

src/map.rs

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -542,7 +542,6 @@ where
542542
/// Computes in **O(n)** time (average).
543543
pub fn insert_sorted_by<F>(&mut self, key: K, value: V, mut cmp: F) -> (usize, Option<V>)
544544
where
545-
K: Ord,
546545
F: FnMut(&K, &V, &K, &V) -> Ordering,
547546
{
548547
let (Ok(i) | Err(i)) = self.binary_search_by(|k, v| cmp(k, v, &key, &value));
@@ -864,7 +863,7 @@ where
864863
self.get_index_of(key).is_some()
865864
}
866865

867-
/// Return a reference to the value stored for `key`, if it is present,
866+
/// Return a reference to the stored value for `key`, if it is present,
868867
/// else `None`.
869868
///
870869
/// Computes in **O(1)** time (average).
@@ -880,7 +879,7 @@ where
880879
}
881880
}
882881

883-
/// Return references to the key-value pair stored for `key`,
882+
/// Return references to the stored key-value pair for the lookup `key`,
884883
/// if it is present, else `None`.
885884
///
886885
/// Computes in **O(1)** time (average).
@@ -896,7 +895,10 @@ where
896895
}
897896
}
898897

899-
/// Return item index, key and value
898+
/// Return the index with references to the stored key-value pair for the
899+
/// lookup `key`, if it is present, else `None`.
900+
///
901+
/// Computes in **O(1)** time (average).
900902
pub fn get_full<Q>(&self, key: &Q) -> Option<(usize, &K, &V)>
901903
where
902904
Q: ?Sized + Hash + Equivalent<K>,
@@ -909,7 +911,7 @@ where
909911
}
910912
}
911913

912-
/// Return item index, if it exists in the map
914+
/// Return the item index for `key`, if it is present, else `None`.
913915
///
914916
/// Computes in **O(1)** time (average).
915917
pub fn get_index_of<Q>(&self, key: &Q) -> Option<usize>
@@ -926,6 +928,10 @@ where
926928
}
927929
}
928930

931+
/// Return a mutable reference to the stored value for `key`,
932+
/// if it is present, else `None`.
933+
///
934+
/// Computes in **O(1)** time (average).
929935
pub fn get_mut<Q>(&mut self, key: &Q) -> Option<&mut V>
930936
where
931937
Q: ?Sized + Hash + Equivalent<K>,
@@ -938,6 +944,26 @@ where
938944
}
939945
}
940946

947+
/// Return a reference and mutable references to the stored key-value pair
948+
/// for the lookup `key`, if it is present, else `None`.
949+
///
950+
/// Computes in **O(1)** time (average).
951+
pub fn get_key_value_mut<Q>(&mut self, key: &Q) -> Option<(&K, &mut V)>
952+
where
953+
Q: ?Sized + Hash + Equivalent<K>,
954+
{
955+
if let Some(i) = self.get_index_of(key) {
956+
let entry = &mut self.as_entries_mut()[i];
957+
Some((&entry.key, &mut entry.value))
958+
} else {
959+
None
960+
}
961+
}
962+
963+
/// Return the index with a reference and mutable reference to the stored
964+
/// key-value pair for the lookup `key`, if it is present, else `None`.
965+
///
966+
/// Computes in **O(1)** time (average).
941967
pub fn get_full_mut<Q>(&mut self, key: &Q) -> Option<(usize, &K, &mut V)>
942968
where
943969
Q: ?Sized + Hash + Equivalent<K>,

src/map/core/entry.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -469,7 +469,6 @@ impl<'a, K, V> VacantEntry<'a, K, V> {
469469
/// Computes in **O(n)** time (average).
470470
pub fn insert_sorted_by<F>(self, value: V, mut cmp: F) -> (usize, &'a mut V)
471471
where
472-
K: Ord,
473472
F: FnMut(&K, &V, &K, &V) -> Ordering,
474473
{
475474
let (Ok(i) | Err(i)) = self

src/set.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -464,7 +464,6 @@ where
464464
/// Computes in **O(n)** time (average).
465465
pub fn insert_sorted_by<F>(&mut self, value: T, mut cmp: F) -> (usize, bool)
466466
where
467-
T: Ord,
468467
F: FnMut(&T, &T) -> Ordering,
469468
{
470469
let (index, existing) = self

0 commit comments

Comments
 (0)