-
Notifications
You must be signed in to change notification settings - Fork 13
/
city_hash.h
48 lines (39 loc) · 1.11 KB
/
city_hash.h
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
40
41
42
43
44
45
46
47
48
//------------------------------ city_hash.h -----------------------------------
//
// This software is in the public domain. The only restriction on its use is
// that no one can remove it from the public domain by claiming ownership of it,
// including the original authors.
//
// There is no warranty of correctness on the software contained herein. Use
// at your own risk.
//
//------------------------------------------------------------------------------
#ifndef CITY_HASH_H
#define CITY_HASH_H
#include <cstddef>
#include <vector>
#include "city.h"
// namespace acme is used to demonstrate example code. It is not proposed.
namespace acme
{
class city
{
std::vector<char> buf_;
public:
using result_type = std::size_t;
void
operator()(void const* key, std::size_t len) noexcept
{
char const* p = static_cast<char const*>(key);
char const* const e = p + len;
for (; p < e; ++p)
buf_.push_back(*p);
}
explicit
operator std::size_t() noexcept
{
return CityHash64(buf_.data(), buf_.size());
}
};
} // acme
#endif // CITY_HASH_H