diff --git a/src/libcore/rand.rs b/src/libcore/rand.rs index 753bdd87fa1f..f935f14f4b48 100644 --- a/src/libcore/rand.rs +++ b/src/libcore/rand.rs @@ -165,12 +165,12 @@ impl Rng { } /// Choose an item randomly, failing if values is empty - fn choose(values: ~[T]) -> T { + fn choose(values: &[T]) -> T { self.choose_option(values).get() } /// Choose Some(item) randomly, returning None if values is empty - fn choose_option(values: ~[T]) -> Option { + fn choose_option(values: &[T]) -> Option { if values.is_empty() { None } else { @@ -182,7 +182,7 @@ impl Rng { * Choose an item respecting the relative weights, failing if the sum of * the weights is 0 */ - fn choose_weighted(v : ~[Weighted]) -> T { + fn choose_weighted(v : &[Weighted]) -> T { self.choose_weighted_option(v).get() } @@ -190,7 +190,7 @@ impl Rng { * Choose Some(item) respecting the relative weights, returning none if * the sum of the weights is 0 */ - fn choose_weighted_option(v: ~[Weighted]) -> Option { + fn choose_weighted_option(v: &[Weighted]) -> Option { let mut total = 0u; for v.each |item| { total += item.weight; @@ -213,7 +213,7 @@ impl Rng { * Return a vec containing copies of the items, in order, where * the weight of the item determines how many copies there are */ - fn weighted_vec(v: ~[Weighted]) -> ~[T] { + fn weighted_vec(v: &[Weighted]) -> ~[T] { let mut r = ~[]; for v.each |item| { for uint::range(0u, item.weight) |_i| { @@ -224,14 +224,14 @@ impl Rng { } /// Shuffle a vec - fn shuffle(values: ~[T]) -> ~[T] { - let mut m = vec::to_mut(values); + fn shuffle(values: &[T]) -> ~[T] { + let mut m = vec::from_slice(values); self.shuffle_mut(m); - return vec::from_mut(m); + return m; } /// Shuffle a mutable vec in place - fn shuffle_mut(&&values: ~[mut T]) { + fn shuffle_mut(values: &[mut T]) { let mut i = values.len(); while i >= 2u { // invariant: elements with index >= i have been locked in place. @@ -402,14 +402,14 @@ mod tests { #[test] fn choose() { let r = rand::Rng(); - assert r.choose(~[1, 1, 1]) == 1; + assert r.choose([1, 1, 1]) == 1; } #[test] fn choose_option() { let r = rand::Rng(); - assert r.choose_option(~[]).is_none(); - assert r.choose_option(~[1, 1, 1]) == Some(1); + assert r.choose_option::([]).is_none(); + assert r.choose_option([1, 1, 1]) == Some(1); } #[test] @@ -431,7 +431,7 @@ mod tests { {weight: 0u, item: 42}, {weight: 1u, item: 43} ]) == Some(43); - assert r.choose_weighted_option(~[]).is_none(); + assert r.choose_weighted_option::([]).is_none(); } #[test] diff --git a/src/libcore/vec.rs b/src/libcore/vec.rs index edf154a2db54..db564fc4a6f3 100644 --- a/src/libcore/vec.rs +++ b/src/libcore/vec.rs @@ -1086,7 +1086,7 @@ pure fn zip(+v: ~[const T], +u: ~[const U]) -> ~[(T, U)] { * * a - The index of the first element * * b - The index of the second element */ -fn swap(&&v: ~[mut T], a: uint, b: uint) { +fn swap(v: &[mut T], a: uint, b: uint) { v[a] <-> v[b]; }