Version
menu_open
link
Wwise SDK 2021.1.14
AkMurMurHash.h
Go to the documentation of this file.
1 /*******************************************************************************
2 The content of this file includes portions of the AUDIOKINETIC Wwise Technology
3 released in source code form as part of the SDK installer package.
4 
5 Commercial License Usage
6 
7 Licensees holding valid commercial licenses to the AUDIOKINETIC Wwise Technology
8 may use this file in accordance with the end user license agreement provided
9 with the software or, alternatively, in accordance with the terms contained in a
10 written agreement between you and Audiokinetic Inc.
11 
12 Apache License Usage
13 
14 Alternatively, this file may be used under the Apache License, Version 2.0 (the
15 "Apache License"); you may not use this file except in compliance with the
16 Apache License. You may obtain a copy of the Apache License at
17 http://www.apache.org/licenses/LICENSE-2.0.
18 
19 Unless required by applicable law or agreed to in writing, software distributed
20 under the Apache License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES
21 OR CONDITIONS OF ANY KIND, either express or implied. See the Apache License for
22 the specific language governing permissions and limitations under the License.
23 
24 Version: v2021.1.14 Build: 6590
25 Copyright (c) 2006-2023 Audiokinetic Inc.
26 *******************************************************************************/
27 
28 #ifndef _AKMURMURHASH_H_
29 #define _AKMURMURHASH_H_
30 
33 
34 // https://github.com/aappleby/smhasher/blob/master/src/MurmurHash3.cpp
35 
36 #define MURMUR3_SEED ( 0x41545731 )
37 #define MURMUR3_C1 ( 0xcc9e2d51 )
38 #define MURMUR3_C2 ( 0x1b873593 )
39 #define MURMUR3_C3 ( 0xe6546b64 )
40 
42 {
43  uValue ^= uValue >> 16;
44  uValue *= 0x85ebca6b;
45  uValue ^= uValue >> 13;
46  uValue *= 0xc2b2ae35;
47  uValue ^= uValue >> 16;
48  return uValue;
49 }
50 
52  uValue ^= uValue >> 33;
53  uValue *= 0xff51afd7ed558ccd;
54  uValue ^= uValue >> 33;
55  uValue *= 0xc4ceb9fe1a85ec53;
56  uValue ^= uValue >> 33;
57  return uValue;
58 }
59 
60 AkForceInline void AkHashMurMur32( AkUInt32* pHash, const void* pData, size_t uSize ) {
61  AkUInt32 uH1 = MURMUR3_SEED;
62  AkUInt8* pBytes = ( AkUInt8* )pData;
63  AkUInt32 uNumBlocks = ( AkUInt32 )( uSize / 4 );
64  AkUInt32* pBlocks = ( AkUInt32* )( pBytes + ( uNumBlocks * 4 ) );
65  for ( AkInt32 i = -( AkInt32 )uNumBlocks; i; ++i ) {
66  AkUInt32 uK1 = *( AkUInt32* )( pBlocks + i );
67  uK1 *= MURMUR3_C1;
68  uK1 = AK::ROTL32( uK1, 15 );
69  uK1 *= MURMUR3_C2;
70  uH1 ^= uK1;
71  uH1 = AK::ROTL32( uH1, 13 );
72  uH1 = uH1 * 5 + MURMUR3_C3;
73  }
74  AkUInt8* pBytesTail = ( AkUInt8* )( pBytes + ( uNumBlocks * 4 ) );
75  AkUInt32 uK1 = 0;
76  switch ( uSize & 3 ) {
77  case 3: uK1 ^= pBytesTail[ 2 ] << 16;
78  case 2: uK1 ^= pBytesTail[ 1 ] << 8;
79  case 1: uK1 ^= pBytesTail[ 0 ];
80  uK1 *= MURMUR3_C1;
81  uK1 = AK::ROTL32( uK1, 15 );
82  uK1 *= MURMUR3_C2;
83  uH1 ^= uK1;
84  }
85  uH1 ^= uSize;
86  uH1 = AkHashMurMurMix32( uH1 );
87  *pHash = uH1;
88 }
89 
90 #endif // _AKMURMURHASH_H_
AkForceInline AkUInt32 AkHashMurMurMix32(AkUInt32 uValue)
Definition: AkMurMurHash.h:41
#define MURMUR3_C3
Definition: AkMurMurHash.h:39
uint8_t AkUInt8
Unsigned 8-bit integer.
Definition: AkTypes.h:57
AkForceInline AkUInt32 ROTL32(AkUInt32 x, AkUInt32 r)
Definition: AkPlatformFuncs.h:144
#define MURMUR3_SEED
Definition: AkMurMurHash.h:36
uint64_t AkUInt64
Unsigned 64-bit integer.
Definition: AkTypes.h:60
#define MURMUR3_C2
Definition: AkMurMurHash.h:38
AkForceInline void AkHashMurMur32(AkUInt32 *pHash, const void *pData, size_t uSize)
Definition: AkMurMurHash.h:60
#define MURMUR3_C1
Definition: AkMurMurHash.h:37
uint32_t AkUInt32
Unsigned 32-bit integer.
Definition: AkTypes.h:59
int32_t AkInt32
Signed 32-bit integer.
Definition: AkTypes.h:64
#define AkForceInline
Definition: AkTypes.h:60
AkForceInline AkUInt64 AkHashMurMurMix64(AkUInt64 uValue)
Definition: AkMurMurHash.h:51

Was this page helpful?

Need Support?

Questions? Problems? Need more info? Contact us, and we can help!

Visit our Support page

Tell us about your project. We're here to help.

Register your project and we'll help you get started with no strings attached!

Get started with Wwise