MeshLib Documentation
Loading...
Searching...
No Matches
MRHash.h
Go to the documentation of this file.
1#pragma once
2
3#include "MRId.h"
4#include "MRVector2.h"
5#include "MRVector3.h"
6#include <cstdint>
7#include <cstring>
8#include <functional>
9
10namespace std
11{
12
13template <typename T>
14struct hash<MR::Id<T>>
15{
16 size_t operator() ( MR::Id<T> const& p ) const noexcept
17 {
18 return (int)p;
19 }
20};
21
22template<>
23struct hash<MR::Vector2f>
24{
25 size_t operator()( MR::Vector2f const& p ) const noexcept
26 {
27 std::uint64_t xy;
28 static_assert( sizeof( float ) == sizeof( std::uint32_t ) );
29 std::memcpy( &xy, &p.x, sizeof( std::uint64_t ) );
30 return size_t( xy );
31 }
32};
33
34template<>
35struct hash<MR::Vector3f>
36{
37 size_t operator()( MR::Vector3f const& p ) const noexcept
38 {
39 // standard implementation is slower:
40 // phmap::HashState().combine(phmap::Hash<float>()(p.x), p.y, p.z);
41 std::uint64_t xy;
42 std::uint32_t z;
43 static_assert( sizeof( float ) == sizeof( std::uint32_t ) );
44 std::memcpy( &xy, &p.x, sizeof( std::uint64_t ) );
45 std::memcpy( &z, &p.z, sizeof( std::uint32_t ) );
46 return size_t( xy ) ^ ( size_t( z ) << 16 );
47 }
48};
49
50} // namespace std
Definition MRMesh/MRId.h:13
Definition MRCameraOrientationPlugin.h:8