Skip to content

Commit 686b56f

Browse files
committed
Merge pull request #106434 from Ivorforce/invert-hashfuncs
Reduce cross project includes by rewriting `HashMapHasherDefault`.
2 parents dd6ffaa + ad60012 commit 686b56f

File tree

29 files changed

+228
-197
lines changed

29 files changed

+228
-197
lines changed

core/math/aabb.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232

3333
#include "core/math/plane.h"
3434
#include "core/math/vector3.h"
35+
#include "core/templates/hashfuncs.h"
3536

3637
/**
3738
* AABB (Axis Aligned Bounding Box)
@@ -131,6 +132,16 @@ struct [[nodiscard]] AABB {
131132
return position + (size * 0.5f);
132133
}
133134

135+
uint32_t hash() const {
136+
uint32_t h = hash_murmur3_one_real(position.x);
137+
h = hash_murmur3_one_real(position.y, h);
138+
h = hash_murmur3_one_real(position.z, h);
139+
h = hash_murmur3_one_real(size.x, h);
140+
h = hash_murmur3_one_real(size.y, h);
141+
h = hash_murmur3_one_real(size.z, h);
142+
return hash_fmix32(h);
143+
}
144+
134145
explicit operator String() const;
135146

136147
AABB() = default;

core/math/color.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#pragma once
3232

3333
#include "core/math/math_funcs.h"
34+
#include "core/templates/hashfuncs.h"
3435

3536
class String;
3637

@@ -239,6 +240,14 @@ struct [[nodiscard]] Color {
239240
_FORCE_INLINE_ void set_ok_hsl_s(float p_s) { set_ok_hsl(get_ok_hsl_h(), p_s, get_ok_hsl_l(), a); }
240241
_FORCE_INLINE_ void set_ok_hsl_l(float p_l) { set_ok_hsl(get_ok_hsl_h(), get_ok_hsl_s(), p_l, a); }
241242

243+
uint32_t hash() const {
244+
uint32_t h = hash_murmur3_one_float(r);
245+
h = hash_murmur3_one_float(r, h);
246+
h = hash_murmur3_one_float(b, h);
247+
h = hash_murmur3_one_float(a, h);
248+
return hash_fmix32(h);
249+
}
250+
242251
constexpr Color() :
243252
r(0), g(0), b(0), a(1) {}
244253

core/math/delaunay_3d.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
#include "core/math/aabb.h"
3434
#include "core/math/projection.h"
3535
#include "core/math/vector3.h"
36+
#include "core/math/vector3i.h"
3637
#include "core/templates/a_hash_map.h"
3738
#include "core/templates/list.h"
3839
#include "core/templates/local_vector.h"

core/math/geometry_3d.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,10 @@
3030

3131
#pragma once
3232

33+
#include "core/math/color.h"
3334
#include "core/math/delaunay_3d.h"
3435
#include "core/math/face3.h"
36+
#include "core/math/vector2.h"
3537
#include "core/templates/local_vector.h"
3638
#include "core/templates/vector.h"
3739

core/math/rect2.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232

3333
#include "core/error/error_macros.h"
3434
#include "core/math/vector2.h"
35+
#include "core/templates/hashfuncs.h"
3536

3637
class String;
3738
struct Rect2i;
@@ -361,6 +362,14 @@ struct [[nodiscard]] Rect2 {
361362
explicit operator String() const;
362363
operator Rect2i() const;
363364

365+
uint32_t hash() const {
366+
uint32_t h = hash_murmur3_one_real(position.x);
367+
h = hash_murmur3_one_real(position.y, h);
368+
h = hash_murmur3_one_real(size.x, h);
369+
h = hash_murmur3_one_real(size.y, h);
370+
return hash_fmix32(h);
371+
}
372+
364373
Rect2() = default;
365374
constexpr Rect2(real_t p_x, real_t p_y, real_t p_width, real_t p_height) :
366375
position(Point2(p_x, p_y)),

core/math/rect2i.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232

3333
#include "core/error/error_macros.h"
3434
#include "core/math/vector2i.h"
35+
#include "core/templates/hashfuncs.h"
3536

3637
class String;
3738
struct Rect2;
@@ -226,6 +227,14 @@ struct [[nodiscard]] Rect2i {
226227
explicit operator String() const;
227228
operator Rect2() const;
228229

230+
uint32_t hash() const {
231+
uint32_t h = hash_murmur3_one_32(uint32_t(position.x));
232+
h = hash_murmur3_one_32(uint32_t(position.y), h);
233+
h = hash_murmur3_one_32(uint32_t(size.x), h);
234+
h = hash_murmur3_one_32(uint32_t(size.y), h);
235+
return hash_fmix32(h);
236+
}
237+
229238
Rect2i() = default;
230239
constexpr Rect2i(int p_x, int p_y, int p_width, int p_height) :
231240
position(Point2i(p_x, p_y)),

core/math/vector2.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232

3333
#include "core/error/error_macros.h"
3434
#include "core/math/math_funcs.h"
35+
#include "core/templates/hashfuncs.h"
3536

3637
class String;
3738
struct Vector2i;
@@ -190,6 +191,12 @@ struct [[nodiscard]] Vector2 {
190191
explicit operator String() const;
191192
operator Vector2i() const;
192193

194+
uint32_t hash() const {
195+
uint32_t h = hash_murmur3_one_real(x);
196+
h = hash_murmur3_one_real(y, h);
197+
return hash_fmix32(h);
198+
}
199+
193200
// NOLINTBEGIN(cppcoreguidelines-pro-type-member-init)
194201
constexpr Vector2() :
195202
x(0), y(0) {}

core/math/vector2i.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232

3333
#include "core/error/error_macros.h"
3434
#include "core/math/math_funcs.h"
35+
#include "core/templates/hashfuncs.h"
3536

3637
class String;
3738
struct Vector2;
@@ -147,6 +148,12 @@ struct [[nodiscard]] Vector2i {
147148
explicit operator String() const;
148149
operator Vector2() const;
149150

151+
uint32_t hash() const {
152+
uint32_t h = hash_murmur3_one_32(uint32_t(x));
153+
h = hash_murmur3_one_32(uint32_t(y), h);
154+
return hash_fmix32(h);
155+
}
156+
150157
// NOLINTBEGIN(cppcoreguidelines-pro-type-member-init)
151158
constexpr Vector2i() :
152159
x(0), y(0) {}

core/math/vector3.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,13 @@ struct [[nodiscard]] Vector3 {
214214
explicit operator String() const;
215215
operator Vector3i() const;
216216

217+
uint32_t hash() const {
218+
uint32_t h = hash_murmur3_one_real(x);
219+
h = hash_murmur3_one_real(y, h);
220+
h = hash_murmur3_one_real(z, h);
221+
return hash_fmix32(h);
222+
}
223+
217224
constexpr Vector3() :
218225
x(0), y(0), z(0) {}
219226
constexpr Vector3(real_t p_x, real_t p_y, real_t p_z) :

core/math/vector3i.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232

3333
#include "core/error/error_macros.h"
3434
#include "core/math/math_funcs.h"
35+
#include "core/templates/hashfuncs.h"
3536

3637
class String;
3738
struct Vector3;
@@ -140,6 +141,13 @@ struct [[nodiscard]] Vector3i {
140141
explicit operator String() const;
141142
operator Vector3() const;
142143

144+
uint32_t hash() const {
145+
uint32_t h = hash_murmur3_one_32(uint32_t(x));
146+
h = hash_murmur3_one_32(uint32_t(y), h);
147+
h = hash_murmur3_one_32(uint32_t(z), h);
148+
return hash_fmix32(h);
149+
}
150+
143151
constexpr Vector3i() :
144152
x(0), y(0), z(0) {}
145153
constexpr Vector3i(int32_t p_x, int32_t p_y, int32_t p_z) :

0 commit comments

Comments
 (0)