-
Notifications
You must be signed in to change notification settings - Fork 50
/
Copy pathhash.h
55 lines (39 loc) · 1.22 KB
/
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
49
50
51
52
53
54
55
// hash.h
// Copyright 2014 - 2023 Alex Dixon.
// License: https://github.com/polymonster/pmtech/blob/master/license.md
// Hash murmur2 implementation for all hashing needs
#pragma once
#include "types.h"
#include "str/Str.h"
namespace pen
{
class HashMurmur2A
{
public:
void begin(uint32_t _seed = 0);
void add(const void* _data, int _len);
void addAligned(const void* _data, int _len);
void addUnaligned(const void* _data, int _len);
template <typename Ty>
void add(Ty _value);
uint32_t end();
private:
static void readUnaligned(const void* _data, uint32_t& _out);
void mixTail(const uint8_t*& _data, int& _len);
uint32_t m_hash;
uint32_t m_tail;
uint32_t m_count;
uint32_t m_size;
};
uint32_t hashMurmur2A(const void* _data, uint32_t _size);
template <typename Ty>
uint32_t hashMurmur2A(const Ty& _data);
template <>
uint32_t hashMurmur2A(const Str& s);
uint32_t hashMurmur2A(const char* _data);
uint32_t hashMurmur2A(char* _data);
typedef HashMurmur2A hash_murmur;
} // namespace pen
#define _hash_h
#define PEN_HASH(V) pen::hashMurmur2A(V)
#include "hash.inl"