aboutsummaryrefslogtreecommitdiffstats
path: root/common/hashlib.h
diff options
context:
space:
mode:
authorgatecat <gatecat@ds0.me>2021-10-07 16:55:20 +0100
committergatecat <gatecat@ds0.me>2021-10-07 17:05:16 +0100
commitb749ef5f563fa9d099b158c2e493e8734558a327 (patch)
tree703d187a2f123d9cfb96845e724fcbb53a3ac1db /common/hashlib.h
parent74e7beb5e1137b48a22de5eec1707747603698aa (diff)
downloadnextpnr-b749ef5f563fa9d099b158c2e493e8734558a327.tar.gz
nextpnr-b749ef5f563fa9d099b158c2e493e8734558a327.tar.bz2
nextpnr-b749ef5f563fa9d099b158c2e493e8734558a327.zip
hashlib: Support for std::array keys
Signed-off-by: gatecat <gatecat@ds0.me>
Diffstat (limited to 'common/hashlib.h')
-rw-r--r--common/hashlib.h13
1 files changed, 13 insertions, 0 deletions
diff --git a/common/hashlib.h b/common/hashlib.h
index 063df78f..b71f0129 100644
--- a/common/hashlib.h
+++ b/common/hashlib.h
@@ -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)