@@ -52,7 +52,7 @@ Predicate: same_length
52
52
53
53
Returns true if two vectors have the same length
54
54
*/
55
- pure fn same_length < T , U > ( xs : [ T ] , ys : [ U ] ) -> bool {
55
+ pure fn same_length < T , U > ( xs : [ const T ] , ys : [ const U ] ) -> bool {
56
56
vec:: len ( xs) == vec:: len ( ys)
57
57
}
58
58
@@ -278,7 +278,7 @@ Function: split
278
278
279
279
Split the vector `v` by applying each element against the predicate `f`.
280
280
*/
281
- fn split < T : copy > ( v : [ T ] , f : fn ( T ) -> bool ) -> [ [ T ] ] {
281
+ fn split < T : copy > ( v : [ const T ] , f : fn ( T ) -> bool ) -> [ [ T ] ] {
282
282
let ln = len ( v) ;
283
283
if ( ln == 0 u) { ret [ ] }
284
284
@@ -303,7 +303,7 @@ Function: splitn
303
303
Split the vector `v` by applying each element against the predicate `f` up
304
304
to `n` times.
305
305
*/
306
- fn splitn < T : copy > ( v : [ T ] , n : uint , f : fn ( T ) -> bool ) -> [ [ T ] ] {
306
+ fn splitn < T : copy > ( v : [ const T ] , n : uint , f : fn ( T ) -> bool ) -> [ [ T ] ] {
307
307
let ln = len ( v) ;
308
308
if ( ln == 0 u) { ret [ ] }
309
309
@@ -331,7 +331,7 @@ Function: rsplit
331
331
Reverse split the vector `v` by applying each element against the predicate
332
332
`f`.
333
333
*/
334
- fn rsplit < T : copy > ( v : [ T ] , f : fn ( T ) -> bool ) -> [ [ T ] ] {
334
+ fn rsplit < T : copy > ( v : [ const T ] , f : fn ( T ) -> bool ) -> [ [ T ] ] {
335
335
let ln = len ( v) ;
336
336
if ( ln == 0 u) { ret [ ] }
337
337
@@ -356,7 +356,7 @@ Function: rsplitn
356
356
Reverse split the vector `v` by applying each element against the predicate
357
357
`f` up to `n times.
358
358
*/
359
- fn rsplitn < T : copy > ( v : [ T ] , n : uint , f : fn ( T ) -> bool ) -> [ [ T ] ] {
359
+ fn rsplitn < T : copy > ( v : [ const T ] , n : uint , f : fn ( T ) -> bool ) -> [ [ T ] ] {
360
360
let ln = len ( v) ;
361
361
if ( ln == 0 u) { ret [ ] }
362
362
@@ -412,7 +412,7 @@ Function: push
412
412
413
413
Append an element to a vector
414
414
*/
415
- fn push < T : copy > ( & v : [ T ] , initval : T ) {
415
+ fn push < T : copy > ( & v : [ const T ] , initval : T ) {
416
416
v += [ initval ] ;
417
417
}
418
418
@@ -432,7 +432,7 @@ v - The vector to grow
432
432
n - The number of elements to add
433
433
initval - The value for the new elements
434
434
*/
435
- fn grow < T : copy > ( & v : [ T ] , n : uint , initval : T ) {
435
+ fn grow < T : copy > ( & v : [ const T ] , n : uint , initval : T ) {
436
436
reserve ( v , next_power_of_two ( len ( v ) + n ) ) ;
437
437
let i: uint = 0 u;
438
438
while i < n { v += [ initval] ; i += 1 u; }
@@ -471,7 +471,7 @@ v - The vector to grow
471
471
n - The number of elements to add
472
472
init_op - A function to call to retreive each appended element's value
473
473
*/
474
- fn grow_fn < T > ( & v : [ T ] , n : uint , op : init_op < T > ) {
474
+ fn grow_fn < T > ( & v : [ const T ] , n : uint , op : init_op < T > ) {
475
475
reserve ( v , next_power_of_two ( len ( v ) + n ) ) ;
476
476
let i : uint = 0 u;
477
477
while i < n { v += [ op ( i) ] ; i += 1 u; }
@@ -527,7 +527,8 @@ Function: map2
527
527
528
528
Apply a function to each pair of elements and return the results
529
529
*/
530
- fn map2 < T : copy , U : copy , V > ( v0 : [ T ] , v1 : [ U ] , f : fn ( T , U ) -> V ) -> [ V ] {
530
+ fn map2 < T : copy , U : copy , V > ( v0 : [ const T ] , v1 : [ const U ] ,
531
+ f : fn ( T , U ) -> V ) -> [ V ] {
531
532
let v0_len = len ( v0) ;
532
533
if v0_len != len ( v1) { fail; }
533
534
let u: [ V ] = [ ] ;
@@ -645,7 +646,7 @@ Return true if a predicate matches any elements in both vectors.
645
646
646
647
If the vectors contains no elements then false is returned.
647
648
*/
648
- fn any2 < T , U > ( v0 : [ T ] , v1 : [ U ] , f : fn ( T , U ) -> bool ) -> bool {
649
+ fn any2 < T , U > ( v0 : [ const T ] , v1 : [ U ] , f : fn ( T , U ) -> bool ) -> bool {
649
650
let v0_len = len ( v0) ;
650
651
let v1_len = len ( v1) ;
651
652
let i = 0 u;
@@ -675,7 +676,7 @@ Return true if a predicate matches all elements in both vectors.
675
676
676
677
If the vectors are not the same size then false is returned.
677
678
*/
678
- fn all2 < T , U > ( v0 : [ T ] , v1 : [ U ] , f : fn ( T , U ) -> bool ) -> bool {
679
+ fn all2 < T , U > ( v0 : [ const T ] , v1 : [ const U ] , f : fn ( T , U ) -> bool ) -> bool {
679
680
let v0_len = len ( v0) ;
680
681
if v0_len != len ( v1) { ret false ; }
681
682
let i = 0 u;
@@ -688,7 +689,7 @@ Function: contains
688
689
689
690
Return true if a vector contains an element with the given value
690
691
*/
691
- fn contains < T > ( v : [ T ] , x : T ) -> bool {
692
+ fn contains < T > ( v : [ const T ] , x : T ) -> bool {
692
693
for elt: T in v { if x == elt { ret true ; } }
693
694
ret false;
694
695
}
@@ -713,7 +714,7 @@ Apply function `f` to each element of `v`, starting from the first.
713
714
When function `f` returns true then an option containing the element
714
715
is returned. If `f` matches no elements then none is returned.
715
716
*/
716
- fn find < T : copy > ( v : [ T ] , f : fn ( T ) -> bool ) -> option < T > {
717
+ fn find < T : copy > ( v : [ const T ] , f : fn ( T ) -> bool ) -> option < T > {
717
718
find_from ( v, 0 u, len ( v) , f)
718
719
}
719
720
@@ -726,8 +727,8 @@ Apply function `f` to each element of `v` within the range [`start`, `end`).
726
727
When function `f` returns true then an option containing the element
727
728
is returned. If `f` matches no elements then none is returned.
728
729
*/
729
- fn find_from < T : copy > ( v : [ T ] , start : uint , end : uint , f : fn ( T ) -> bool ) ->
730
- option < T > {
730
+ fn find_from < T : copy > ( v : [ const T ] , start : uint , end : uint ,
731
+ f : fn ( T ) -> bool ) -> option < T > {
731
732
option:: map ( position_from ( v, start, end, f) ) { |i| v[ i] }
732
733
}
733
734
@@ -740,7 +741,7 @@ Apply function `f` to each element of `v` in reverse order. When function `f`
740
741
returns true then an option containing the element is returned. If `f`
741
742
matches no elements then none is returned.
742
743
*/
743
- fn rfind < T : copy > ( v : [ T ] , f : fn ( T ) -> bool ) -> option < T > {
744
+ fn rfind < T : copy > ( v : [ const T ] , f : fn ( T ) -> bool ) -> option < T > {
744
745
rfind_from ( v, 0 u, len ( v) , f)
745
746
}
746
747
@@ -753,8 +754,8 @@ Apply function `f` to each element of `v` in reverse order within the range
753
754
[`start`, `end`). When function `f` returns true then an option containing
754
755
the element is returned. If `f` matches no elements then none is returned.
755
756
*/
756
- fn rfind_from < T : copy > ( v : [ T ] , start : uint , end : uint , f : fn ( T ) -> bool ) ->
757
- option < T > {
757
+ fn rfind_from < T : copy > ( v : [ const T ] , start : uint , end : uint ,
758
+ f : fn ( T ) -> bool ) -> option < T > {
758
759
option:: map ( rposition_from ( v, start, end, f) ) { |i| v[ i] }
759
760
}
760
761
@@ -768,7 +769,7 @@ Returns:
768
769
option::some(uint) - The first index containing a matching value
769
770
option::none - No elements matched
770
771
*/
771
- fn position_elt < T > ( v : [ T ] , x : T ) -> option < uint > {
772
+ fn position_elt < T > ( v : [ const T ] , x : T ) -> option < uint > {
772
773
position ( v) { |y| x == y }
773
774
}
774
775
@@ -781,7 +782,7 @@ Apply function `f` to each element of `v`. When function `f` returns true
781
782
then an option containing the index is returned. If `f` matches no elements
782
783
then none is returned.
783
784
*/
784
- fn position < T > ( v : [ T ] , f : fn ( T ) -> bool ) -> option < uint > {
785
+ fn position < T > ( v : [ const T ] , f : fn ( T ) -> bool ) -> option < uint > {
785
786
position_from ( v, 0 u, len ( v) , f)
786
787
}
787
788
@@ -794,8 +795,8 @@ Apply function `f` to each element of `v` between the range [`start`, `end`).
794
795
When function `f` returns true then an option containing the index is
795
796
returned. If `f` matches no elements then none is returned.
796
797
*/
797
- fn position_from < T > ( v : [ T ] , start : uint , end : uint , f : fn ( T ) -> bool ) ->
798
- option < uint > {
798
+ fn position_from < T > ( v : [ const T ] , start : uint , end : uint ,
799
+ f : fn ( T ) -> bool ) -> option < uint > {
799
800
assert start <= end;
800
801
assert end <= len ( v) ;
801
802
let i = start;
@@ -813,7 +814,7 @@ Returns:
813
814
option::some(uint) - The last index containing a matching value
814
815
option::none - No elements matched
815
816
*/
816
- fn rposition_elt < T > ( v : [ T ] , x : T ) -> option < uint > {
817
+ fn rposition_elt < T > ( v : [ const T ] , x : T ) -> option < uint > {
817
818
rposition ( v) { |y| x == y }
818
819
}
819
820
@@ -826,7 +827,7 @@ Apply function `f` to each element of `v` in reverse order. When function
826
827
`f` returns true then an option containing the index is returned. If `f`
827
828
matches no elements then none is returned.
828
829
*/
829
- fn rposition < T > ( v : [ T ] , f : fn ( T ) -> bool ) -> option < uint > {
830
+ fn rposition < T > ( v : [ const T ] , f : fn ( T ) -> bool ) -> option < uint > {
830
831
rposition_from ( v, 0 u, len ( v) , f)
831
832
}
832
833
@@ -839,8 +840,8 @@ Apply function `f` to each element of `v` in reverse order between the range
839
840
[`start`, `end`). When function `f` returns true then an option containing
840
841
the index is returned. If `f` matches no elements then none is returned.
841
842
*/
842
- fn rposition_from < T > ( v : [ T ] , start : uint , end : uint , f : fn ( T ) -> bool ) ->
843
- option < uint > {
843
+ fn rposition_from < T > ( v : [ const T ] , start : uint , end : uint ,
844
+ f : fn ( T ) -> bool ) -> option < uint > {
844
845
assert start <= end;
845
846
assert end <= len ( v) ;
846
847
let i = end;
@@ -865,7 +866,7 @@ vector contains the first element of the i-th tuple of the input vector,
865
866
and the i-th element of the second vector contains the second element
866
867
of the i-th tuple of the input vector.
867
868
*/
868
- fn unzip < T : copy , U : copy > ( v : [ ( T , U ) ] ) -> ( [ T ] , [ U ] ) {
869
+ fn unzip < T : copy , U : copy > ( v : [ const ( T , U ) ] ) -> ( [ T ] , [ U ] ) {
869
870
let as = [ ] , bs = [ ] ;
870
871
for ( a, b) in v { as += [ a] ; bs += [ b] ; }
871
872
ret ( as, bs) ;
@@ -883,7 +884,7 @@ Preconditions:
883
884
884
885
<same_length> (v, u)
885
886
*/
886
- fn zip < T : copy , U : copy > ( v : [ T ] , u : [ U ] ) -> [ ( T , U ) ] {
887
+ fn zip < T : copy , U : copy > ( v : [ const T ] , u : [ const U ] ) -> [ ( T , U ) ] {
887
888
let zipped = [ ] ;
888
889
let sz = len ( v) , i = 0 u;
889
890
assert sz == len ( u) ;
@@ -979,7 +980,7 @@ Function: iter2
979
980
Iterates over two vectors in parallel
980
981
981
982
*/
982
- fn iter2 < U , T > ( v : [ U ] , v2 : [ T ] , f : fn ( U , T ) ) {
983
+ fn iter2 < U , T > ( v : [ U ] , v2 : [ const T ] , f : fn ( U , T ) ) {
983
984
let i = 0 ;
984
985
for elt in v { f ( elt, v2[ i] ) ; i += 1 ; }
985
986
}
@@ -1036,7 +1037,7 @@ is sorted then the permutations are lexicographically sorted).
1036
1037
The total number of permutations produced is `len(v)!`. If `v` contains
1037
1038
repeated elements, then some permutations are repeated.
1038
1039
*/
1039
- fn permute < T : copy > ( v : [ const T ] , put : fn ( [ T ] ) ) {
1040
+ fn permute < T : copy > ( v : [ T ] , put : fn ( [ T ] ) ) {
1040
1041
let ln = len ( v) ;
1041
1042
if ln == 0 u {
1042
1043
put ( [ ] ) ;
@@ -1051,7 +1052,7 @@ fn permute<T: copy>(v: [const T], put: fn([T])) {
1051
1052
}
1052
1053
}
1053
1054
1054
- fn windowed < TT : copy > ( nn : uint , xx : [ TT ] ) -> [ [ TT ] ] {
1055
+ fn windowed < TT : copy > ( nn : uint , xx : [ const TT ] ) -> [ [ TT ] ] {
1055
1056
let ww = [ ] ;
1056
1057
1057
1058
assert 1 u <= nn;
0 commit comments