Skip to content

std: Export BinarySearchResult #19287

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 27, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/libcollections/slice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ pub use core::slice::{OrdSlicePrelude, SlicePrelude, Items, MutItems};
pub use core::slice::{ImmutableIntSlice, MutableIntSlice};
pub use core::slice::{MutSplits, MutChunks, Splits};
pub use core::slice::{bytes, mut_ref_slice, ref_slice, CloneSlicePrelude};
pub use core::slice::{Found, NotFound, from_raw_buf, from_raw_mut_buf};
pub use core::slice::{from_raw_buf, from_raw_mut_buf, BinarySearchResult};

// Functional utilities

Expand Down
18 changes: 8 additions & 10 deletions src/libcore/slice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@
// * The `raw` and `bytes` submodules.
// * Boilerplate trait implementations.

pub use self::BinarySearchResult::*;

use mem::transmute;
use clone::Clone;
use cmp::{PartialEq, PartialOrd, Eq, Ord, Ordering, Less, Equal, Greater, Equiv};
Expand Down Expand Up @@ -219,7 +217,7 @@ pub trait SlicePrelude<T> for Sized? {
/// found; the fourth could match any position in `[1,4]`.
///
/// ```rust
/// use std::slice::{Found, NotFound};
/// use std::slice::BinarySearchResult::{Found, NotFound};
/// let s = [0i, 1, 1, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55];
/// let s = s.as_slice();
///
Expand Down Expand Up @@ -548,7 +546,7 @@ impl<T> SlicePrelude<T> for [T] {
while lim != 0 {
let ix = base + (lim >> 1);
match f(&self[ix]) {
Equal => return Found(ix),
Equal => return BinarySearchResult::Found(ix),
Less => {
base = ix + 1;
lim -= 1;
Expand All @@ -557,7 +555,7 @@ impl<T> SlicePrelude<T> for [T] {
}
lim >>= 1;
}
return NotFound(base);
return BinarySearchResult::NotFound(base);
}

#[inline]
Expand Down Expand Up @@ -838,7 +836,7 @@ pub trait OrdSlicePrelude<T: Ord> for Sized? {
/// found; the fourth could match any position in `[1,4]`.
///
/// ```rust
/// use std::slice::{Found, NotFound};
/// use std::slice::BinarySearchResult::{Found, NotFound};
/// let s = [0i, 1, 1, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55];
/// let s = s.as_slice();
///
Expand Down Expand Up @@ -1517,17 +1515,17 @@ impl BinarySearchResult {
/// Similar to `Result::ok`.
pub fn found(&self) -> Option<uint> {
match *self {
Found(i) => Some(i),
NotFound(_) => None
BinarySearchResult::Found(i) => Some(i),
BinarySearchResult::NotFound(_) => None
}
}

/// Convert a `Found` to `None`, `NotFound` to `Some`.
/// Similar to `Result::err`.
pub fn not_found(&self) -> Option<uint> {
match *self {
Found(_) => None,
NotFound(i) => Some(i)
BinarySearchResult::Found(_) => None,
BinarySearchResult::NotFound(i) => Some(i)
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/libregex/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use std::cmp;
use std::fmt;
use std::iter;
use std::num;
use std::slice;
use std::slice::BinarySearchResult;

/// Static data containing Unicode ranges for general categories and scripts.
use unicode::regex::{UNICODE_CLASSES, PERLD, PERLS, PERLW};
Expand Down Expand Up @@ -1027,8 +1027,8 @@ fn is_valid_cap(c: char) -> bool {

fn find_class(classes: NamedClasses, name: &str) -> Option<Vec<(char, char)>> {
match classes.binary_search(|&(s, _)| s.cmp(name)) {
slice::Found(i) => Some(classes[i].val1().to_vec()),
slice::NotFound(_) => None,
BinarySearchResult::Found(i) => Some(classes[i].val1().to_vec()),
BinarySearchResult::NotFound(_) => None,
}
}

Expand Down