Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
5 changes: 5 additions & 0 deletions RELEASES.md
Original file line number Diff line number Diff line change
@@ -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`,
Expand Down
36 changes: 31 additions & 5 deletions src/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -542,7 +542,6 @@ where
/// Computes in **O(n)** time (average).
pub fn insert_sorted_by<F>(&mut self, key: K, value: V, mut cmp: F) -> (usize, Option<V>)
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));
Expand Down Expand Up @@ -864,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).
Expand All @@ -880,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).
Expand All @@ -896,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<Q>(&self, key: &Q) -> Option<(usize, &K, &V)>
where
Q: ?Sized + Hash + Equivalent<K>,
Expand All @@ -909,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<Q>(&self, key: &Q) -> Option<usize>
Expand All @@ -926,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<Q>(&mut self, key: &Q) -> Option<&mut V>
where
Q: ?Sized + Hash + Equivalent<K>,
Expand All @@ -938,6 +944,26 @@ where
}
}

/// 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<Q>(&mut self, key: &Q) -> Option<(&K, &mut V)>
where
Q: ?Sized + Hash + Equivalent<K>,
{
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
}
}

/// 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<Q>(&mut self, key: &Q) -> Option<(usize, &K, &mut V)>
where
Q: ?Sized + Hash + Equivalent<K>,
Expand Down
1 change: 0 additions & 1 deletion src/map/core/entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,6 @@ impl<'a, K, V> VacantEntry<'a, K, V> {
/// Computes in **O(n)** time (average).
pub fn insert_sorted_by<F>(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
Expand Down
1 change: 0 additions & 1 deletion src/set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,6 @@ where
/// Computes in **O(n)** time (average).
pub fn insert_sorted_by<F>(&mut self, value: T, mut cmp: F) -> (usize, bool)
where
T: Ord,
F: FnMut(&T, &T) -> Ordering,
{
let (index, existing) = self
Expand Down