Skip to content

Commit

Permalink
fix wording
Browse files Browse the repository at this point in the history
  • Loading branch information
Eh2406 committed Oct 30, 2023
1 parent d93534f commit 3263c0f
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 56 deletions.
23 changes: 13 additions & 10 deletions src/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -796,9 +796,10 @@ where

/// Search over a sorted map with a comparator function.
///
/// Returns the position where that value is present, or the position where can be inserted to maintain the sort.
/// see [slice::binary_search_by] for more details.
/// **O(log(n))**
/// 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]
pub fn binary_search_by<'a, F>(&'a self, f: F) -> Result<usize, usize>
where
Expand All @@ -807,11 +808,12 @@ where
self.as_slice().binary_search_by(f)
}

/// Search over a sorted map with a key extraction function.
/// 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 can be inserted to maintain the sort.
/// see [slice::binary_search_by_key] for more details.
/// **O(log(n))**
/// Computes in **O(log(n))** time.
#[inline]
pub fn binary_search_by_key<'a, B, F>(&'a self, b: &B, f: F) -> Result<usize, usize>
where
Expand All @@ -821,11 +823,12 @@ where
self.as_slice().binary_search_by_key(b, f)
}

/// Returns the index of the partition point or a sorted map according to the given predicate
/// Returns the index of the partition point of a sorted map according to the given predicate
/// (the index of the first element of the second partition).
///
/// see [slice::partition_point] for more details.
/// **O(log(n))**
/// see [`slice::partition_point`] for more details.
///
/// Computes in **O(log(n))** time.
#[must_use]
pub fn partition_point<P>(&self, pred: P) -> usize
where
Expand Down
33 changes: 19 additions & 14 deletions src/map/slice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,11 +202,13 @@ impl<K, V> Slice<K, V> {
IntoValues::new(self.into_entries())
}

/// Search over a sorted map for a value.
/// Search over a sorted map for a key.
///
/// Returns the position where that value is present, or the position where can be inserted to maintain the sort.
/// see [slice::binary_search] for more details.
/// **O(log(n))**, which is notably less scalable than looking the value up in the map set is a slice from.
/// 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 map this is a slice from.
pub fn binary_search_keys(&self, x: &K) -> Result<usize, usize>
where
K: Ord,
Expand All @@ -216,9 +218,10 @@ 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 can be inserted to maintain the sort.
/// see [slice::binary_search_by] for more details.
/// **O(log(n))**
/// 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]
pub fn binary_search_by<'a, F>(&'a self, mut f: F) -> Result<usize, usize>
where
Expand All @@ -227,11 +230,12 @@ impl<K, V> Slice<K, V> {
self.entries.binary_search_by(move |a| f(&a.key, &a.value))
}

/// Search over a sorted map with a key extraction function.
/// Search over a sorted map with an extraction function.
///
/// Returns the position where that value is present, or the position where can be inserted to maintain the sort.
/// see [slice::binary_search_by_key] for more details.
/// **O(log(n))**
/// 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]
pub fn binary_search_by_key<'a, B, F>(&'a self, b: &B, mut f: F) -> Result<usize, usize>
where
Expand All @@ -241,11 +245,12 @@ impl<K, V> Slice<K, V> {
self.binary_search_by(|k, v| f(k, v).cmp(b))
}

/// Returns the index of the partition point or a sorted map according to the given predicate
/// Returns the index of the partition point of a sorted map according to the given predicate
/// (the index of the first element of the second partition).
///
/// see [slice::partition_point] for more details.
/// **O(log(n))**
/// see [`slice::partition_point`] for more details.
///
/// Computes in **O(log(n))** time.
#[must_use]
pub fn partition_point<P>(&self, mut pred: P) -> usize
where
Expand Down
6 changes: 3 additions & 3 deletions src/map/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,7 @@ fn iter_default() {

#[test]
fn test_binary_search_by() {
// addaped from stds test for binary_search
// adapted from std's test for binary_search
let b: IndexMap<_, i32> = []
.into_iter()
.enumerate()
Expand Down Expand Up @@ -526,7 +526,7 @@ fn test_binary_search_by() {

#[test]
fn test_binary_search_by_key() {
// addaped from stds test for binary_search
// adapted from std's test for binary_search
let b: IndexMap<_, i32> = []
.into_iter()
.enumerate()
Expand Down Expand Up @@ -602,7 +602,7 @@ fn test_binary_search_by_key() {

#[test]
fn test_partition_point() {
// addaped from stds test for partition_point
// adapted from std's test for partition_point
let b: IndexMap<_, i32> = []
.into_iter()
.enumerate()
Expand Down
23 changes: 13 additions & 10 deletions src/set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -690,9 +690,10 @@ where

/// Search over a sorted set with a comparator function.
///
/// Returns the position where that value is present, or the position where can be inserted to maintain the sort.
/// see [slice::binary_search_by] for more details.
/// **O(log(n))**
/// 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]
pub fn binary_search_by<'a, F>(&'a self, f: F) -> Result<usize, usize>
where
Expand All @@ -701,11 +702,12 @@ where
self.as_slice().binary_search_by(f)
}

/// Search over a sorted set with a key extraction function.
/// 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 can be inserted to maintain the sort.
/// see [slice::binary_search_by_key] for more details.
/// **O(log(n))**
/// Computes in **O(log(n))** time.
#[inline]
pub fn binary_search_by_key<'a, B, F>(&'a self, b: &B, f: F) -> Result<usize, usize>
where
Expand All @@ -715,11 +717,12 @@ where
self.as_slice().binary_search_by_key(b, f)
}

/// Returns the index of the partition point or a sorted set according to the given predicate
/// Returns the index of the partition point of a sorted set according to the given predicate
/// (the index of the first element of the second partition).
///
/// see [slice::partition_point] for more details.
/// **O(log(n))**
/// see [`slice::partition_point`] for more details.
///
/// Computes in **O(log(n))** time.
#[must_use]
pub fn partition_point<P>(&self, pred: P) -> usize
where
Expand Down
31 changes: 18 additions & 13 deletions src/set/slice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,11 @@ impl<T> Slice<T> {

/// Search over a sorted set for a value.
///
/// Returns the position where that value is present, or the position where can be inserted to maintain the sort.
/// see [slice::binary_search] for more details.
/// **O(log(n))**, which is notably less scalable than looking the value up in the set this is a slice from.
/// 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.
pub fn binary_search(&self, x: &T) -> Result<usize, usize>
where
T: Ord,
Expand All @@ -124,9 +126,10 @@ 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 can be inserted to maintain the sort.
/// see [slice::binary_search_by] for more details.
/// **O(log(n))**
/// 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]
pub fn binary_search_by<'a, F>(&'a self, mut f: F) -> Result<usize, usize>
where
Expand All @@ -135,11 +138,12 @@ impl<T> Slice<T> {
self.entries.binary_search_by(move |a| f(&a.key))
}

/// Search over a sorted set with a key extraction function.
/// Search over a sorted set with an extraction function.
///
/// Returns the position where that value is present, or the position where can be inserted to maintain the sort.
/// see [slice::binary_search_by_key] for more details.
/// **O(log(n))**
/// 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]
pub fn binary_search_by_key<'a, B, F>(&'a self, b: &B, mut f: F) -> Result<usize, usize>
where
Expand All @@ -149,11 +153,12 @@ impl<T> Slice<T> {
self.binary_search_by(|k| f(k).cmp(b))
}

/// Returns the index of the partition point or a sorted set according to the given predicate
/// Returns the index of the partition point of a sorted set according to the given predicate
/// (the index of the first element of the second partition).
///
/// see [slice::partition_point] for more details.
/// **O(log(n))**
/// see [`slice::partition_point`] for more details.
///
/// Computes in **O(log(n))** time.
#[must_use]
pub fn partition_point<P>(&self, mut pred: P) -> usize
where
Expand Down
12 changes: 6 additions & 6 deletions src/set/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -546,7 +546,7 @@ fn iter_default() {

#[test]
fn test_binary_search_by() {
// addaped from stds test for binary_search
// adapted from std's test for binary_search
let b: IndexSet<i32> = [].into();
assert_eq!(b.binary_search_by(|x| x.cmp(&5)), Err(0));

Expand Down Expand Up @@ -577,7 +577,7 @@ fn test_binary_search_by() {
assert_eq!(b.binary_search_by(|x| x.cmp(&0)), Err(0));
assert_eq!(b.binary_search_by(|x| x.cmp(&1)), Ok(0));
assert_eq!(b.binary_search_by(|x| x.cmp(&2)), Err(1));
// diff from std as set the duplicates keys
// diff from std as set merges the duplicate keys
assert!(match b.binary_search_by(|x| x.cmp(&3)) {
Ok(1..=2) => true,
_ => false,
Expand All @@ -595,7 +595,7 @@ fn test_binary_search_by() {

#[test]
fn test_binary_search_by_key() {
// addaped from stds test for binary_search
// adapted from std's test for binary_search
let b: IndexSet<i32> = [].into();
assert_eq!(b.binary_search_by_key(&5, |&x| x), Err(0));

Expand Down Expand Up @@ -626,7 +626,7 @@ fn test_binary_search_by_key() {
assert_eq!(b.binary_search_by_key(&0, |&x| x), Err(0));
assert_eq!(b.binary_search_by_key(&1, |&x| x), Ok(0));
assert_eq!(b.binary_search_by_key(&2, |&x| x), Err(1));
// diff from std as set the duplicates keys
// diff from std as set merges the duplicate keys
assert!(match b.binary_search_by_key(&3, |&x| x) {
Ok(1..=2) => true,
_ => false,
Expand All @@ -644,7 +644,7 @@ fn test_binary_search_by_key() {

#[test]
fn test_partition_point() {
// addaped from stds test for partition_point
// adapted from std's test for partition_point
let b: IndexSet<i32> = [].into();
assert_eq!(b.partition_point(|&x| x < 5), 0);

Expand Down Expand Up @@ -676,7 +676,7 @@ fn test_partition_point() {
assert_eq!(b.partition_point(|&x| x < 1), 0);
assert_eq!(b.partition_point(|&x| x < 2), 1);
assert_eq!(b.partition_point(|&x| x < 3), 1);
assert_eq!(b.partition_point(|&x| x < 4), 2); // diff from std as set the duplicates keys
assert_eq!(b.partition_point(|&x| x < 4), 2); // diff from std as set merges the duplicate keys
assert_eq!(b.partition_point(|&x| x < 5), 2);
assert_eq!(b.partition_point(|&x| x < 6), 2);
assert_eq!(b.partition_point(|&x| x < 7), 2);
Expand Down

0 comments on commit 3263c0f

Please sign in to comment.