pgx/misc.rs
1/*
2Portions Copyright 2019-2021 ZomboDB, LLC.
3Portions Copyright 2021-2022 Technology Concepts & Design, Inc. <support@tcdi.com>
4
5All rights reserved.
6
7Use of this source code is governed by the MIT license that can be found in the LICENSE file.
8*/
9use std::hash::{Hash, Hasher};
10
11/// wrapper around `SeaHasher` from [Seahash](https://crates.io/crates/seahash)
12///
13/// Primarily used by `pgx`'s `#[derive(PostgresHash)]` macro.
14pub fn pgx_seahash<T: Hash>(value: &T) -> u64 {
15 // taken from sources of "SeaHasher, v4.0.1" [Seahash](https://crates.io/crates/seahash)
16 // assuming the underlying implementation doesn't change, we
17 // also want to ensure however we seed it doesn't change either
18 //
19 // these hash values might be stored on disk by Postgres, so we can't afford
20 // to have them changing over time
21 let mut hasher = seahash::SeaHasher::with_seeds(
22 0x16f11fe89b0d677c,
23 0xb480a793d8e6c86c,
24 0x6fe2e5aaf078ebc9,
25 0x14f994a4c5259381,
26 );
27 value.hash(&mut hasher);
28 hasher.finish()
29}