@@ -1300,44 +1300,6 @@ pub fn reverse<T>(v: &mut [T]) {
1300
1300
}
1301
1301
}
1302
1302
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
-
1341
1303
/// Returns a vector with the order of elements reversed
1342
1304
pub fn reversed < T : Copy > ( v : & const [ T ] ) -> ~[ T ] {
1343
1305
let mut rs: ~[ T ] = ~[ ] ;
@@ -1394,7 +1356,7 @@ pub fn each_permutation<T:Copy>(values: &[T], fun: &fn(perm : &[T]) -> bool) ->
1394
1356
// swap indices[k] and indices[l]; sort indices[k+1..]
1395
1357
// (they're just reversed)
1396
1358
vec:: swap ( indices, k, l) ;
1397
- reverse_part ( indices, k+1 , length) ;
1359
+ reverse ( indices. mut_slice ( k+1 , length) ) ;
1398
1360
// fixup permutation based on indices
1399
1361
for uint:: range( k, length) |i| {
1400
1362
permutation[ i] = copy values[ indices[ i] ] ;
@@ -3971,7 +3933,7 @@ mod tests {
3971
3933
#[ test]
3972
3934
fn test_reverse_part( ) {
3973
3935
let mut values = [ 1 , 2 , 3 , 4 , 5 ] ;
3974
- reverse_part ( values, 1 , 4 ) ;
3936
+ reverse ( values. mut_slice ( 1 , 4 ) ) ;
3975
3937
assert_eq ! ( values, [ 1 , 4 , 3 , 2 , 5 ] ) ;
3976
3938
}
3977
3939
0 commit comments