1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
//! Rust implementation of the [wyhash algorithm by Wang Yi][original].
//!
//! The hashing algorithm passes SMHasher and the random number generator
//! passes BigCrush and practrand.
//! As of now it is the fastest algorithm in the SMHasher benchmark
//! (faster than t1ha and XXH3).
//! See [here][original].
//!
//! Furthermore, this algorithm is solid, simple, portable (does not need
//! hardware support, can be used in `no_std` environments) and has
//! no dependencies.
//!
//! The generated hashes are equal (see tests) as of the version stated
//! [here][original-version] although the speed varies
//! ([PRs are welcome][issue-tracker]).
//!
//! [issue-tracker]: https://github.com/eldruin/wyhash-rs/issues
//! [original]: https://github.com/wangyi-fudan/wyhash
//! [original-version]: https://github.com/eldruin/wyhash-rs/blob/master/comparison/original/CMakeLists.txt
//!
//! ## Crate features
//!
//! By default this crate uses 128-bit integer multiplications.
//! To restrict that to 64 bits you can enable the feature `mum32bit`. This offers better
//! performance on 32-bit architectures.
//! Beware that this feature produces different the results.
//!
//! ## Usage (see also examples folder)
//!
//! For the hashing function you can use either the free function or the
//! `Hasher` trait.
//!
//! ### `wyhash` function usage
//!
//! ```
//! use wyhash::wyhash;
//!
//! let data = [0, 1, 2];
//! let seed = 3;
//! let hash = wyhash(&data, seed);
//!
//! println!("{:x}", hash); // prints b0f941520b1ad95d
//! ```
//!
//! ### `Hasher` trait usage
//!
//! You can also use `std::hash::Hasher`, it is the same.
//!
//! ```
//! use core::hash::Hasher;
//! use wyhash::WyHash;
//!
//! let mut hasher = WyHash::with_seed(3);
//! hasher.write(&[0, 1, 2]);
//!
//! println!("{:x}", hasher.finish()); // prints b0f941520b1ad95d
//! ```
//!
//! ### `wyrng` function usage
//!
//! Note that the seed parameter is updated so that it is possible to
//! generate a sequence of random numbers.
//!
//! ```
//! use wyhash::wyrng;
//!
//! let mut seed = 3;
//! let random_number = wyrng(&mut seed);
//!
//! println!("{:x}", random_number); // prints 3e99a772750dcbe
//! println!("{:x}", seed); //prints a0761d6478bd6432
//! ```
//!
//! ### `RngCore` trait usage
//!
//! You can also use `rand::Rng`, it is the same.
//!
//! ```
//! use rand_core::RngCore;
//! use wyhash::WyRng;
//!
//! let mut rng = WyRng::default();
//! println!("{:x}", rng.next_u64()); // prints 111cb3a78f59a58e
//! ```
//!
//! ### `SeedableRng` trait usage
//!
//! You can also use `rand::SeedableRng`, it is the same.
//!
//! ```
//! use rand_core::{RngCore, SeedableRng};
//! use wyhash::WyRng;
//!
//! // Seeds are 8-byte long.
//! let seed = [0, 1, 2, 3, 4, 5, 6, 7];
//! let mut rng1 = WyRng::from_seed(seed);
//! println!("{:x}", rng1.next_u64()); // prints d730135774c6ae31
//!
//! // Alternatively you can also use this convenience method:
//! let mut rng2 = WyRng::seed_from_u64(3);
//! println!("{:x}", rng2.next_u64()); // prints 3e99a772750dcbe
//! ```
/// WyHash version 1
pub use crate;
pub use crate;
/// WyHash version final 3