Add a simple 32 bit to 32 bit hash function (MurmurHash3)

This commit is contained in:
Jonathan G Rennison
2022-06-13 01:08:03 +01:00
parent 65236bacc7
commit 67104b4dc1
2 changed files with 29 additions and 0 deletions

View File

@@ -11,6 +11,7 @@ add_files(
endian_func.hpp
endian_type.hpp
enum_type.hpp
hash_func.hpp
geometry_func.cpp
geometry_func.hpp
geometry_type.hpp

28
src/core/hash_func.hpp Normal file
View File

@@ -0,0 +1,28 @@
/*
* This file is part of OpenTTD.
* OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
* OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
*/
/** @file hash_func.hpp Functions related to hashing operations. */
#ifndef HASH_FUNC_HPP
#define HASH_FUNC_HPP
/**
* Simple 32 bit to 32 bit hash
* From MurmurHash3
*/
inline uint32 SimpleHash32(uint32 h)
{
h ^= h >> 16;
h *= 0x85ebca6b;
h ^= h >> 13;
h *= 0xc2b2ae35;
h ^= h >> 16;
return h;
}
#endif /* HASH_FUNC_HPP */