Skip to content

Fix core::vec documentation a bit #6055

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 2 commits into from
Apr 26, 2013
Merged
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
19 changes: 11 additions & 8 deletions src/libcore/vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ pub fn from_slice<T:Copy>(t: &[T]) -> ~[T] {
from_fn(t.len(), |i| t[i])
}

/// Creates a new vector with a capacity of `capacity`
pub fn with_capacity<T>(capacity: uint) -> ~[T] {
let mut vec = ~[];
reserve(&mut vec, capacity);
Expand Down Expand Up @@ -1565,6 +1566,16 @@ pub fn each_permutation<T:Copy>(v: &[T], put: &fn(ts: &[T]) -> bool) {
}
}

// see doc below
#[cfg(stage0)] // XXX: lifetimes!
pub fn windowed<T>(n: uint, v: &[T], it: &fn(&[T]) -> bool) {
assert!(1u <= n);
if n > v.len() { return; }
for uint::range(0, v.len() - n + 1) |i| {
if !it(v.slice(i, i+n)) { return }
}
}

/**
* Iterate over all contiguous windows of length `n` of the vector `v`.
*
Expand All @@ -1579,14 +1590,6 @@ pub fn each_permutation<T:Copy>(v: &[T], put: &fn(ts: &[T]) -> bool) {
* ~~~
*
*/
#[cfg(stage0)] // XXX: lifetimes!
pub fn windowed<T>(n: uint, v: &[T], it: &fn(&[T]) -> bool) {
assert!(1u <= n);
if n > v.len() { return; }
for uint::range(0, v.len() - n + 1) |i| {
if !it(v.slice(i, i+n)) { return }
}
}
#[cfg(stage1)]
#[cfg(stage2)]
#[cfg(stage3)]
Expand Down