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) {
}
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, || {
// 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();
// 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> {