@@ -173,6 +173,7 @@ pub fn from_slice<T:Copy>(t: &[T]) -> ~[T] {
173
173
from_fn ( t. len ( ) , |i| t[ i] )
174
174
}
175
175
176
+ /// Creates a new vector with a capacity of `capacity`
176
177
pub fn with_capacity < T > ( capacity : uint ) -> ~[ T ] {
177
178
let mut vec = ~[ ] ;
178
179
reserve ( & mut vec, capacity) ;
@@ -1565,6 +1566,16 @@ pub fn each_permutation<T:Copy>(v: &[T], put: &fn(ts: &[T]) -> bool) {
1565
1566
}
1566
1567
}
1567
1568
1569
+ // see doc below
1570
+ #[cfg(stage0)] // XXX: lifetimes!
1571
+ pub fn windowed<T>(n: uint, v: &[T], it: &fn(&[T]) -> bool) {
1572
+ assert!(1u <= n);
1573
+ if n > v.len() { return; }
1574
+ for uint::range(0, v.len() - n + 1) |i| {
1575
+ if !it(v.slice(i, i+n)) { return }
1576
+ }
1577
+ }
1578
+
1568
1579
/**
1569
1580
* Iterate over all contiguous windows of length `n` of the vector `v`.
1570
1581
*
@@ -1579,14 +1590,6 @@ pub fn each_permutation<T:Copy>(v: &[T], put: &fn(ts: &[T]) -> bool) {
1579
1590
* ~~~
1580
1591
*
1581
1592
* /
1582
- #[ cfg ( stage0) ] // XXX: lifetimes!
1583
- pub fn windowed<T >( n: uint, v: & [ T ] , it: & fn ( & [ T ] ) -> bool) {
1584
- assert ! ( 1 u <= n) ;
1585
- if n > v. len ( ) { return ; }
1586
- for uint:: range( 0 , v. len( ) - n + 1 ) |i| {
1587
- if !it ( v. slice ( i, i+n) ) { return }
1588
- }
1589
- }
1590
1593
#[ cfg ( stage1) ]
1591
1594
#[ cfg( stage2) ]
1592
1595
#[ cfg( stage3) ]
0 commit comments