1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 #![allow(non_snake_case)]
11 use fxhash::FxHashSet;
12 use std::collections::HashSet;
13 use std::os::raw::{c_char, c_void};
16 /// Keep this in sync with Params in Bench.cpp.
20 config_name: *const c_char,
22 num_successful_lookups: usize,
23 num_failing_lookups: usize,
24 num_iterations: usize,
29 pub extern "C" fn Bench_Rust_HashSet(
30 params: *const Params,
31 vals: *const *const c_void,
34 let hs: HashSet<_> = std::collections::HashSet::default();
35 Bench_Rust(hs, params, vals, len);
39 pub extern "C" fn Bench_Rust_FnvHashSet(
40 params: *const Params,
41 vals: *const *const c_void,
44 let hs = FnvHashSet::default();
45 Bench_Rust(hs, params, vals, len);
49 pub extern "C" fn Bench_Rust_FxHashSet(
50 params: *const Params,
51 vals: *const *const c_void,
54 let hs = FxHashSet::default();
55 Bench_Rust(hs, params, vals, len);
58 // Keep this in sync with all the other Bench_*() functions.
59 fn Bench_Rust<H: std::hash::BuildHasher>(
60 mut hs: HashSet<*const c_void, H>,
61 params: *const Params,
62 vals: *const *const c_void,
65 let params = unsafe { &*params };
66 let vals = unsafe { slice::from_raw_parts(vals, len) };
68 for j in 0..params.num_inserts {
72 for _i in 0..params.num_successful_lookups {
73 for j in 0..params.num_inserts {
74 assert!(hs.contains(&vals[j]));
78 for _i in 0..params.num_failing_lookups {
79 for j in params.num_inserts..params.num_inserts * 2 {
80 assert!(!hs.contains(&vals[j]));
84 for _i in 0..params.num_iterations {
89 assert!(params.num_inserts == n);
90 assert!(hs.len() == n);
93 if params.remove_inserts {
94 for j in 0..params.num_inserts {
95 assert!(hs.remove(&vals[j]));
97 assert!(hs.is_empty());
99 assert!(hs.len() == params.num_inserts);