-
Notifications
You must be signed in to change notification settings - Fork 32
Expand file tree
/
Copy pathHash.h
More file actions
39 lines (35 loc) · 815 Bytes
/
Hash.h
File metadata and controls
39 lines (35 loc) · 815 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
/**
* Copyright (c) 2017 HERE Europe B.V.
* See the LICENSE file in the root of this project for license details.
*/
#pragma once
#include <boost/functional/hash.hpp>
#include <cstddef>
namespace flatdata
{
/**
* Hash function for a flatdata structure.
*
* Example:
*
* std::unordered_set< flatdata::SomeStruct, flatdata::Hash > set;
* std::unordered_map< flatdata::SomeStruct, uint32_t, flatdata::Hash > map;
*
*/
struct Hash
{
template < typename T >
size_t
operator( )( const T& value ) const
{
std::size_t hash = 0;
auto data = value.data( );
auto size = value.size_in_bytes( );
for ( size_t i = 0; i < size; i++ )
{
boost::hash_combine( hash, data[ i ] );
}
return hash;
}
};
} // namespace flatdata