summaryrefslogtreecommitdiffstats
path: root/third_party/rust/ahash/tests/nopanic.rs
diff options
context:
space:
mode:
Diffstat (limited to 'third_party/rust/ahash/tests/nopanic.rs')
-rw-r--r--third_party/rust/ahash/tests/nopanic.rs35
1 files changed, 22 insertions, 13 deletions
diff --git a/third_party/rust/ahash/tests/nopanic.rs b/third_party/rust/ahash/tests/nopanic.rs
index d48ff559d2..56f754cbee 100644
--- a/third_party/rust/ahash/tests/nopanic.rs
+++ b/third_party/rust/ahash/tests/nopanic.rs
@@ -1,5 +1,5 @@
-use ahash::{AHasher, CallHasher, RandomState};
-use std::hash::BuildHasher;
+use ahash::{AHasher, RandomState};
+use std::hash::{BuildHasher, Hash, Hasher};
#[macro_use]
extern crate no_panic;
@@ -8,8 +8,8 @@ extern crate no_panic;
#[no_panic]
fn hash_test_final(num: i32, string: &str) -> (u64, u64) {
use core::hash::Hasher;
- let mut hasher1 = AHasher::new_with_keys(1, 2);
- let mut hasher2 = AHasher::new_with_keys(3, 4);
+ let mut hasher1 = RandomState::with_seeds(1, 2, 3, 4).build_hasher();
+ let mut hasher2 = RandomState::with_seeds(3, 4, 5, 6).build_hasher();
hasher1.write_i32(num);
hasher2.write(string.as_bytes());
(hasher1.finish(), hasher2.finish())
@@ -24,6 +24,17 @@ struct SimpleBuildHasher {
hasher: AHasher,
}
+impl SimpleBuildHasher {
+ fn hash_one<T: Hash>(&self, x: T) -> u64
+ where
+ Self: Sized,
+ {
+ let mut hasher = self.build_hasher();
+ x.hash(&mut hasher);
+ hasher.finish()
+ }
+}
+
impl BuildHasher for SimpleBuildHasher {
type Hasher = AHasher;
@@ -35,11 +46,11 @@ impl BuildHasher for SimpleBuildHasher {
#[inline(never)]
#[no_panic]
fn hash_test_specialize(num: i32, string: &str) -> (u64, u64) {
- let hasher1 = AHasher::new_with_keys(1, 2);
- let hasher2 = AHasher::new_with_keys(1, 2);
+ let hasher1 = RandomState::with_seeds(1, 2, 3, 4).build_hasher();
+ let hasher2 = RandomState::with_seeds(1, 2, 3, 4).build_hasher();
(
- i32::get_hash(&num, &SimpleBuildHasher { hasher: hasher1 }),
- <[u8]>::get_hash(string.as_bytes(), &SimpleBuildHasher { hasher: hasher2 }),
+ SimpleBuildHasher { hasher: hasher1 }.hash_one(num),
+ SimpleBuildHasher { hasher: hasher2 }.hash_one(string.as_bytes()),
)
}
@@ -53,10 +64,7 @@ fn hash_test_random_wrapper(num: i32, string: &str) {
fn hash_test_random(num: i32, string: &str) -> (u64, u64) {
let build_hasher1 = RandomState::with_seeds(1, 2, 3, 4);
let build_hasher2 = RandomState::with_seeds(1, 2, 3, 4);
- (
- i32::get_hash(&num, &build_hasher1),
- <[u8]>::get_hash(string.as_bytes(), &build_hasher2),
- )
+ (build_hasher1.hash_one(&num), build_hasher2.hash_one(string.as_bytes()))
}
#[inline(never)]
@@ -68,5 +76,6 @@ fn hash_test_specialize_wrapper(num: i32, string: &str) {
fn test_no_panic() {
hash_test_final_wrapper(2, "Foo");
hash_test_specialize_wrapper(2, "Bar");
- hash_test_random_wrapper(2, "Baz");
+ hash_test_random(2, "Baz");
+ hash_test_random_wrapper(2, "Bat");
}