Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Document equivalence of move_index/swap_indices
  • Loading branch information
cuviper committed Feb 11, 2024
1 parent 3264695 commit 209e3e1
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/map/core/entry.rs
Expand Up @@ -241,6 +241,9 @@ impl<'a, K, V> OccupiedEntry<'a, K, V> {
/// Moves the position of the entry to a new index
/// by shifting all other entries in-between.
///
/// This is equivalent to [`IndexMap::move_index`][`crate::IndexMap::move_index`]
/// coming `from` the current [`.index()`][Self::index].
///
/// * If `self.index() < to`, the other pairs will shift down while the targeted pair moves up.
/// * If `self.index() > to`, the other pairs will shift up while the targeted pair moves down.
///
Expand All @@ -254,6 +257,9 @@ impl<'a, K, V> OccupiedEntry<'a, K, V> {

/// Swaps the position of entry with another.
///
/// This is equivalent to [`IndexMap::swap_indices`][`crate::IndexMap::swap_indices`]
/// with the current [`.index()`][Self::index] as one of the two being swapped.
///
/// ***Panics*** if the `other` index is out of bounds.
///
/// Computes in **O(1)** time (average).
Expand Down Expand Up @@ -420,6 +426,9 @@ impl<'a, K, V> IndexedEntry<'a, K, V> {
/// Moves the position of the entry to a new index
/// by shifting all other entries in-between.
///
/// This is equivalent to [`IndexMap::move_index`][`crate::IndexMap::move_index`]
/// coming `from` the current [`.index()`][Self::index].
///
/// * If `self.index() < to`, the other pairs will shift down while the targeted pair moves up.
/// * If `self.index() > to`, the other pairs will shift up while the targeted pair moves down.
///
Expand All @@ -432,6 +441,9 @@ impl<'a, K, V> IndexedEntry<'a, K, V> {

/// Swaps the position of entry with another.
///
/// This is equivalent to [`IndexMap::swap_indices`][`crate::IndexMap::swap_indices`]
/// with the current [`.index()`][Self::index] as one of the two being swapped.
///
/// ***Panics*** if the `other` index is out of bounds.
///
/// Computes in **O(1)** time (average).
Expand Down
6 changes: 6 additions & 0 deletions src/map/core/raw_entry_v1.rs
Expand Up @@ -543,6 +543,9 @@ impl<'a, K, V, S> RawOccupiedEntryMut<'a, K, V, S> {
/// Moves the position of the entry to a new index
/// by shifting all other entries in-between.
///
/// This is equivalent to [`IndexMap::move_index`]
/// coming `from` the current [`.index()`][Self::index].
///
/// * If `self.index() < to`, the other pairs will shift down while the targeted pair moves up.
/// * If `self.index() > to`, the other pairs will shift up while the targeted pair moves down.
///
Expand All @@ -556,6 +559,9 @@ impl<'a, K, V, S> RawOccupiedEntryMut<'a, K, V, S> {

/// Swaps the position of entry with another.
///
/// This is equivalent to [`IndexMap::swap_indices`]
/// with the current [`.index()`][Self::index] as one of the two being swapped.
///
/// ***Panics*** if the `other` index is out of bounds.
///
/// Computes in **O(1)** time (average).
Expand Down

0 comments on commit 209e3e1

Please sign in to comment.