Skip to content

Commit

Permalink
Merge pull request #5 from cuviper/sync
Browse files Browse the repository at this point in the history
Sync changes from indexmap and release 0.5.4
  • Loading branch information
cuviper authored Dec 1, 2024
2 parents 69945c2 + 76ab82e commit ce5c3e6
Show file tree
Hide file tree
Showing 9 changed files with 76 additions and 16 deletions.
11 changes: 11 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ jobs:
- uses: dtolnay/rust-toolchain@master
with:
toolchain: ${{ matrix.rust }}
- name: Downgrade dependencies
if: matrix.rust == '1.63.0'
run: |
cargo generate-lockfile
cargo update -p hashbrown --precise 0.15.0
- name: Tests
run: |
cargo build --verbose --features "${{ matrix.features }}"
Expand Down Expand Up @@ -81,6 +86,11 @@ jobs:
with:
toolchain: ${{ matrix.rust }}
target: ${{ matrix.target }}
- name: Downgrade dependencies
if: matrix.rust == '1.63.0'
run: |
cargo generate-lockfile
cargo update -p hashbrown --precise 0.15.0
- name: Tests
run: |
cargo build -vv --target=${{ matrix.target }} --no-default-features
Expand Down Expand Up @@ -119,6 +129,7 @@ jobs:
with:
tool: cargo-hack
- run: cargo +nightly hack generate-lockfile --remove-dev-deps -Z direct-minimal-versions
- run: cargo update -p hashbrown --precise 0.15.0
- name: Build (nightly)
run: cargo +nightly build --verbose --all-features
- name: Build (MSRV)
Expand Down
6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "ordermap"
edition = "2021"
version = "0.5.3"
version = "0.5.4"
documentation = "https://docs.rs/ordermap/"
repository = "https://github.com/indexmap-rs/ordermap"
license = "Apache-2.0 OR MIT"
Expand All @@ -14,13 +14,13 @@ rust-version = "1.63"
bench = false

[dependencies]
indexmap = { version = "2.5.0", default-features = false }
indexmap = { version = "2.7.0", default-features = false }

arbitrary = { version = "1.0", optional = true, default-features = false }
quickcheck = { version = "1.0", optional = true, default-features = false }
serde = { version = "1.0", optional = true, default-features = false }
borsh = { version = "1.2", optional = true, default-features = false }
rayon = { version = "1.5.3", optional = true }
rayon = { version = "1.9", optional = true }

[dev-dependencies]
itertools = "0.13"
Expand Down
7 changes: 7 additions & 0 deletions RELEASES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Releases

## 0.5.4 (2024-11-30)

- Added methods `Entry::insert_entry` and `VacantEntry::insert_entry`, returning
an `OccupiedEntry` after insertion.
- Updated the `indexmap` dependency to version 2.7.0, indirectly updating to
`hashbrown` version 0.15 as well.

## 0.5.3 (2024-08-30)

- Added an `insert_before` method to `OrderMap` and `OrderSet`, as an
Expand Down
14 changes: 7 additions & 7 deletions src/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -981,7 +981,7 @@ impl<K, V, S> OrderMap<K, V, S> {

/// Get a key-value pair by index
///
/// Valid indices are *0 <= index < self.len()*
/// Valid indices are `0 <= index < self.len()`.
///
/// Computes in **O(1)** time.
pub fn get_index(&self, index: usize) -> Option<(&K, &V)> {
Expand All @@ -990,7 +990,7 @@ impl<K, V, S> OrderMap<K, V, S> {

/// Get a key-value pair by index
///
/// Valid indices are *0 <= index < self.len()*
/// Valid indices are `0 <= index < self.len()`.
///
/// Computes in **O(1)** time.
pub fn get_index_mut(&mut self, index: usize) -> Option<(&K, &mut V)> {
Expand All @@ -999,7 +999,7 @@ impl<K, V, S> OrderMap<K, V, S> {

/// Get an entry in the map by index for in-place manipulation.
///
/// Valid indices are *0 <= index < self.len()*
/// Valid indices are `0 <= index < self.len()`.
///
/// Computes in **O(1)** time.
pub fn get_index_entry(&mut self, index: usize) -> Option<IndexedEntry<'_, K, V>> {
Expand All @@ -1008,7 +1008,7 @@ impl<K, V, S> OrderMap<K, V, S> {

/// Returns a slice of key-value pairs in the given range of indices.
///
/// Valid indices are *0 <= index < self.len()*
/// Valid indices are `0 <= index < self.len()`.
///
/// Computes in **O(1)** time.
pub fn get_range<R: RangeBounds<usize>>(&self, range: R) -> Option<&Slice<K, V>> {
Expand All @@ -1017,7 +1017,7 @@ impl<K, V, S> OrderMap<K, V, S> {

/// Returns a mutable slice of key-value pairs in the given range of indices.
///
/// Valid indices are *0 <= index < self.len()*
/// Valid indices are `0 <= index < self.len()`.
///
/// Computes in **O(1)** time.
pub fn get_range_mut<R: RangeBounds<usize>>(&mut self, range: R) -> Option<&mut Slice<K, V>> {
Expand Down Expand Up @@ -1070,7 +1070,7 @@ impl<K, V, S> OrderMap<K, V, S> {

/// Remove the key-value pair by index
///
/// Valid indices are *0 <= index < self.len()*
/// Valid indices are `0 <= index < self.len()`
///
/// **NOTE:** This is equivalent to [`IndexMap::shift_remove_index`], and
/// like [`Vec::remove`], the pair is removed by shifting all of the
Expand All @@ -1084,7 +1084,7 @@ impl<K, V, S> OrderMap<K, V, S> {

/// Remove the key-value pair by index
///
/// Valid indices are *0 <= index < self.len()*
/// Valid indices are `0 <= index < self.len()`.
///
/// Like [`Vec::swap_remove`], the pair is removed by swapping it with the
/// last element of the map and popping it off. **This perturbs
Expand Down
22 changes: 22 additions & 0 deletions src/map/entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,19 @@ impl<'a, K, V> Entry<'a, K, V> {
}
}

/// Sets the value of the entry (after inserting if vacant), and returns an `OccupiedEntry`.
///
/// Computes in **O(1)** time (amortized average).
pub fn insert_entry(self, value: V) -> OccupiedEntry<'a, K, V> {
match self {
Entry::Occupied(mut entry) => {
entry.insert(value);
entry
}
Entry::Vacant(entry) => entry.insert_entry(value),
}
}

/// Inserts the given default value in the entry if it is vacant and returns a mutable
/// reference to it. Otherwise a mutable reference to an already existent value is returned.
///
Expand Down Expand Up @@ -286,6 +299,15 @@ impl<'a, K, V> VacantEntry<'a, K, V> {
self.inner.insert(value)
}

/// Inserts the entry's key and the given value into the map, and returns an `OccupiedEntry`.
///
/// Computes in **O(1)** time (amortized average).
pub fn insert_entry(self, value: V) -> OccupiedEntry<'a, K, V> {
OccupiedEntry {
inner: self.inner.insert_entry(value),
}
}

/// Inserts the entry's key and the given value into the map at its ordered
/// position among sorted keys, and returns the new index and a mutable
/// reference to the value.
Expand Down
2 changes: 1 addition & 1 deletion src/map/mutable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ pub trait MutableKeys: private::Sealed {

/// Return mutable reference to key and value at an index.
///
/// Valid indices are *0 <= index < self.len()*
/// Valid indices are `0 <= index < self.len()`.
///
/// Computes in **O(1)** time.
fn get_index_mut2(&mut self, index: usize) -> Option<(&mut Self::Key, &mut Self::Value)>;
Expand Down
20 changes: 20 additions & 0 deletions src/map/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -538,6 +538,26 @@ fn into_values() {
assert!(values.contains(&'c'));
}

#[test]
fn drain_range() {
// Test the various heuristics of `erase_indices`
for range in [
0..0, // nothing erased
10..90, // reinsert the few kept (..10 and 90..)
80..90, // update the few to adjust (80..)
20..30, // sweep everything
] {
let mut vec = Vec::from_iter(0..100);
let mut map: IndexMap<i32, ()> = (0..100).map(|i| (i, ())).collect();
drop(vec.drain(range.clone()));
drop(map.drain(range));
assert!(vec.iter().eq(map.keys()));
for (i, x) in vec.iter().enumerate() {
assert_eq!(map.get_index_of(x), Some(i));
}
}
}

#[test]
#[cfg(feature = "std")]
fn from_array() {
Expand Down
8 changes: 4 additions & 4 deletions src/set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -917,7 +917,7 @@ impl<T, S> OrderSet<T, S> {

/// Get a value by index
///
/// Valid indices are *0 <= index < self.len()*
/// Valid indices are `0 <= index < self.len()`.
///
/// Computes in **O(1)** time.
pub fn get_index(&self, index: usize) -> Option<&T> {
Expand All @@ -926,7 +926,7 @@ impl<T, S> OrderSet<T, S> {

/// Returns a slice of values in the given range of indices.
///
/// Valid indices are *0 <= index < self.len()*
/// Valid indices are `0 <= index < self.len()`.
///
/// Computes in **O(1)** time.
pub fn get_range<R: RangeBounds<usize>>(&self, range: R) -> Option<&Slice<T>> {
Expand All @@ -949,7 +949,7 @@ impl<T, S> OrderSet<T, S> {

/// Remove the value by index
///
/// Valid indices are *0 <= index < self.len()*
/// Valid indices are `0 <= index < self.len()`
///
/// **NOTE:** This is equivalent to [`IndexSet::shift_remove_index`], and
/// like [`Vec::remove`], the value is removed by shifting all of the
Expand All @@ -963,7 +963,7 @@ impl<T, S> OrderSet<T, S> {

/// Remove the value by index
///
/// Valid indices are *0 <= index < self.len()*
/// Valid indices are `0 <= index < self.len()`.
///
/// Like [`Vec::swap_remove`], the value is removed by swapping it with the
/// last element of the set and popping it off. **This perturbs
Expand Down
2 changes: 1 addition & 1 deletion src/set/mutable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ pub trait MutableValues: private::Sealed {

/// Return mutable reference to the value at an index.
///
/// Valid indices are *0 <= index < self.len()*
/// Valid indices are `0 <= index < self.len()`.
///
/// Computes in **O(1)** time.
fn get_index_mut2(&mut self, index: usize) -> Option<&mut Self::Value>;
Expand Down

0 comments on commit ce5c3e6

Please sign in to comment.