Skip to content

Commit c7b4b40

Browse files
committed
perf(Hash): add abseil hahs on basic types
1 parent 9a036ba commit c7b4b40

9 files changed

Lines changed: 99 additions & 0 deletions

File tree

include/geode/basic/named_type.hpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323

2424
#pragma once
2525

26+
#include <absl/hash/hash.h>
27+
2628
#include <bitsery/bitsery.h>
2729
#include <bitsery/brief_syntax.h>
2830

@@ -65,6 +67,12 @@ namespace geode
6567
return !( operator==( other ) );
6668
}
6769

70+
template < typename H >
71+
friend H AbslHashValue( H h, const NamedType& value )
72+
{
73+
return H::combine( std::move( h ), value.value_ );
74+
}
75+
6876
private:
6977
template < typename Archive >
7078
void serialize( Archive& archive )

include/geode/basic/uuid.hpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@
8181

8282
#include <string>
8383

84+
#include <absl/hash/hash.h>
85+
8486
#include <bitsery/bitsery.h>
8587

8688
#include <geode/basic/common.hpp>
@@ -110,6 +112,12 @@ namespace geode
110112

111113
[[nodiscard]] std::string string() const;
112114

115+
template < typename H >
116+
friend H AbslHashValue( H h, const uuid &value )
117+
{
118+
return H::combine( std::move( h ), value.ab, value.cd );
119+
}
120+
113121
uint64_t ab;
114122
uint64_t cd;
115123

include/geode/geometry/point.hpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525

2626
#include <array>
2727

28+
#include <absl/hash/hash.h>
29+
2830
#include <geode/basic/attribute_utils.hpp>
2931
#include <geode/basic/range.hpp>
3032

@@ -80,6 +82,12 @@ namespace geode
8082
[[nodiscard]] Point< dimension - 1 > project_point(
8183
local_index_t axis_to_remove ) const;
8284

85+
template < typename H >
86+
friend H AbslHashValue( H h, const Point &point )
87+
{
88+
return H::combine( std::move( h ), point.values_ );
89+
}
90+
8391
private:
8492
friend class bitsery::Access;
8593
template < typename Archive >

include/geode/mesh/core/graph.hpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include <vector>
2828

2929
#include <absl/container/inlined_vector.h>
30+
#include <absl/hash/hash.h>
3031

3132
#include <geode/basic/passkey.hpp>
3233

@@ -79,6 +80,12 @@ namespace geode
7980
template < typename Archive >
8081
void serialize( Archive& archive );
8182

83+
template < typename H >
84+
friend H AbslHashValue( H h, const EdgeVertex& value )
85+
{
86+
return H::combine( std::move( h ), value.edge_id, value.vertex_id );
87+
}
88+
8289
/*!
8390
* Index of the edge
8491
*/

include/geode/mesh/core/mesh_element.hpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#pragma once
2525

2626
#include <absl/algorithm/container.h>
27+
#include <absl/hash/hash.h>
2728
#include <absl/types/span.h>
2829

2930
#include <geode/basic/uuid.hpp>
@@ -76,6 +77,13 @@ namespace geode
7677
return absl::StrCat( "[", mesh_id.string(), " ", element_id, "]" );
7778
}
7879

80+
template < typename H >
81+
friend H AbslHashValue( H h, const MeshElement& value )
82+
{
83+
return H::combine(
84+
std::move( h ), value.mesh_id, value.element_id );
85+
}
86+
7987
uuid mesh_id;
8088
index_t element_id{ geode::NO_ID };
8189
};

include/geode/mesh/core/solid_mesh.hpp

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include <vector>
2828

2929
#include <absl/container/inlined_vector.h>
30+
#include <absl/hash/hash.h>
3031

3132
#include <geode/basic/passkey.hpp>
3233

@@ -87,6 +88,13 @@ namespace geode
8788
template < typename Archive >
8889
void serialize( Archive& archive );
8990

91+
template < typename H >
92+
friend H AbslHashValue( H h, const PolyhedronVertex& value )
93+
{
94+
return H::combine(
95+
std::move( h ), value.polyhedron_id, value.vertex_id );
96+
}
97+
9098
index_t polyhedron_id{ NO_ID };
9199
local_index_t vertex_id{ NO_LID };
92100
};
@@ -126,6 +134,13 @@ namespace geode
126134
template < typename Archive >
127135
void serialize( Archive& archive );
128136

137+
template < typename H >
138+
friend H AbslHashValue( H h, const PolyhedronFacet& value )
139+
{
140+
return H::combine(
141+
std::move( h ), value.polyhedron_id, value.facet_id );
142+
}
143+
129144
index_t polyhedron_id{ NO_ID };
130145
local_index_t facet_id{ NO_LID };
131146
};
@@ -165,6 +180,13 @@ namespace geode
165180
template < typename Archive >
166181
void serialize( Archive& archive );
167182

183+
template < typename H >
184+
friend H AbslHashValue( H h, const PolyhedronFacetVertex& value )
185+
{
186+
return H::combine(
187+
std::move( h ), value.polyhedron_facet, value.vertex_id );
188+
}
189+
168190
PolyhedronFacet polyhedron_facet;
169191
local_index_t vertex_id{ NO_LID };
170192
};
@@ -201,6 +223,13 @@ namespace geode
201223
template < typename Archive >
202224
void serialize( Archive& archive );
203225

226+
template < typename H >
227+
friend H AbslHashValue( H h, const PolyhedronFacetEdge& value )
228+
{
229+
return H::combine(
230+
std::move( h ), value.polyhedron_facet, value.edge_id );
231+
}
232+
204233
PolyhedronFacet polyhedron_facet;
205234
local_index_t edge_id{ NO_LID };
206235
};

include/geode/mesh/core/surface_mesh.hpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include <optional>
2727

2828
#include <absl/container/inlined_vector.h>
29+
#include <absl/hash/hash.h>
2930

3031
#include <geode/basic/passkey.hpp>
3132

@@ -88,6 +89,13 @@ namespace geode
8889
template < typename Archive >
8990
void serialize( Archive& archive );
9091

92+
template < typename H >
93+
friend H AbslHashValue( H h, const PolygonVertex& value )
94+
{
95+
return H::combine(
96+
std::move( h ), value.polygon_id, value.vertex_id );
97+
}
98+
9199
index_t polygon_id{ NO_ID };
92100
local_index_t vertex_id{ NO_LID };
93101
};
@@ -126,6 +134,13 @@ namespace geode
126134
template < typename Archive >
127135
void serialize( Archive& archive );
128136

137+
template < typename H >
138+
friend H AbslHashValue( H h, const PolygonEdge& value )
139+
{
140+
return H::combine(
141+
std::move( h ), value.polygon_id, value.edge_id );
142+
}
143+
129144
index_t polygon_id{ NO_ID };
130145
local_index_t edge_id{ NO_LID };
131146
};

include/geode/model/mixin/core/component_type.hpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323

2424
#pragma once
2525

26+
#include <absl/hash/hash.h>
27+
2628
#include <bitsery/brief_syntax/string.h>
2729

2830
#include <geode/basic/growable.hpp>
@@ -87,6 +89,12 @@ namespace geode
8789
return absl::StrCat( type_.get(), " ", id_.string() );
8890
}
8991

92+
template < typename H >
93+
friend H AbslHashValue( H h, const ComponentID& value )
94+
{
95+
return H::combine( std::move( h ), value.type_, value.id_ );
96+
}
97+
9098
private:
9199
friend class bitsery::Access;
92100
template < typename Archive >

include/geode/model/mixin/core/vertex_identifier.hpp

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

2626
#include <vector>
2727

28+
#include <absl/hash/hash.h>
2829
#include <absl/types/span.h>
2930

3031
#include <geode/basic/passkey.hpp>
@@ -64,6 +65,13 @@ namespace geode
6465
return absl::StrCat( component_id.string(), " ", vertex );
6566
}
6667

68+
template < typename H >
69+
friend H AbslHashValue( H h, const ComponentMeshVertex& value )
70+
{
71+
return H::combine(
72+
std::move( h ), value.component_id, value.vertex );
73+
}
74+
6775
ComponentID component_id;
6876
index_t vertex{ NO_ID };
6977

0 commit comments

Comments
 (0)