Skip to content

Commit 9f5f609

Browse files
thestingeremberian
authored andcommitted
vec: remove superseded reverse_part function
`reverse(xs.mut_slice(a, b))` replaces `reverse_part(xs, a, b)`
1 parent 58fc1fc commit 9f5f609

File tree

1 file changed

+2
-40
lines changed

1 file changed

+2
-40
lines changed

src/libstd/vec.rs

Lines changed: 2 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1300,44 +1300,6 @@ pub fn reverse<T>(v: &mut [T]) {
13001300
}
13011301
}
13021302

1303-
/**
1304-
* Reverse part of a vector in place.
1305-
*
1306-
* Reverse the elements in the vector between `start` and `end - 1`.
1307-
*
1308-
* If either start or end do not represent valid positions in the vector, the
1309-
* vector is returned unchanged.
1310-
*
1311-
* # Arguments
1312-
*
1313-
* * `v` - The mutable vector to be modified
1314-
*
1315-
* * `start` - Index of the first element of the slice
1316-
*
1317-
* * `end` - Index one past the final element to be reversed.
1318-
*
1319-
* # Example
1320-
*
1321-
* Assume a mutable vector `v` contains `[1,2,3,4,5]`. After the call:
1322-
*
1323-
* ~~~ {.rust}
1324-
* reverse_part(v, 1, 4);
1325-
* ~~~
1326-
*
1327-
* `v` now contains `[1,4,3,2,5]`.
1328-
*/
1329-
pub fn reverse_part<T>(v: &mut [T], start: uint, end : uint) {
1330-
let sz = v.len();
1331-
if start >= sz || end > sz { return; }
1332-
let mut i = start;
1333-
let mut j = end - 1;
1334-
while i < j {
1335-
vec::swap(v, i, j);
1336-
i += 1;
1337-
j -= 1;
1338-
}
1339-
}
1340-
13411303
/// Returns a vector with the order of elements reversed
13421304
pub fn reversed<T:Copy>(v: &const [T]) -> ~[T] {
13431305
let mut rs: ~[T] = ~[];
@@ -1394,7 +1356,7 @@ pub fn each_permutation<T:Copy>(values: &[T], fun: &fn(perm : &[T]) -> bool) ->
13941356
// swap indices[k] and indices[l]; sort indices[k+1..]
13951357
// (they're just reversed)
13961358
vec::swap(indices, k, l);
1397-
reverse_part(indices, k+1, length);
1359+
reverse(indices.mut_slice(k+1, length));
13981360
// fixup permutation based on indices
13991361
for uint::range(k, length) |i| {
14001362
permutation[i] = copy values[indices[i]];
@@ -3971,7 +3933,7 @@ mod tests {
39713933
#[test]
39723934
fn test_reverse_part() {
39733935
let mut values = [1,2,3,4,5];
3974-
reverse_part(values,1,4);
3936+
reverse(values.mut_slice(1, 4));
39753937
assert_eq!(values, [1,4,3,2,5]);
39763938
}
39773939

0 commit comments

Comments
 (0)