Skip to content

Commit

Permalink
Re-wrap the binary search docs
Browse files Browse the repository at this point in the history
  • Loading branch information
cuviper committed Oct 31, 2023
1 parent eec4c43 commit 7326a6e
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 36 deletions.
17 changes: 8 additions & 9 deletions src/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -796,12 +796,11 @@ where

/// Search over a sorted map for a key.
///
/// Returns the position where that key is present, or the position where it can be inserted to maintain the sort.
/// See [`slice::binary_search`] for more details.
/// Returns the position where that key is present, or the position where it can be inserted to
/// maintain the sort. See [`slice::binary_search`] for more details.
///
/// Computes in **O(log(n))** time,
/// which is notably less scalable than looking the key up using [`get_index_of`],
/// but this can also position missing keys.
/// Computes in **O(log(n))** time, which is notably less scalable than looking the key up
/// using [`get_index_of`][IndexMap::get_index_of], but this can also position missing keys.
pub fn binary_search_keys(&self, x: &K) -> Result<usize, usize>
where
K: Ord,
Expand All @@ -811,8 +810,8 @@ where

/// Search over a sorted map with a comparator function.
///
/// Returns the position where that value is present, or the position where it can be inserted to maintain the sort.
/// See [`slice::binary_search_by`] for more details.
/// Returns the position where that value is present, or the position where it can be inserted
/// to maintain the sort. See [`slice::binary_search_by`] for more details.
///
/// Computes in **O(log(n))** time.
#[inline]
Expand All @@ -825,8 +824,8 @@ where

/// Search over a sorted map with an extraction function.
///
/// Returns the position where that value is present, or the position where it can be inserted to maintain the sort.
/// See [`slice::binary_search_by_key`] for more details.
/// Returns the position where that value is present, or the position where it can be inserted
/// to maintain the sort. See [`slice::binary_search_by_key`] for more details.
///
/// Computes in **O(log(n))** time.
#[inline]
Expand Down
18 changes: 9 additions & 9 deletions src/map/slice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,12 +204,12 @@ impl<K, V> Slice<K, V> {

/// Search over a sorted map for a key.
///
/// Returns the position where that key is present, or the position where it can be inserted to maintain the sort.
/// See [`slice::binary_search`] for more details.
/// Returns the position where that key is present, or the position where it can be inserted to
/// maintain the sort. See [`slice::binary_search`] for more details.
///
/// Computes in **O(log(n))** time,
/// which is notably less scalable than looking the key up in the map this is a slice from
/// using [`IndexMap::get_index_of`], but this can also position missing keys.
/// Computes in **O(log(n))** time, which is notably less scalable than looking the key up in
/// the map this is a slice from using [`IndexMap::get_index_of`], but this can also position
/// missing keys.
pub fn binary_search_keys(&self, x: &K) -> Result<usize, usize>
where
K: Ord,
Expand All @@ -219,8 +219,8 @@ impl<K, V> Slice<K, V> {

/// Search over a sorted map with a comparator function.
///
/// Returns the position where that value is present, or the position where it can be inserted to maintain the sort.
/// See [`slice::binary_search_by`] for more details.
/// Returns the position where that value is present, or the position where it can be inserted
/// to maintain the sort. See [`slice::binary_search_by`] for more details.
///
/// Computes in **O(log(n))** time.
#[inline]
Expand All @@ -233,8 +233,8 @@ impl<K, V> Slice<K, V> {

/// Search over a sorted map with an extraction function.
///
/// Returns the position where that value is present, or the position where it can be inserted to maintain the sort.
/// See [`slice::binary_search_by_key`] for more details.
/// Returns the position where that value is present, or the position where it can be inserted
/// to maintain the sort. See [`slice::binary_search_by_key`] for more details.
///
/// Computes in **O(log(n))** time.
#[inline]
Expand Down
17 changes: 8 additions & 9 deletions src/set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -690,12 +690,11 @@ where

/// Search over a sorted set for a value.
///
/// Returns the position where that value is present, or the position where it can be inserted to maintain the sort.
/// See [`slice::binary_search`] for more details.
/// Returns the position where that value is present, or the position where it can be inserted
/// to maintain the sort. See [`slice::binary_search`] for more details.
///
/// Computes in **O(log(n))** time,
/// which is notably less scalable than looking the value up using [`get_index_of`],
/// but this can also position missing values.
/// Computes in **O(log(n))** time, which is notably less scalable than looking the value up
/// using [`get_index_of`][IndexSet::get_index_of], but this can also position missing values.
pub fn binary_search(&self, x: &T) -> Result<usize, usize>
where
T: Ord,
Expand All @@ -705,8 +704,8 @@ where

/// Search over a sorted set with a comparator function.
///
/// Returns the position where that value is present, or the position where it can be inserted to maintain the sort.
/// See [`slice::binary_search_by`] for more details.
/// Returns the position where that value is present, or the position where it can be inserted
/// to maintain the sort. See [`slice::binary_search_by`] for more details.
///
/// Computes in **O(log(n))** time.
#[inline]
Expand All @@ -719,8 +718,8 @@ where

/// Search over a sorted set with an extraction function.
///
/// Returns the position where that value is present, or the position where it can be inserted to maintain the sort.
/// See [`slice::binary_search_by_key`] for more details.
/// Returns the position where that value is present, or the position where it can be inserted
/// to maintain the sort. See [`slice::binary_search_by_key`] for more details.
///
/// Computes in **O(log(n))** time.
#[inline]
Expand Down
18 changes: 9 additions & 9 deletions src/set/slice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,12 +112,12 @@ impl<T> Slice<T> {

/// Search over a sorted set for a value.
///
/// Returns the position where that value is present, or the position where it can be inserted to maintain the sort.
/// See [`slice::binary_search`] for more details.
/// Returns the position where that value is present, or the position where it can be inserted
/// to maintain the sort. See [`slice::binary_search`] for more details.
///
/// Computes in **O(log(n))** time,
/// which is notably less scalable than looking the value up in the set this is a slice from
/// using [`IndexSet::get_index_of`], but this can also position missing values.
/// Computes in **O(log(n))** time, which is notably less scalable than looking the value up in
/// the set this is a slice from using [`IndexSet::get_index_of`], but this can also position
/// missing values.
pub fn binary_search(&self, x: &T) -> Result<usize, usize>
where
T: Ord,
Expand All @@ -127,8 +127,8 @@ impl<T> Slice<T> {

/// Search over a sorted set with a comparator function.
///
/// Returns the position where that value is present, or the position where it can be inserted to maintain the sort.
/// See [`slice::binary_search_by`] for more details.
/// Returns the position where that value is present, or the position where it can be inserted
/// to maintain the sort. See [`slice::binary_search_by`] for more details.
///
/// Computes in **O(log(n))** time.
#[inline]
Expand All @@ -141,8 +141,8 @@ impl<T> Slice<T> {

/// Search over a sorted set with an extraction function.
///
/// Returns the position where that value is present, or the position where it can be inserted to maintain the sort.
/// See [`slice::binary_search_by_key`] for more details.
/// Returns the position where that value is present, or the position where it can be inserted
/// to maintain the sort. See [`slice::binary_search_by_key`] for more details.
///
/// Computes in **O(log(n))** time.
#[inline]
Expand Down

0 comments on commit 7326a6e

Please sign in to comment.