@@ -127,31 +127,31 @@ pub trait VectorVector<T> {
127
127
// FIXME #5898: calling these .concat and .connect conflicts with
128
128
// StrVector::con{cat,nect}, since they have generic contents.
129
129
/// Flattens a vector of vectors of T into a single vector of T.
130
- fn concat_vec ( & self ) -> ~ [ T ] ;
130
+ fn concat_vec ( & self ) -> Vec < T > ;
131
131
132
132
/// Concatenate a vector of vectors, placing a given separator between each.
133
- fn connect_vec ( & self , sep : & T ) -> ~ [ T ] ;
133
+ fn connect_vec ( & self , sep : & T ) -> Vec < T > ;
134
134
}
135
135
136
136
impl < ' a , T : Clone , V : Vector < T > > VectorVector < T > for & ' a [ V ] {
137
- fn concat_vec ( & self ) -> ~ [ T ] {
137
+ fn concat_vec ( & self ) -> Vec < T > {
138
138
let size = self . iter ( ) . fold ( 0 u, |acc, v| acc + v. as_slice ( ) . len ( ) ) ;
139
139
let mut result = Vec :: with_capacity ( size) ;
140
140
for v in self . iter ( ) {
141
141
result. push_all ( v. as_slice ( ) )
142
142
}
143
- result. move_iter ( ) . collect ( )
143
+ result
144
144
}
145
145
146
- fn connect_vec ( & self , sep : & T ) -> ~ [ T ] {
146
+ fn connect_vec ( & self , sep : & T ) -> Vec < T > {
147
147
let size = self . iter ( ) . fold ( 0 u, |acc, v| acc + v. as_slice ( ) . len ( ) ) ;
148
148
let mut result = Vec :: with_capacity ( size + self . len ( ) ) ;
149
149
let mut first = true ;
150
150
for v in self . iter ( ) {
151
151
if first { first = false } else { result. push ( sep. clone ( ) ) }
152
152
result. push_all ( v. as_slice ( ) )
153
153
}
154
- result. move_iter ( ) . collect ( )
154
+ result
155
155
}
156
156
}
157
157
@@ -185,7 +185,7 @@ pub fn unzip<T, U, V: Iterator<(T, U)>>(mut iter: V) -> (~[T], ~[U]) {
185
185
/// The last generated swap is always (0, 1), and it returns the
186
186
/// sequence to its initial order.
187
187
pub struct ElementSwaps {
188
- sdir : ~ [ SizeDirection ] ,
188
+ sdir : Vec < SizeDirection > ,
189
189
/// If true, emit the last swap that returns the sequence to initial state
190
190
emit_reset : bool ,
191
191
swaps_made : uint ,
@@ -199,9 +199,7 @@ impl ElementSwaps {
199
199
// element (equal to the original index).
200
200
ElementSwaps {
201
201
emit_reset : true ,
202
- sdir : range ( 0 , length)
203
- . map ( |i| SizeDirection { size : i, dir : Neg } )
204
- . collect :: < ~[ _ ] > ( ) ,
202
+ sdir : range ( 0 , length) . map ( |i| SizeDirection { size : i, dir : Neg } ) . collect ( ) ,
205
203
swaps_made : 0
206
204
}
207
205
}
@@ -228,12 +226,12 @@ impl Iterator<(uint, uint)> for ElementSwaps {
228
226
let max = self . sdir . iter ( ) . map ( |& x| x) . enumerate ( )
229
227
. filter ( |& ( i, sd) |
230
228
new_pos ( i, sd. dir ) < self . sdir . len ( ) &&
231
- self . sdir [ new_pos ( i, sd. dir ) ] . size < sd. size )
229
+ self . sdir . get ( new_pos ( i, sd. dir ) ) . size < sd. size )
232
230
. max_by ( |& ( _, sd) | sd. size ) ;
233
231
match max {
234
232
Some ( ( i, sd) ) => {
235
233
let j = new_pos ( i, sd. dir ) ;
236
- self . sdir . swap ( i, j) ;
234
+ self . sdir . as_mut_slice ( ) . swap ( i, j) ;
237
235
238
236
// Swap the direction of each larger SizeDirection
239
237
for x in self . sdir . mut_iter ( ) {
@@ -368,7 +366,7 @@ impl<T: Clone> CloneableVector<T> for ~[T] {
368
366
pub trait ImmutableCloneableVector < T > {
369
367
/// Partitions the vector into two vectors `(A,B)`, where all
370
368
/// elements of `A` satisfy `f` and all elements of `B` do not.
371
- fn partitioned ( & self , f: |& T | -> bool) -> ( ~ [ T ] , ~ [ T ] ) ;
369
+ fn partitioned ( & self , f: |& T | -> bool) -> ( Vec < T > , Vec < T > ) ;
372
370
373
371
/// Create an iterator that yields every possible permutation of the
374
372
/// vector in succession.
@@ -377,7 +375,7 @@ pub trait ImmutableCloneableVector<T> {
377
375
378
376
impl < ' a , T : Clone > ImmutableCloneableVector < T > for & ' a [ T ] {
379
377
#[ inline]
380
- fn partitioned ( & self , f: |& T | -> bool) -> ( ~ [ T ] , ~ [ T ] ) {
378
+ fn partitioned ( & self , f: |& T | -> bool) -> ( Vec < T > , Vec < T > ) {
381
379
let mut lefts = Vec :: new ( ) ;
382
380
let mut rights = Vec :: new ( ) ;
383
381
@@ -389,7 +387,7 @@ impl<'a,T:Clone> ImmutableCloneableVector<T> for &'a [T] {
389
387
}
390
388
}
391
389
392
- ( lefts. move_iter ( ) . collect ( ) , rights. move_iter ( ) . collect ( ) )
390
+ ( lefts, rights)
393
391
}
394
392
395
393
fn permutations ( self ) -> Permutations < T > {
@@ -426,7 +424,7 @@ pub trait OwnedVector<T> {
426
424
* Partitions the vector into two vectors `(A,B)`, where all
427
425
* elements of `A` satisfy `f` and all elements of `B` do not.
428
426
*/
429
- fn partition ( self , f: |& T | -> bool) -> ( ~ [ T ] , ~ [ T ] ) ;
427
+ fn partition ( self , f: |& T | -> bool) -> ( Vec < T > , Vec < T > ) ;
430
428
}
431
429
432
430
impl < T > OwnedVector < T > for ~[ T ] {
@@ -446,7 +444,7 @@ impl<T> OwnedVector<T> for ~[T] {
446
444
}
447
445
448
446
#[ inline]
449
- fn partition ( self , f: |& T | -> bool) -> ( ~ [ T ] , ~ [ T ] ) {
447
+ fn partition ( self , f: |& T | -> bool) -> ( Vec < T > , Vec < T > ) {
450
448
let mut lefts = Vec :: new ( ) ;
451
449
let mut rights = Vec :: new ( ) ;
452
450
@@ -458,7 +456,7 @@ impl<T> OwnedVector<T> for ~[T] {
458
456
}
459
457
}
460
458
461
- ( lefts. move_iter ( ) . collect ( ) , rights. move_iter ( ) . collect ( ) )
459
+ ( lefts, rights)
462
460
}
463
461
}
464
462
@@ -1250,6 +1248,7 @@ mod tests {
1250
1248
1251
1249
let ( left, right) = unzip ( z1. iter ( ) . map ( |& x| x) ) ;
1252
1250
1251
+ let ( left, right) = ( left. as_slice ( ) , right. as_slice ( ) ) ;
1253
1252
assert_eq ! ( ( 1 , 4 ) , ( left[ 0 ] , right[ 0 ] ) ) ;
1254
1253
assert_eq ! ( ( 2 , 5 ) , ( left[ 1 ] , right[ 1 ] ) ) ;
1255
1254
assert_eq ! ( ( 3 , 6 ) , ( left[ 2 ] , right[ 2 ] ) ) ;
@@ -1455,43 +1454,6 @@ mod tests {
1455
1454
}
1456
1455
}
1457
1456
1458
- #[ test]
1459
- fn test_partition ( ) {
1460
- assert_eq ! ( ( box [ ] ) . partition( |x: & int| * x < 3 ) , ( box [ ] , box [ ] ) ) ;
1461
- assert_eq ! ( ( box [ 1 , 2 , 3 ] ) . partition( |x: & int| * x < 4 ) , ( box [ 1 , 2 , 3 ] , box [ ] ) ) ;
1462
- assert_eq ! ( ( box [ 1 , 2 , 3 ] ) . partition( |x: & int| * x < 2 ) , ( box [ 1 ] , box [ 2 , 3 ] ) ) ;
1463
- assert_eq ! ( ( box [ 1 , 2 , 3 ] ) . partition( |x: & int| * x < 0 ) , ( box [ ] , box [ 1 , 2 , 3 ] ) ) ;
1464
- }
1465
-
1466
- #[ test]
1467
- fn test_partitioned ( ) {
1468
- assert_eq ! ( ( [ ] ) . partitioned( |x: & int| * x < 3 ) , ( box [ ] , box [ ] ) )
1469
- assert_eq ! ( ( [ 1 , 2 , 3 ] ) . partitioned( |x: & int| * x < 4 ) , ( box [ 1 , 2 , 3 ] , box [ ] ) ) ;
1470
- assert_eq ! ( ( [ 1 , 2 , 3 ] ) . partitioned( |x: & int| * x < 2 ) , ( box [ 1 ] , box [ 2 , 3 ] ) ) ;
1471
- assert_eq ! ( ( [ 1 , 2 , 3 ] ) . partitioned( |x: & int| * x < 0 ) , ( box [ ] , box [ 1 , 2 , 3 ] ) ) ;
1472
- }
1473
-
1474
- #[ test]
1475
- fn test_concat ( ) {
1476
- let v: [ ~[ int ] , ..0 ] = [ ] ;
1477
- assert_eq ! ( v. concat_vec( ) , box [ ] ) ;
1478
- assert_eq ! ( [ box [ 1 ] , box [ 2 , 3 ] ] . concat_vec( ) , box [ 1 , 2 , 3 ] ) ;
1479
-
1480
- assert_eq ! ( [ & [ 1 ] , & [ 2 , 3 ] ] . concat_vec( ) , box [ 1 , 2 , 3 ] ) ;
1481
- }
1482
-
1483
- #[ test]
1484
- fn test_connect ( ) {
1485
- let v: [ ~[ int ] , ..0 ] = [ ] ;
1486
- assert_eq ! ( v. connect_vec( & 0 ) , box [ ] ) ;
1487
- assert_eq ! ( [ box [ 1 ] , box [ 2 , 3 ] ] . connect_vec( & 0 ) , box [ 1 , 0 , 2 , 3 ] ) ;
1488
- assert_eq ! ( [ box [ 1 ] , box [ 2 ] , box [ 3 ] ] . connect_vec( & 0 ) , box [ 1 , 0 , 2 , 0 , 3 ] ) ;
1489
-
1490
- assert_eq ! ( v. connect_vec( & 0 ) , box [ ] ) ;
1491
- assert_eq ! ( [ & [ 1 ] , & [ 2 , 3 ] ] . connect_vec( & 0 ) , box [ 1 , 0 , 2 , 3 ] ) ;
1492
- assert_eq ! ( [ & [ 1 ] , & [ 2 ] , & [ 3 ] ] . connect_vec( & 0 ) , box [ 1 , 0 , 2 , 0 , 3 ] ) ;
1493
- }
1494
-
1495
1457
#[ test]
1496
1458
fn test_shift ( ) {
1497
1459
let mut x = vec ! [ 1 , 2 , 3 ] ;
0 commit comments