1 // Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
11 // Checks for issue #26235
17 const NUM_THREADS: usize = 2;
27 impl<S> Stats<S> where S: Copy {
28 fn dot<B, F, T>(self, s: Stats<T>, f: F) -> Stats<B> where F: Fn(S, T) -> B {
29 let Stats { upsert: u1, delete: d1, insert: i1, update: p1 } = self;
30 let Stats { upsert: u2, delete: d2, insert: i2, update: p2 } = s;
31 Stats { upsert: f(u1, u2), delete: f(d1, d2), insert: f(i1, i2), update: f(p1, p2) }
34 fn new(init: S) -> Self {
35 Stats { upsert: init, delete: init, insert: init, update: init }
39 fn make_threads() -> Vec<thread::JoinHandle<()>> {
40 let mut t = Vec::with_capacity(NUM_THREADS);
41 for _ in 0..NUM_THREADS {
42 t.push(thread::spawn(move || {}));
47 let stats = [Stats::new(0); NUM_THREADS];
51 let Stats { ref upsert, ref delete, ref insert, ref update } = stats.iter().fold(
52 Stats::new(0), |res, &s| res.dot(s, |x: Key, y: Key| x.wrapping_add(y)));
53 println!("upserts: {}, deletes: {}, inserts: {}, updates: {}",
54 upsert, delete, insert, update);