]> git.lizzy.rs Git - rust.git/commitdiff
fix benchmarks
authorJorge Aparicio <japaricious@gmail.com>
Mon, 5 Jan 2015 13:23:55 +0000 (08:23 -0500)
committerJorge Aparicio <japaricious@gmail.com>
Mon, 5 Jan 2015 22:22:17 +0000 (17:22 -0500)
src/test/bench/core-set.rs
src/test/bench/shootout-k-nucleotide-pipes.rs
src/test/bench/shootout-meteor.rs

index 491d910f3517d7853742b2501aefa546d54aad84..1dcac9fe0742d5f6961a2c861eab1aeb92e54036 100644 (file)
@@ -61,12 +61,14 @@ fn contains(&self, k: &uint) -> bool { self.contains(k) }
 
 impl Results {
     pub fn bench_int<T:MutableSet<uint>,
-                     R: rand::Rng>(
+                     R:rand::Rng,
+                     F:FnMut() -> T>(
                      &mut self,
                      rng: &mut R,
                      num_keys: uint,
                      rand_cap: uint,
-                     f: || -> T) { {
+                     mut f: F) {
+        {
             let mut set = f();
             timed(&mut self.sequential_ints, || {
                 for i in range(0u, num_keys) {
@@ -103,11 +105,12 @@ pub fn bench_int<T:MutableSet<uint>,
     }
 
     pub fn bench_str<T:MutableSet<String>,
-                     R:rand::Rng>(
+                     R:rand::Rng,
+                     F:FnMut() -> T>(
                      &mut self,
                      rng: &mut R,
                      num_keys: uint,
-                     f: || -> T) {
+                     mut f: F) {
         {
             let mut set = f();
             timed(&mut self.sequential_strings, || {
index 8c0ec667332d39ce46a7afe65d80e32910970e36..e6ef6a8c8c9ec4da7841ca5e263852b94cb25933 100644 (file)
@@ -94,7 +94,9 @@ fn update_freq(mm: &mut HashMap<Vec<u8> , uint>, key: &[u8]) {
 // given a Vec<u8>, for each window call a function
 // i.e., for "hello" and windows of size four,
 // run it("hell") and it("ello"), then return "llo"
-fn windows_with_carry(bb: &[u8], nn: uint, it: |window: &[u8]|) -> Vec<u8> {
+fn windows_with_carry<F>(bb: &[u8], nn: uint, mut it: F) -> Vec<u8> where
+    F: FnMut(&[u8]),
+{
    let mut ii = 0u;
 
    let len = bb.len();
index 438775d8ba0a405f1686e52ad6e65c7c369e9780..cdc7617fec8b074f294cd4117988b1a19e9b6557 100644 (file)
 
 // returns an infinite iterator of repeated applications of f to x,
 // i.e. [x, f(x), f(f(x)), ...], as haskell iterate function.
-fn iterate<'a, T>(x: T, f: |&T|: 'a -> T) -> Iterate<'a, T> {
+fn iterate<T, F>(x: T, f: F) -> Iterate<T, F> where F: FnMut(&T) -> T {
     Iterate {f: f, next: x}
 }
-struct Iterate<'a, T> {
-    f: |&T|: 'a -> T,
+struct Iterate<T, F> where F: FnMut(&T) -> T {
+    f: F,
     next: T
 }
-impl<'a, T> Iterator for Iterate<'a, T> {
+impl<T, F> Iterator for Iterate<T, F> where F: FnMut(&T) -> T {
     type Item = T;
 
     fn next(&mut self) -> Option<T> {