xref: /aosp_15_r20/external/erofs-utils/lib/xxhash.h (revision 33b1fccf6a0fada2c2875d400ed01119b7676ee5)
1*33b1fccfSAndroid Build Coastguard Worker /* SPDX-License-Identifier: BSD-2-Clause OR GPL-2.0+ */
2*33b1fccfSAndroid Build Coastguard Worker #ifndef __EROFS_LIB_XXHASH_H
3*33b1fccfSAndroid Build Coastguard Worker #define __EROFS_LIB_XXHASH_H
4*33b1fccfSAndroid Build Coastguard Worker 
5*33b1fccfSAndroid Build Coastguard Worker #ifdef __cplusplus
6*33b1fccfSAndroid Build Coastguard Worker extern "C"
7*33b1fccfSAndroid Build Coastguard Worker {
8*33b1fccfSAndroid Build Coastguard Worker #endif
9*33b1fccfSAndroid Build Coastguard Worker 
10*33b1fccfSAndroid Build Coastguard Worker #include <stdint.h>
11*33b1fccfSAndroid Build Coastguard Worker 
12*33b1fccfSAndroid Build Coastguard Worker /*
13*33b1fccfSAndroid Build Coastguard Worker  * xxh32() - calculate the 32-bit hash of the input with a given seed.
14*33b1fccfSAndroid Build Coastguard Worker  *
15*33b1fccfSAndroid Build Coastguard Worker  * @input:  The data to hash.
16*33b1fccfSAndroid Build Coastguard Worker  * @length: The length of the data to hash.
17*33b1fccfSAndroid Build Coastguard Worker  * @seed:   The seed can be used to alter the result predictably.
18*33b1fccfSAndroid Build Coastguard Worker  *
19*33b1fccfSAndroid Build Coastguard Worker  * Return:  The 32-bit hash of the data.
20*33b1fccfSAndroid Build Coastguard Worker  */
21*33b1fccfSAndroid Build Coastguard Worker uint32_t xxh32(const void *input, size_t length, uint32_t seed);
22*33b1fccfSAndroid Build Coastguard Worker 
23*33b1fccfSAndroid Build Coastguard Worker /*
24*33b1fccfSAndroid Build Coastguard Worker  * xxh64() - calculate the 64-bit hash of the input with a given seed.
25*33b1fccfSAndroid Build Coastguard Worker  *
26*33b1fccfSAndroid Build Coastguard Worker  * @input:  The data to hash.
27*33b1fccfSAndroid Build Coastguard Worker  * @length: The length of the data to hash.
28*33b1fccfSAndroid Build Coastguard Worker  * @seed:   The seed can be used to alter the result predictably.
29*33b1fccfSAndroid Build Coastguard Worker  *
30*33b1fccfSAndroid Build Coastguard Worker  * This function runs 2x faster on 64-bit systems, but slower on 32-bit systems.
31*33b1fccfSAndroid Build Coastguard Worker  *
32*33b1fccfSAndroid Build Coastguard Worker  * Return:  The 64-bit hash of the data.
33*33b1fccfSAndroid Build Coastguard Worker  */
34*33b1fccfSAndroid Build Coastguard Worker uint64_t xxh64(const void *input, const size_t len, const uint64_t seed);
35*33b1fccfSAndroid Build Coastguard Worker 
36*33b1fccfSAndroid Build Coastguard Worker #ifdef __cplusplus
37*33b1fccfSAndroid Build Coastguard Worker }
38*33b1fccfSAndroid Build Coastguard Worker #endif
39*33b1fccfSAndroid Build Coastguard Worker 
40*33b1fccfSAndroid Build Coastguard Worker #endif
41