- Separated Platform and Compiler Dependent Behaviour into CMake scripts
- Implemented Basic Platform Interfaces
- Implemented partial Linux platform and Wayland Display.
- Implemented Dependencies for the above
- map
- set
- optional
- pair
TODO: threading
This commit is contained in:
89
include/fennec/lang/hashing.h
Normal file
89
include/fennec/lang/hashing.h
Normal file
@@ -0,0 +1,89 @@
|
||||
// =====================================================================================================================
|
||||
// fennec, a free and open source game engine
|
||||
// Copyright © 2025 Medusa Slockbower
|
||||
//
|
||||
// This program 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, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program 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 this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
// =====================================================================================================================
|
||||
|
||||
#ifndef FENNEC_LANG_HASHING_H
|
||||
#define FENNEC_LANG_HASHING_H
|
||||
|
||||
#include <fennec/lang/types.h>
|
||||
#include <fennec/lang/type_traits.h>
|
||||
|
||||
namespace fennec
|
||||
{
|
||||
|
||||
///
|
||||
/// \brief Struct for hashing types, there is no default hashing function
|
||||
/// \tparam Key The type to hash
|
||||
template<typename Key> struct hash;
|
||||
|
||||
// Murmur3 Hash for 64-bit ints
|
||||
template<>
|
||||
struct hash<uint64_t> {
|
||||
using type_t = uint64_t;
|
||||
constexpr size_t operator()(uint64_t x) const {
|
||||
// Murmur3
|
||||
x ^= x >> 33U;
|
||||
x *= 0xff51afd7ed558ccd;
|
||||
x ^= x >> 33U;
|
||||
x *= 0xc4ceb9fe1a85ec53;
|
||||
x ^= x >> 33U;
|
||||
return x;
|
||||
}
|
||||
};
|
||||
|
||||
// Wrapper for casting ints
|
||||
template<typename IntT>
|
||||
requires is_integral_v<IntT>
|
||||
struct hash<IntT> : hash<uint64_t> {
|
||||
using type_t = IntT;
|
||||
};
|
||||
|
||||
// Wrapper for pointers
|
||||
template<typename PtrT>
|
||||
requires is_pointer_v<PtrT>
|
||||
struct hash<PtrT> : hash<uintptr_t> {
|
||||
};
|
||||
|
||||
// Float
|
||||
template<>
|
||||
struct hash<float> : hash<uint32_t> {
|
||||
constexpr size_t operator()(float x) const {
|
||||
return hash<uint32_t>::operator()(bit_cast<uint32_t>(x));
|
||||
}
|
||||
};
|
||||
|
||||
template<>
|
||||
struct hash<double> : hash<uint64_t> {
|
||||
constexpr size_t operator()(double x) const {
|
||||
return hash<uint64_t>::operator()(bit_cast<uint64_t>(x));
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
///
|
||||
/// \brief Pairs two hashes
|
||||
/// \param x first hash
|
||||
/// \param y second hash
|
||||
/// \returns a pairing of the two hashes
|
||||
constexpr size_t pair_hash(size_t x, size_t y) {
|
||||
// Szudzik Pairing
|
||||
return (x >= y ? (x * x) + x + y : (y * y) + x);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif // FENNEC_LANG_HASHING_H
|
||||
Reference in New Issue
Block a user