mirror of
https://github.com/servo/servo.git
synced 2025-07-22 14:53:49 +01:00
Define the binary search methods on [T] rather than &[T].
This commit is contained in:
parent
88d9c1b257
commit
4ee89363fb
1 changed files with 5 additions and 5 deletions
|
@ -11,8 +11,8 @@ pub trait Comparator<K,T> {
|
|||
fn compare(&self, key: &K, value: &T) -> Ordering;
|
||||
}
|
||||
|
||||
pub trait BinarySearchMethods<'a, T: Ord + PartialOrd + PartialEq> {
|
||||
fn binary_search_(&self, key: &T) -> Option<&'a T>;
|
||||
pub trait BinarySearchMethods<T: Ord + PartialOrd + PartialEq> {
|
||||
fn binary_search_(&self, key: &T) -> Option<&T>;
|
||||
fn binary_search_index(&self, key: &T) -> Option<usize>;
|
||||
}
|
||||
|
||||
|
@ -20,8 +20,8 @@ pub trait FullBinarySearchMethods<T> {
|
|||
fn binary_search_index_by<K,C:Comparator<K,T>>(&self, key: &K, cmp: C) -> Option<usize>;
|
||||
}
|
||||
|
||||
impl<'a, T: Ord + PartialOrd + PartialEq> BinarySearchMethods<'a, T> for &'a [T] {
|
||||
fn binary_search_(&self, key: &T) -> Option<&'a T> {
|
||||
impl<T: Ord + PartialOrd + PartialEq> BinarySearchMethods<T> for [T] {
|
||||
fn binary_search_(&self, key: &T) -> Option<&T> {
|
||||
self.binary_search_index(key).map(|i| &self[i])
|
||||
}
|
||||
|
||||
|
@ -30,7 +30,7 @@ impl<'a, T: Ord + PartialOrd + PartialEq> BinarySearchMethods<'a, T> for &'a [T]
|
|||
}
|
||||
}
|
||||
|
||||
impl<'a, T> FullBinarySearchMethods<T> for &'a [T] {
|
||||
impl<T> FullBinarySearchMethods<T> for [T] {
|
||||
fn binary_search_index_by<K,C:Comparator<K,T>>(&self, key: &K, cmp: C) -> Option<usize> {
|
||||
if self.len() == 0 {
|
||||
return None;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue