mz_timely_util/hash.rs
1// Copyright Materialize, Inc. and contributors. All rights reserved.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License in the LICENSE file at the
6// root of this repository, or online at
7//
8// http://www.apache.org/licenses/LICENSE-2.0
9//
10// Unless required by applicable law or agreed to in writing, software
11// distributed under the License is distributed on an "AS IS" BASIS,
12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13// See the License for the specific language governing permissions and
14// limitations under the License.
15
16//! Deterministic hashing helpers.
17
18/// A fixed-seed [`ahash::RandomState`].
19///
20/// We fix the seeds explicitly rather than letting `ahash` randomize per process
21/// so that hashing is deterministic across runs, replicas, and — crucially —
22/// across builds that select `ahash`'s compile-time features differently. Cargo
23/// unions features across the workspace, so a `RandomState::new()` could pick a
24/// different hasher depending on what other dependencies enable; pinning the
25/// seeds avoids that. The seeds are the ones `ahash::AHasher::default()` would
26/// use. (Depending on target features `ahash` may fall back to its non-AES
27/// hasher, which is still sufficient for our needs.)
28///
29/// Used wherever Materialize needs a stable hash: distributing data to workers
30/// during consolidation ([`crate::operator`]) and the per-column codec summaries
31/// in `mz_row_spine`.
32pub fn fixed_state() -> ahash::RandomState {
33 ahash::RandomState::with_seeds(
34 0x243f_6a88_85a3_08d3,
35 0x1319_8a2e_0370_7344,
36 0xa409_3822_299f_31d0,
37 0x082e_fa98_ec4e_6c89,
38 )
39}