about summary refs log tree commit diff
diff options
context:
space:
mode:
authorNiko Matsakis <niko@alum.mit.edu>2012-08-27 19:55:18 -0700
committerNiko Matsakis <niko@alum.mit.edu>2012-08-27 19:56:42 -0700
commit206edf66c92e12f1d98b56ea48a340e7e86d8552 (patch)
tree8689810e01108282b0c311132f4893783996df0d
parent0a01d82f6f3e33ca742c8e985d2a4819faeafe40 (diff)
make rand code use slices
-rw-r--r--src/libcore/rand.rs26
-rw-r--r--src/libcore/vec.rs2
2 files changed, 14 insertions, 14 deletions
diff --git a/src/libcore/rand.rs b/src/libcore/rand.rs
index 753bdd87fa1..f935f14f4b4 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<T:copy>(values: ~[T]) -> T {
+    fn choose<T:copy>(values: &[T]) -> T {
         self.choose_option(values).get()
     }
 
     /// Choose Some(item) randomly, returning None if values is empty
-    fn choose_option<T:copy>(values: ~[T]) -> Option<T> {
+    fn choose_option<T:copy>(values: &[T]) -> Option<T> {
         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<T: copy>(v : ~[Weighted<T>]) -> T {
+    fn choose_weighted<T: copy>(v : &[Weighted<T>]) -> 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<T:copy>(v: ~[Weighted<T>]) -> Option<T> {
+    fn choose_weighted_option<T:copy>(v: &[Weighted<T>]) -> Option<T> {
         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<T:copy>(v: ~[Weighted<T>]) -> ~[T] {
+    fn weighted_vec<T:copy>(v: &[Weighted<T>]) -> ~[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<T:copy>(values: ~[T]) -> ~[T] {
-        let mut m = vec::to_mut(values);
+    fn shuffle<T:copy>(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<T>(&&values: ~[mut T]) {
+    fn shuffle_mut<T>(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::<int>([]).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::<int>([]).is_none();
     }
 
     #[test]
diff --git a/src/libcore/vec.rs b/src/libcore/vec.rs
index edf154a2db5..db564fc4a6f 100644
--- a/src/libcore/vec.rs
+++ b/src/libcore/vec.rs
@@ -1086,7 +1086,7 @@ pure fn zip<T, U>(+v: ~[const T], +u: ~[const U]) -> ~[(T, U)] {
  * * a - The index of the first element
  * * b - The index of the second element
  */
-fn swap<T>(&&v: ~[mut T], a: uint, b: uint) {
+fn swap<T>(v: &[mut T], a: uint, b: uint) {
     v[a] <-> v[b];
 }