jaffarCommon
Loading...
Searching...
No Matches
include
jaffarCommon
hash.hpp
Go to the documentation of this file.
1
#pragma once
2
8
#include <metrohash128/metrohash128.h>
9
#include <sha1/sha1.hpp>
10
#include <stdio.h>
11
#include <string>
12
13
namespace
jaffarCommon
14
{
15
16
namespace
hash
17
{
18
22
typedef
_uint128_t
hash_t
;
23
30
__JAFFAR_COMMON__INLINE__ std::string
getSHA1String
(
const
std::string&
string
) {
return
sha1::SHA1::GetHash((
const
uint8_t*)
string
.data(),
string
.size()); }
31
39
__JAFFAR_COMMON__INLINE__
hash_t
calculateMetroHash
(
const
void
* data,
size_t
size)
40
{
41
MetroHash128 hash;
42
hash.Update(data, size);
43
hash_t
result;
44
hash.Finalize(
reinterpret_cast<
uint8_t*
>
(&result));
45
return
result;
46
}
47
54
__JAFFAR_COMMON__INLINE__ std::string
hashToString
(
const
hash_t
hash)
55
{
56
// Creating hash string
57
char
hashStringBuffer[256];
58
sprintf(hashStringBuffer,
"0x%016lX%016lX"
, hash.first, hash.second);
59
return
std::string(hashStringBuffer);
60
}
61
68
__JAFFAR_COMMON__INLINE__
hash_t
hashString
(
const
std::string&
string
) {
return
calculateMetroHash
(
string
.data(),
string
.size()); }
69
70
}
// namespace hash
71
72
}
// namespace jaffarCommon
jaffarCommon::hash::hash_t
_uint128_t hash_t
Definition
hash.hpp:22
jaffarCommon::hash::calculateMetroHash
__JAFFAR_COMMON__INLINE__ hash_t calculateMetroHash(const void *data, size_t size)
Definition
hash.hpp:39
jaffarCommon::hash::hashString
__JAFFAR_COMMON__INLINE__ hash_t hashString(const std::string &string)
Definition
hash.hpp:68
jaffarCommon::hash::getSHA1String
__JAFFAR_COMMON__INLINE__ std::string getSHA1String(const std::string &string)
Definition
hash.hpp:30
jaffarCommon::hash::hashToString
__JAFFAR_COMMON__INLINE__ std::string hashToString(const hash_t hash)
Definition
hash.hpp:54
Generated by
1.9.8