1 use ahash::{AHasher, CallHasher, RandomState};
2 use std::hash::BuildHasher;
3
4 #[macro_use]
5 extern crate no_panic;
6
7 #[inline(never)]
8 #[no_panic]
hash_test_final(num: i32, string: &str) -> (u64, u64)9 fn hash_test_final(num: i32, string: &str) -> (u64, u64) {
10 use core::hash::Hasher;
11 let mut hasher1 = AHasher::new_with_keys(1, 2);
12 let mut hasher2 = AHasher::new_with_keys(3, 4);
13 hasher1.write_i32(num);
14 hasher2.write(string.as_bytes());
15 (hasher1.finish(), hasher2.finish())
16 }
17
18 #[inline(never)]
hash_test_final_wrapper(num: i32, string: &str)19 fn hash_test_final_wrapper(num: i32, string: &str) {
20 hash_test_final(num, string);
21 }
22
23 #[inline(never)]
24 #[no_panic]
hash_test_specialize(num: i32, string: &str) -> (u64, u64)25 fn hash_test_specialize(num: i32, string: &str) -> (u64, u64) {
26 let hasher1 = AHasher::new_with_keys(1, 2);
27 let hasher2 = AHasher::new_with_keys(1, 2);
28 (i32::get_hash(&num, hasher1), <[u8]>::get_hash(string.as_bytes(), hasher2))
29 }
30
31 #[inline(never)]
hash_test_random_wrapper(num: i32, string: &str)32 fn hash_test_random_wrapper(num: i32, string: &str) {
33 hash_test_specialize(num, string);
34 }
35
36 #[inline(never)]
37 #[no_panic]
hash_test_random(num: i32, string: &str) -> (u64, u64)38 fn hash_test_random(num: i32, string: &str) -> (u64, u64) {
39 let hasher1 = RandomState::with_seeds(1, 2, 3, 4).build_hasher();
40 let hasher2 = RandomState::with_seeds(1, 2, 3, 4).build_hasher();
41 (i32::get_hash(&num,hasher1), <[u8]>::get_hash(string.as_bytes(), hasher2))
42 }
43
44 #[inline(never)]
hash_test_specialize_wrapper(num: i32, string: &str)45 fn hash_test_specialize_wrapper(num: i32, string: &str) {
46 hash_test_specialize(num, string);
47 }
48
49 #[test]
test_no_panic()50 fn test_no_panic() {
51 hash_test_final_wrapper(2, "Foo");
52 hash_test_specialize_wrapper(2, "Bar");
53 hash_test_random_wrapper(2, "Baz");
54 }
55