Skip to content

Commit 1878402

Browse files
committed
---
yaml --- r: 14559 b: refs/heads/try c: 99f231f h: refs/heads/master i: 14557: 7efaa9f 14555: 80fda81 14551: 3ec6daf 14543: 1d9fe27 14527: 11c1ec0 v: v3
1 parent 6cd0386 commit 1878402

File tree

2 files changed

+33
-32
lines changed

2 files changed

+33
-32
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
refs/heads/master: 61b1875c16de39c166b0f4d54bba19f9c6777d1a
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: 4a81779abd786ff22d71434c6d9a5917ea4cdfff
5-
refs/heads/try: 4132cbd22a139f0dace8cb914b63faf816b77ea3
5+
refs/heads/try: 99f231f3477c276c84b1335490c3942453095dad
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105

branches/try/src/libcore/vec.rs

Lines changed: 32 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ Predicate: same_length
5252
5353
Returns true if two vectors have the same length
5454
*/
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 {
5656
vec::len(xs) == vec::len(ys)
5757
}
5858

@@ -278,7 +278,7 @@ Function: split
278278
279279
Split the vector `v` by applying each element against the predicate `f`.
280280
*/
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]] {
282282
let ln = len(v);
283283
if (ln == 0u) { ret [] }
284284

@@ -303,7 +303,7 @@ Function: splitn
303303
Split the vector `v` by applying each element against the predicate `f` up
304304
to `n` times.
305305
*/
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]] {
307307
let ln = len(v);
308308
if (ln == 0u) { ret [] }
309309

@@ -331,7 +331,7 @@ Function: rsplit
331331
Reverse split the vector `v` by applying each element against the predicate
332332
`f`.
333333
*/
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]] {
335335
let ln = len(v);
336336
if (ln == 0u) { ret [] }
337337

@@ -356,7 +356,7 @@ Function: rsplitn
356356
Reverse split the vector `v` by applying each element against the predicate
357357
`f` up to `n times.
358358
*/
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]] {
360360
let ln = len(v);
361361
if (ln == 0u) { ret [] }
362362

@@ -412,7 +412,7 @@ Function: push
412412
413413
Append an element to a vector
414414
*/
415-
fn push<T: copy>(&v: [T], initval: T) {
415+
fn push<T: copy>(&v: [const T], initval: T) {
416416
v += [initval];
417417
}
418418

@@ -432,7 +432,7 @@ v - The vector to grow
432432
n - The number of elements to add
433433
initval - The value for the new elements
434434
*/
435-
fn grow<T: copy>(&v: [T], n: uint, initval: T) {
435+
fn grow<T: copy>(&v: [const T], n: uint, initval: T) {
436436
reserve(v, next_power_of_two(len(v) + n));
437437
let i: uint = 0u;
438438
while i < n { v += [initval]; i += 1u; }
@@ -471,7 +471,7 @@ v - The vector to grow
471471
n - The number of elements to add
472472
init_op - A function to call to retreive each appended element's value
473473
*/
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>) {
475475
reserve(v, next_power_of_two(len(v) + n));
476476
let i: uint = 0u;
477477
while i < n { v += [op(i)]; i += 1u; }
@@ -527,7 +527,8 @@ Function: map2
527527
528528
Apply a function to each pair of elements and return the results
529529
*/
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] {
531532
let v0_len = len(v0);
532533
if v0_len != len(v1) { fail; }
533534
let u: [V] = [];
@@ -645,7 +646,7 @@ Return true if a predicate matches any elements in both vectors.
645646
646647
If the vectors contains no elements then false is returned.
647648
*/
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 {
649650
let v0_len = len(v0);
650651
let v1_len = len(v1);
651652
let i = 0u;
@@ -675,7 +676,7 @@ Return true if a predicate matches all elements in both vectors.
675676
676677
If the vectors are not the same size then false is returned.
677678
*/
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 {
679680
let v0_len = len(v0);
680681
if v0_len != len(v1) { ret false; }
681682
let i = 0u;
@@ -688,7 +689,7 @@ Function: contains
688689
689690
Return true if a vector contains an element with the given value
690691
*/
691-
fn contains<T>(v: [T], x: T) -> bool {
692+
fn contains<T>(v: [const T], x: T) -> bool {
692693
for elt: T in v { if x == elt { ret true; } }
693694
ret false;
694695
}
@@ -713,7 +714,7 @@ Apply function `f` to each element of `v`, starting from the first.
713714
When function `f` returns true then an option containing the element
714715
is returned. If `f` matches no elements then none is returned.
715716
*/
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> {
717718
find_from(v, 0u, len(v), f)
718719
}
719720

@@ -726,8 +727,8 @@ Apply function `f` to each element of `v` within the range [`start`, `end`).
726727
When function `f` returns true then an option containing the element
727728
is returned. If `f` matches no elements then none is returned.
728729
*/
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> {
731732
option::map(position_from(v, start, end, f)) { |i| v[i] }
732733
}
733734

@@ -740,7 +741,7 @@ Apply function `f` to each element of `v` in reverse order. When function `f`
740741
returns true then an option containing the element is returned. If `f`
741742
matches no elements then none is returned.
742743
*/
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> {
744745
rfind_from(v, 0u, len(v), f)
745746
}
746747

@@ -753,8 +754,8 @@ Apply function `f` to each element of `v` in reverse order within the range
753754
[`start`, `end`). When function `f` returns true then an option containing
754755
the element is returned. If `f` matches no elements then none is returned.
755756
*/
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> {
758759
option::map(rposition_from(v, start, end, f)) { |i| v[i] }
759760
}
760761

@@ -768,7 +769,7 @@ Returns:
768769
option::some(uint) - The first index containing a matching value
769770
option::none - No elements matched
770771
*/
771-
fn position_elt<T>(v: [T], x: T) -> option<uint> {
772+
fn position_elt<T>(v: [const T], x: T) -> option<uint> {
772773
position(v) { |y| x == y }
773774
}
774775

@@ -781,7 +782,7 @@ Apply function `f` to each element of `v`. When function `f` returns true
781782
then an option containing the index is returned. If `f` matches no elements
782783
then none is returned.
783784
*/
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> {
785786
position_from(v, 0u, len(v), f)
786787
}
787788

@@ -794,8 +795,8 @@ Apply function `f` to each element of `v` between the range [`start`, `end`).
794795
When function `f` returns true then an option containing the index is
795796
returned. If `f` matches no elements then none is returned.
796797
*/
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> {
799800
assert start <= end;
800801
assert end <= len(v);
801802
let i = start;
@@ -813,7 +814,7 @@ Returns:
813814
option::some(uint) - The last index containing a matching value
814815
option::none - No elements matched
815816
*/
816-
fn rposition_elt<T>(v: [T], x: T) -> option<uint> {
817+
fn rposition_elt<T>(v: [const T], x: T) -> option<uint> {
817818
rposition(v) { |y| x == y }
818819
}
819820

@@ -826,7 +827,7 @@ Apply function `f` to each element of `v` in reverse order. When function
826827
`f` returns true then an option containing the index is returned. If `f`
827828
matches no elements then none is returned.
828829
*/
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> {
830831
rposition_from(v, 0u, len(v), f)
831832
}
832833

@@ -839,8 +840,8 @@ Apply function `f` to each element of `v` in reverse order between the range
839840
[`start`, `end`). When function `f` returns true then an option containing
840841
the index is returned. If `f` matches no elements then none is returned.
841842
*/
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> {
844845
assert start <= end;
845846
assert end <= len(v);
846847
let i = end;
@@ -865,7 +866,7 @@ vector contains the first element of the i-th tuple of the input vector,
865866
and the i-th element of the second vector contains the second element
866867
of the i-th tuple of the input vector.
867868
*/
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]) {
869870
let as = [], bs = [];
870871
for (a, b) in v { as += [a]; bs += [b]; }
871872
ret (as, bs);
@@ -883,7 +884,7 @@ Preconditions:
883884
884885
<same_length> (v, u)
885886
*/
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)] {
887888
let zipped = [];
888889
let sz = len(v), i = 0u;
889890
assert sz == len(u);
@@ -979,7 +980,7 @@ Function: iter2
979980
Iterates over two vectors in parallel
980981
981982
*/
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)) {
983984
let i = 0;
984985
for elt in v { f(elt, v2[i]); i += 1; }
985986
}
@@ -1036,7 +1037,7 @@ is sorted then the permutations are lexicographically sorted).
10361037
The total number of permutations produced is `len(v)!`. If `v` contains
10371038
repeated elements, then some permutations are repeated.
10381039
*/
1039-
fn permute<T: copy>(v: [const T], put: fn([T])) {
1040+
fn permute<T: copy>(v: [T], put: fn([T])) {
10401041
let ln = len(v);
10411042
if ln == 0u {
10421043
put([]);
@@ -1051,7 +1052,7 @@ fn permute<T: copy>(v: [const T], put: fn([T])) {
10511052
}
10521053
}
10531054

1054-
fn windowed <TT: copy> (nn: uint, xx: [TT]) -> [[TT]] {
1055+
fn windowed <TT: copy> (nn: uint, xx: [const TT]) -> [[TT]] {
10551056
let ww = [];
10561057

10571058
assert 1u <= nn;

0 commit comments

Comments
 (0)