@@ -237,31 +237,31 @@ pub trait VectorVector<T> {
237
237
// FIXME #5898: calling these .concat and .connect conflicts with
238
238
// StrVector::con{cat,nect}, since they have generic contents.
239
239
/// Flattens a vector of vectors of T into a single vector of T.
240
- fn concat_vec ( & self ) -> ~ [ T ] ;
240
+ fn concat_vec ( & self ) -> Vec < T > ;
241
241
242
242
/// Concatenate a vector of vectors, placing a given separator between each.
243
- fn connect_vec ( & self , sep : & T ) -> ~ [ T ] ;
243
+ fn connect_vec ( & self , sep : & T ) -> Vec < T > ;
244
244
}
245
245
246
246
impl < ' a , T : Clone , V : Vector < T > > VectorVector < T > for & ' a [ V ] {
247
- fn concat_vec ( & self ) -> ~ [ T ] {
247
+ fn concat_vec ( & self ) -> Vec < T > {
248
248
let size = self . iter ( ) . fold ( 0 u, |acc, v| acc + v. as_slice ( ) . len ( ) ) ;
249
249
let mut result = Vec :: with_capacity ( size) ;
250
250
for v in self . iter ( ) {
251
251
result. push_all ( v. as_slice ( ) )
252
252
}
253
- result. move_iter ( ) . collect ( )
253
+ result
254
254
}
255
255
256
- fn connect_vec ( & self , sep : & T ) -> ~ [ T ] {
256
+ fn connect_vec ( & self , sep : & T ) -> Vec < T > {
257
257
let size = self . iter ( ) . fold ( 0 u, |acc, v| acc + v. as_slice ( ) . len ( ) ) ;
258
258
let mut result = Vec :: with_capacity ( size + self . len ( ) ) ;
259
259
let mut first = true ;
260
260
for v in self . iter ( ) {
261
261
if first { first = false } else { result. push ( sep. clone ( ) ) }
262
262
result. push_all ( v. as_slice ( ) )
263
263
}
264
- result. move_iter ( ) . collect ( )
264
+ result
265
265
}
266
266
}
267
267
@@ -295,7 +295,7 @@ pub fn unzip<T, U, V: Iterator<(T, U)>>(mut iter: V) -> (~[T], ~[U]) {
295
295
/// The last generated swap is always (0, 1), and it returns the
296
296
/// sequence to its initial order.
297
297
pub struct ElementSwaps {
298
- sdir : ~ [ SizeDirection ] ,
298
+ sdir : Vec < SizeDirection > ,
299
299
/// If true, emit the last swap that returns the sequence to initial state
300
300
emit_reset : bool ,
301
301
swaps_made : uint ,
@@ -309,9 +309,7 @@ impl ElementSwaps {
309
309
// element (equal to the original index).
310
310
ElementSwaps {
311
311
emit_reset : true ,
312
- sdir : range ( 0 , length)
313
- . map ( |i| SizeDirection { size : i, dir : Neg } )
314
- . collect :: < ~[ _ ] > ( ) ,
312
+ sdir : range ( 0 , length) . map ( |i| SizeDirection { size : i, dir : Neg } ) . collect ( ) ,
315
313
swaps_made : 0
316
314
}
317
315
}
@@ -338,12 +336,12 @@ impl Iterator<(uint, uint)> for ElementSwaps {
338
336
let max = self . sdir . iter ( ) . map ( |& x| x) . enumerate ( )
339
337
. filter ( |& ( i, sd) |
340
338
new_pos ( i, sd. dir ) < self . sdir . len ( ) &&
341
- self . sdir [ new_pos ( i, sd. dir ) ] . size < sd. size )
339
+ self . sdir . get ( new_pos ( i, sd. dir ) ) . size < sd. size )
342
340
. max_by ( |& ( _, sd) | sd. size ) ;
343
341
match max {
344
342
Some ( ( i, sd) ) => {
345
343
let j = new_pos ( i, sd. dir ) ;
346
- self . sdir . swap ( i, j) ;
344
+ self . sdir . as_mut_slice ( ) . swap ( i, j) ;
347
345
348
346
// Swap the direction of each larger SizeDirection
349
347
for x in self . sdir . mut_iter ( ) {
@@ -1132,7 +1130,7 @@ impl<'a, T: TotalOrd> ImmutableTotalOrdVector<T> for &'a [T] {
1132
1130
pub trait ImmutableCloneableVector < T > {
1133
1131
/// Partitions the vector into two vectors `(A,B)`, where all
1134
1132
/// elements of `A` satisfy `f` and all elements of `B` do not.
1135
- fn partitioned ( & self , f: |& T | -> bool) -> ( ~ [ T ] , ~ [ T ] ) ;
1133
+ fn partitioned ( & self , f: |& T | -> bool) -> ( Vec < T > , Vec < T > ) ;
1136
1134
1137
1135
/// Create an iterator that yields every possible permutation of the
1138
1136
/// vector in succession.
@@ -1141,7 +1139,7 @@ pub trait ImmutableCloneableVector<T> {
1141
1139
1142
1140
impl < ' a , T : Clone > ImmutableCloneableVector < T > for & ' a [ T ] {
1143
1141
#[ inline]
1144
- fn partitioned ( & self , f: |& T | -> bool) -> ( ~ [ T ] , ~ [ T ] ) {
1142
+ fn partitioned ( & self , f: |& T | -> bool) -> ( Vec < T > , Vec < T > ) {
1145
1143
let mut lefts = Vec :: new ( ) ;
1146
1144
let mut rights = Vec :: new ( ) ;
1147
1145
@@ -1153,7 +1151,7 @@ impl<'a,T:Clone> ImmutableCloneableVector<T> for &'a [T] {
1153
1151
}
1154
1152
}
1155
1153
1156
- ( lefts. move_iter ( ) . collect ( ) , rights. move_iter ( ) . collect ( ) )
1154
+ ( lefts, rights)
1157
1155
}
1158
1156
1159
1157
fn permutations ( self ) -> Permutations < T > {
@@ -1190,7 +1188,7 @@ pub trait OwnedVector<T> {
1190
1188
* Partitions the vector into two vectors `(A,B)`, where all
1191
1189
* elements of `A` satisfy `f` and all elements of `B` do not.
1192
1190
*/
1193
- fn partition ( self , f: |& T | -> bool) -> ( ~ [ T ] , ~ [ T ] ) ;
1191
+ fn partition ( self , f: |& T | -> bool) -> ( Vec < T > , Vec < T > ) ;
1194
1192
}
1195
1193
1196
1194
impl < T > OwnedVector < T > for ~[ T ] {
@@ -1210,7 +1208,7 @@ impl<T> OwnedVector<T> for ~[T] {
1210
1208
}
1211
1209
1212
1210
#[ inline]
1213
- fn partition ( self , f: |& T | -> bool) -> ( ~ [ T ] , ~ [ T ] ) {
1211
+ fn partition ( self , f: |& T | -> bool) -> ( Vec < T > , Vec < T > ) {
1214
1212
let mut lefts = Vec :: new ( ) ;
1215
1213
let mut rights = Vec :: new ( ) ;
1216
1214
@@ -1222,7 +1220,7 @@ impl<T> OwnedVector<T> for ~[T] {
1222
1220
}
1223
1221
}
1224
1222
1225
- ( lefts. move_iter ( ) . collect ( ) , rights. move_iter ( ) . collect ( ) )
1223
+ ( lefts, rights)
1226
1224
}
1227
1225
}
1228
1226
@@ -2745,6 +2743,7 @@ mod tests {
2745
2743
2746
2744
let ( left, right) = unzip ( z1. iter ( ) . map ( |& x| x) ) ;
2747
2745
2746
+ let ( left, right) = ( left. as_slice ( ) , right. as_slice ( ) ) ;
2748
2747
assert_eq ! ( ( 1 , 4 ) , ( left[ 0 ] , right[ 0 ] ) ) ;
2749
2748
assert_eq ! ( ( 2 , 5 ) , ( left[ 1 ] , right[ 1 ] ) ) ;
2750
2749
assert_eq ! ( ( 3 , 6 ) , ( left[ 2 ] , right[ 2 ] ) ) ;
@@ -2950,43 +2949,6 @@ mod tests {
2950
2949
}
2951
2950
}
2952
2951
2953
- #[ test]
2954
- fn test_partition ( ) {
2955
- assert_eq ! ( ( box [ ] ) . partition( |x: & int| * x < 3 ) , ( box [ ] , box [ ] ) ) ;
2956
- assert_eq ! ( ( box [ 1 , 2 , 3 ] ) . partition( |x: & int| * x < 4 ) , ( box [ 1 , 2 , 3 ] , box [ ] ) ) ;
2957
- assert_eq ! ( ( box [ 1 , 2 , 3 ] ) . partition( |x: & int| * x < 2 ) , ( box [ 1 ] , box [ 2 , 3 ] ) ) ;
2958
- assert_eq ! ( ( box [ 1 , 2 , 3 ] ) . partition( |x: & int| * x < 0 ) , ( box [ ] , box [ 1 , 2 , 3 ] ) ) ;
2959
- }
2960
-
2961
- #[ test]
2962
- fn test_partitioned ( ) {
2963
- assert_eq ! ( ( [ ] ) . partitioned( |x: & int| * x < 3 ) , ( box [ ] , box [ ] ) )
2964
- assert_eq ! ( ( [ 1 , 2 , 3 ] ) . partitioned( |x: & int| * x < 4 ) , ( box [ 1 , 2 , 3 ] , box [ ] ) ) ;
2965
- assert_eq ! ( ( [ 1 , 2 , 3 ] ) . partitioned( |x: & int| * x < 2 ) , ( box [ 1 ] , box [ 2 , 3 ] ) ) ;
2966
- assert_eq ! ( ( [ 1 , 2 , 3 ] ) . partitioned( |x: & int| * x < 0 ) , ( box [ ] , box [ 1 , 2 , 3 ] ) ) ;
2967
- }
2968
-
2969
- #[ test]
2970
- fn test_concat ( ) {
2971
- let v: [ ~[ int ] , ..0 ] = [ ] ;
2972
- assert_eq ! ( v. concat_vec( ) , box [ ] ) ;
2973
- assert_eq ! ( [ box [ 1 ] , box [ 2 , 3 ] ] . concat_vec( ) , box [ 1 , 2 , 3 ] ) ;
2974
-
2975
- assert_eq ! ( [ & [ 1 ] , & [ 2 , 3 ] ] . concat_vec( ) , box [ 1 , 2 , 3 ] ) ;
2976
- }
2977
-
2978
- #[ test]
2979
- fn test_connect ( ) {
2980
- let v: [ ~[ int ] , ..0 ] = [ ] ;
2981
- assert_eq ! ( v. connect_vec( & 0 ) , box [ ] ) ;
2982
- assert_eq ! ( [ box [ 1 ] , box [ 2 , 3 ] ] . connect_vec( & 0 ) , box [ 1 , 0 , 2 , 3 ] ) ;
2983
- assert_eq ! ( [ box [ 1 ] , box [ 2 ] , box [ 3 ] ] . connect_vec( & 0 ) , box [ 1 , 0 , 2 , 0 , 3 ] ) ;
2984
-
2985
- assert_eq ! ( v. connect_vec( & 0 ) , box [ ] ) ;
2986
- assert_eq ! ( [ & [ 1 ] , & [ 2 , 3 ] ] . connect_vec( & 0 ) , box [ 1 , 0 , 2 , 3 ] ) ;
2987
- assert_eq ! ( [ & [ 1 ] , & [ 2 ] , & [ 3 ] ] . connect_vec( & 0 ) , box [ 1 , 0 , 2 , 0 , 3 ] ) ;
2988
- }
2989
-
2990
2952
#[ test]
2991
2953
fn test_shift ( ) {
2992
2954
let mut x = vec ! [ 1 , 2 , 3 ] ;
0 commit comments