Skip to content

Commit

Permalink
Move position and rposition methods to ImmutableVector trait
Browse files Browse the repository at this point in the history
  • Loading branch information
gifnksm committed May 14, 2013
1 parent 3aa1122 commit 4e1fac8
Showing 1 changed file with 26 additions and 26 deletions.
52 changes: 26 additions & 26 deletions src/libcore/vec.rs
Expand Up @@ -2069,6 +2069,8 @@ pub trait ImmutableVector<'self, T> {
fn initn(&self, n: uint) -> &'self [T];
fn last(&self) -> &'self T;
fn last_opt(&self) -> Option<&'self T>;
fn position(&self, f: &fn(t: &T) -> bool) -> Option<uint>;
fn rposition(&self, f: &fn(t: &T) -> bool) -> Option<uint>;
#[cfg(stage0)]
fn each_reverse(&self, blk: &fn(&T) -> bool);
#[cfg(not(stage0))]
Expand Down Expand Up @@ -2136,6 +2138,30 @@ impl<'self,T> ImmutableVector<'self, T> for &'self [T] {
#[inline]
fn last_opt(&self) -> Option<&'self T> { last_opt(*self) }

/**
* Find the first index matching some predicate
*
* Apply function `f` to each element of `v`. When function `f` returns
* true then an option containing the index is returned. If `f` matches no
* elements then none is returned.
*/
#[inline]
fn position(&self, f: &fn(t: &T) -> bool) -> Option<uint> {
position(*self, f)
}

/**
* Find the last index matching some predicate
*
* Apply function `f` to each element of `v` in reverse order. When
* function `f` returns true then an option containing the index is
* returned. If `f` matches no elements then none is returned.
*/
#[inline]
fn rposition(&self, f: &fn(t: &T) -> bool) -> Option<uint> {
rposition(*self, f)
}

/// Iterates over a vector's elements in reverse.
#[inline]
#[cfg(stage0)]
Expand Down Expand Up @@ -2228,43 +2254,17 @@ impl<'self,T> ImmutableVector<'self, T> for &'self [T] {
}

pub trait ImmutableEqVector<T:Eq> {
fn position(&self, f: &fn(t: &T) -> bool) -> Option<uint>;
fn position_elem(&self, t: &T) -> Option<uint>;
fn rposition(&self, f: &fn(t: &T) -> bool) -> Option<uint>;
fn rposition_elem(&self, t: &T) -> Option<uint>;
}

impl<'self,T:Eq> ImmutableEqVector<T> for &'self [T] {
/**
* Find the first index matching some predicate
*
* Apply function `f` to each element of `v`. When function `f` returns
* true then an option containing the index is returned. If `f` matches no
* elements then none is returned.
*/
#[inline]
fn position(&self, f: &fn(t: &T) -> bool) -> Option<uint> {
position(*self, f)
}

/// Find the first index containing a matching value
#[inline]
fn position_elem(&self, x: &T) -> Option<uint> {
position_elem(*self, x)
}

/**
* Find the last index matching some predicate
*
* Apply function `f` to each element of `v` in reverse order. When
* function `f` returns true then an option containing the index is
* returned. If `f` matches no elements then none is returned.
*/
#[inline]
fn rposition(&self, f: &fn(t: &T) -> bool) -> Option<uint> {
rposition(*self, f)
}

/// Find the last index containing a matching value
#[inline]
fn rposition_elem(&self, t: &T) -> Option<uint> {
Expand Down

5 comments on commit 4e1fac8

@bors
Copy link
Contributor

@bors bors commented on 4e1fac8 May 14, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bors
Copy link
Contributor

@bors bors commented on 4e1fac8 May 14, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging gifnksm/rust/rposition-immutable = 4e1fac8 into auto

@bors
Copy link
Contributor

@bors bors commented on 4e1fac8 May 14, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

gifnksm/rust/rposition-immutable = 4e1fac8 merged ok, testing candidate = 043d022

@bors
Copy link
Contributor

@bors bors commented on 4e1fac8 May 14, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bors
Copy link
Contributor

@bors bors commented on 4e1fac8 May 14, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fast-forwarding incoming to auto = 043d022

Please sign in to comment.