mirror of
https://github.com/godotengine/godot.git
synced 2025-12-07 22:00:10 +00:00
Rewrite HashMapHasherDefault based on type traits - it is now possible to declare a default hashing function for any type.
Remove cross-project includes from `hashfuncs.h`. Improve hashing function for `Color` (based on values instead of `String`). Move `Variant` comparison from `hash_map.h` to `dictionary.cpp` (`VariantComparatorDictionary`), where it's used. Remove now unnecessary `HashableHasher`.
This commit is contained in:
parent
06827c91c6
commit
ad600125df
29 changed files with 253 additions and 222 deletions
|
|
@ -32,6 +32,7 @@
|
|||
|
||||
#include "core/math/plane.h"
|
||||
#include "core/math/vector3.h"
|
||||
#include "core/templates/hashfuncs.h"
|
||||
|
||||
/**
|
||||
* AABB (Axis Aligned Bounding Box)
|
||||
|
|
@ -131,6 +132,16 @@ struct [[nodiscard]] AABB {
|
|||
return position + (size * 0.5f);
|
||||
}
|
||||
|
||||
uint32_t hash() const {
|
||||
uint32_t h = hash_murmur3_one_real(position.x);
|
||||
h = hash_murmur3_one_real(position.y, h);
|
||||
h = hash_murmur3_one_real(position.z, h);
|
||||
h = hash_murmur3_one_real(size.x, h);
|
||||
h = hash_murmur3_one_real(size.y, h);
|
||||
h = hash_murmur3_one_real(size.z, h);
|
||||
return hash_fmix32(h);
|
||||
}
|
||||
|
||||
explicit operator String() const;
|
||||
|
||||
AABB() = default;
|
||||
|
|
|
|||
|
|
@ -31,6 +31,7 @@
|
|||
#pragma once
|
||||
|
||||
#include "core/math/math_funcs.h"
|
||||
#include "core/templates/hashfuncs.h"
|
||||
|
||||
class String;
|
||||
|
||||
|
|
@ -239,6 +240,14 @@ struct [[nodiscard]] Color {
|
|||
_FORCE_INLINE_ void set_ok_hsl_s(float p_s) { set_ok_hsl(get_ok_hsl_h(), p_s, get_ok_hsl_l(), a); }
|
||||
_FORCE_INLINE_ void set_ok_hsl_l(float p_l) { set_ok_hsl(get_ok_hsl_h(), get_ok_hsl_s(), p_l, a); }
|
||||
|
||||
uint32_t hash() const {
|
||||
uint32_t h = hash_murmur3_one_float(r);
|
||||
h = hash_murmur3_one_float(r, h);
|
||||
h = hash_murmur3_one_float(b, h);
|
||||
h = hash_murmur3_one_float(a, h);
|
||||
return hash_fmix32(h);
|
||||
}
|
||||
|
||||
constexpr Color() :
|
||||
r(0), g(0), b(0), a(1) {}
|
||||
|
||||
|
|
|
|||
|
|
@ -33,6 +33,7 @@
|
|||
#include "core/math/aabb.h"
|
||||
#include "core/math/projection.h"
|
||||
#include "core/math/vector3.h"
|
||||
#include "core/math/vector3i.h"
|
||||
#include "core/templates/a_hash_map.h"
|
||||
#include "core/templates/list.h"
|
||||
#include "core/templates/local_vector.h"
|
||||
|
|
|
|||
|
|
@ -30,8 +30,10 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include "core/math/color.h"
|
||||
#include "core/math/delaunay_3d.h"
|
||||
#include "core/math/face3.h"
|
||||
#include "core/math/vector2.h"
|
||||
#include "core/templates/local_vector.h"
|
||||
#include "core/templates/vector.h"
|
||||
|
||||
|
|
|
|||
|
|
@ -32,6 +32,7 @@
|
|||
|
||||
#include "core/error/error_macros.h"
|
||||
#include "core/math/vector2.h"
|
||||
#include "core/templates/hashfuncs.h"
|
||||
|
||||
class String;
|
||||
struct Rect2i;
|
||||
|
|
@ -361,6 +362,14 @@ struct [[nodiscard]] Rect2 {
|
|||
explicit operator String() const;
|
||||
operator Rect2i() const;
|
||||
|
||||
uint32_t hash() const {
|
||||
uint32_t h = hash_murmur3_one_real(position.x);
|
||||
h = hash_murmur3_one_real(position.y, h);
|
||||
h = hash_murmur3_one_real(size.x, h);
|
||||
h = hash_murmur3_one_real(size.y, h);
|
||||
return hash_fmix32(h);
|
||||
}
|
||||
|
||||
Rect2() = default;
|
||||
constexpr Rect2(real_t p_x, real_t p_y, real_t p_width, real_t p_height) :
|
||||
position(Point2(p_x, p_y)),
|
||||
|
|
|
|||
|
|
@ -32,6 +32,7 @@
|
|||
|
||||
#include "core/error/error_macros.h"
|
||||
#include "core/math/vector2i.h"
|
||||
#include "core/templates/hashfuncs.h"
|
||||
|
||||
class String;
|
||||
struct Rect2;
|
||||
|
|
@ -226,6 +227,14 @@ struct [[nodiscard]] Rect2i {
|
|||
explicit operator String() const;
|
||||
operator Rect2() const;
|
||||
|
||||
uint32_t hash() const {
|
||||
uint32_t h = hash_murmur3_one_32(uint32_t(position.x));
|
||||
h = hash_murmur3_one_32(uint32_t(position.y), h);
|
||||
h = hash_murmur3_one_32(uint32_t(size.x), h);
|
||||
h = hash_murmur3_one_32(uint32_t(size.y), h);
|
||||
return hash_fmix32(h);
|
||||
}
|
||||
|
||||
Rect2i() = default;
|
||||
constexpr Rect2i(int p_x, int p_y, int p_width, int p_height) :
|
||||
position(Point2i(p_x, p_y)),
|
||||
|
|
|
|||
|
|
@ -32,6 +32,7 @@
|
|||
|
||||
#include "core/error/error_macros.h"
|
||||
#include "core/math/math_funcs.h"
|
||||
#include "core/templates/hashfuncs.h"
|
||||
|
||||
class String;
|
||||
struct Vector2i;
|
||||
|
|
@ -190,6 +191,12 @@ struct [[nodiscard]] Vector2 {
|
|||
explicit operator String() const;
|
||||
operator Vector2i() const;
|
||||
|
||||
uint32_t hash() const {
|
||||
uint32_t h = hash_murmur3_one_real(x);
|
||||
h = hash_murmur3_one_real(y, h);
|
||||
return hash_fmix32(h);
|
||||
}
|
||||
|
||||
// NOLINTBEGIN(cppcoreguidelines-pro-type-member-init)
|
||||
constexpr Vector2() :
|
||||
x(0), y(0) {}
|
||||
|
|
|
|||
|
|
@ -32,6 +32,7 @@
|
|||
|
||||
#include "core/error/error_macros.h"
|
||||
#include "core/math/math_funcs.h"
|
||||
#include "core/templates/hashfuncs.h"
|
||||
|
||||
class String;
|
||||
struct Vector2;
|
||||
|
|
@ -147,6 +148,12 @@ struct [[nodiscard]] Vector2i {
|
|||
explicit operator String() const;
|
||||
operator Vector2() const;
|
||||
|
||||
uint32_t hash() const {
|
||||
uint32_t h = hash_murmur3_one_32(uint32_t(x));
|
||||
h = hash_murmur3_one_32(uint32_t(y), h);
|
||||
return hash_fmix32(h);
|
||||
}
|
||||
|
||||
// NOLINTBEGIN(cppcoreguidelines-pro-type-member-init)
|
||||
constexpr Vector2i() :
|
||||
x(0), y(0) {}
|
||||
|
|
|
|||
|
|
@ -214,6 +214,13 @@ struct [[nodiscard]] Vector3 {
|
|||
explicit operator String() const;
|
||||
operator Vector3i() const;
|
||||
|
||||
uint32_t hash() const {
|
||||
uint32_t h = hash_murmur3_one_real(x);
|
||||
h = hash_murmur3_one_real(y, h);
|
||||
h = hash_murmur3_one_real(z, h);
|
||||
return hash_fmix32(h);
|
||||
}
|
||||
|
||||
constexpr Vector3() :
|
||||
x(0), y(0), z(0) {}
|
||||
constexpr Vector3(real_t p_x, real_t p_y, real_t p_z) :
|
||||
|
|
|
|||
|
|
@ -32,6 +32,7 @@
|
|||
|
||||
#include "core/error/error_macros.h"
|
||||
#include "core/math/math_funcs.h"
|
||||
#include "core/templates/hashfuncs.h"
|
||||
|
||||
class String;
|
||||
struct Vector3;
|
||||
|
|
@ -140,6 +141,13 @@ struct [[nodiscard]] Vector3i {
|
|||
explicit operator String() const;
|
||||
operator Vector3() const;
|
||||
|
||||
uint32_t hash() const {
|
||||
uint32_t h = hash_murmur3_one_32(uint32_t(x));
|
||||
h = hash_murmur3_one_32(uint32_t(y), h);
|
||||
h = hash_murmur3_one_32(uint32_t(z), h);
|
||||
return hash_fmix32(h);
|
||||
}
|
||||
|
||||
constexpr Vector3i() :
|
||||
x(0), y(0), z(0) {}
|
||||
constexpr Vector3i(int32_t p_x, int32_t p_y, int32_t p_z) :
|
||||
|
|
|
|||
|
|
@ -32,6 +32,7 @@
|
|||
|
||||
#include "core/error/error_macros.h"
|
||||
#include "core/math/math_defs.h"
|
||||
#include "core/templates/hashfuncs.h"
|
||||
#include "core/typedefs.h"
|
||||
|
||||
class String;
|
||||
|
|
@ -146,6 +147,14 @@ struct [[nodiscard]] Vector4 {
|
|||
explicit operator String() const;
|
||||
operator Vector4i() const;
|
||||
|
||||
uint32_t hash() const {
|
||||
uint32_t h = hash_murmur3_one_real(x);
|
||||
h = hash_murmur3_one_real(y, h);
|
||||
h = hash_murmur3_one_real(z, h);
|
||||
h = hash_murmur3_one_real(w, h);
|
||||
return hash_fmix32(h);
|
||||
}
|
||||
|
||||
constexpr Vector4() :
|
||||
x(0), y(0), z(0), w(0) {}
|
||||
constexpr Vector4(real_t p_x, real_t p_y, real_t p_z, real_t p_w) :
|
||||
|
|
|
|||
|
|
@ -32,6 +32,7 @@
|
|||
|
||||
#include "core/error/error_macros.h"
|
||||
#include "core/math/math_funcs.h"
|
||||
#include "core/templates/hashfuncs.h"
|
||||
|
||||
class String;
|
||||
struct Vector4;
|
||||
|
|
@ -135,6 +136,14 @@ struct [[nodiscard]] Vector4i {
|
|||
explicit operator String() const;
|
||||
operator Vector4() const;
|
||||
|
||||
uint32_t hash() const {
|
||||
uint32_t h = hash_murmur3_one_32(uint32_t(x));
|
||||
h = hash_murmur3_one_32(uint32_t(y), h);
|
||||
h = hash_murmur3_one_32(uint32_t(z), h);
|
||||
h = hash_murmur3_one_32(uint32_t(w), h);
|
||||
return hash_fmix32(h);
|
||||
}
|
||||
|
||||
constexpr Vector4i() :
|
||||
x(0), y(0), z(0), w(0) {}
|
||||
Vector4i(const Vector4 &p_vec4);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue