hashlib: Support for std::array keys
Signed-off-by: gatecat <gatecat@ds0.me>
This commit is contained in:
parent
74e7beb5e1
commit
b749ef5f56
@ -13,6 +13,7 @@
|
||||
#define HASHLIB_H
|
||||
|
||||
#include <algorithm>
|
||||
#include <array>
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
@ -132,6 +133,18 @@ template <typename T> struct hash_ops<std::vector<T>>
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T, size_t N> struct hash_ops<std::array<T, N>>
|
||||
{
|
||||
static inline bool cmp(std::array<T, N> a, std::array<T, N> b) { return a == b; }
|
||||
static inline unsigned int hash(std::array<T, N> a)
|
||||
{
|
||||
unsigned int h = mkhash_init;
|
||||
for (auto k : a)
|
||||
h = mkhash(h, hash_ops<T>::hash(k));
|
||||
return h;
|
||||
}
|
||||
};
|
||||
|
||||
struct hash_cstr_ops
|
||||
{
|
||||
static inline bool cmp(const char *a, const char *b)
|
||||
|
Loading…
Reference in New Issue
Block a user