From ffc383884dfc478da9fe12dc4ffd17db50feaf64 Mon Sep 17 00:00:00 2001 From: Patrick Pelissier Date: Thu, 17 Aug 2017 20:22:01 +0200 Subject: [PATCH] Add macro M_HASH_FINAL --- m-array.h | 2 +- m-bitset.h | 2 +- m-core.h | 3 ++- m-list.h | 2 +- m-rbtree.h | 2 +- m-tuple.h | 2 +- m-variant.h | 2 +- 7 files changed, 8 insertions(+), 7 deletions(-) diff --git a/m-array.h b/m-array.h index ae7f3359..c1f2db10 100644 --- a/m-array.h +++ b/m-array.h @@ -733,7 +733,7 @@ size_t hi = M_GET_HASH oplist (array->ptr[i]); \ M_HASH_UP(hash, hi); \ } \ - return hash; \ + return M_HASH_FINAL (hash); \ } \ , /* no HASH */ ) \ diff --git a/m-bitset.h b/m-bitset.h index 9242167f..81be0a86 100644 --- a/m-bitset.h +++ b/m-bitset.h @@ -627,7 +627,7 @@ bitset_hash(const bitset_t dest) size_t mask = (1UL << m) - 1; M_HASH_UP(hash, (dest->ptr[n] & mask)); } - return hash; + return M_HASH_FINAL (hash); } #define BITSET_OPLIST \ diff --git a/m-core.h b/m-core.h index 2dde779f..ba6c7c96 100644 --- a/m-core.h +++ b/m-core.h @@ -668,7 +668,8 @@ #endif #define M_HASH_DECL(hash) size_t hash = M_HASH_INIT ^ M_HASH_SEED -#define M_HASH_UP(hash,h) hash = M_HASH_CALC(hash, (h)) +#define M_HASH_UP(hash,h) do { hash = M_HASH_CALC(hash, (h)); } while (0) +#define M_HASH_FINAL(hash) (hash) /* Safe, efficient, and portable Rotate: It should be recognized by any compiler and generate a single roll instruction */ diff --git a/m-list.h b/m-list.h index 8183f524..1a99029a 100644 --- a/m-list.h +++ b/m-list.h @@ -582,7 +582,7 @@ size_t hi = M_GET_HASH oplist (*item); \ M_HASH_UP(hash, hi); \ } \ - return hash; \ + return M_HASH_FINAL (hash); \ } \ , /* no hash */ ) \ diff --git a/m-rbtree.h b/m-rbtree.h index 99a749fc..aee719df 100644 --- a/m-rbtree.h +++ b/m-rbtree.h @@ -892,7 +892,7 @@ typedef enum { const type *ref1 = M_C(name, _cref)(it1); \ M_HASH_UP(hash, M_GET_HASH oplist (*ref1)); \ } \ - return hash; \ + return M_HASH_FINAL (hash); \ } \ , /* NO HASH METHOD */ ) \ \ diff --git a/m-tuple.h b/m-tuple.h index f3c73a2a..f8bdcd75 100644 --- a/m-tuple.h +++ b/m-tuple.h @@ -189,7 +189,7 @@ static inline size_t M_C(name, _hash)(M_C(name,_t) const e1) { \ M_HASH_DECL(hash); \ M_MAP(TUPLE_DEFINE_HASH_FUNC , __VA_ARGS__) \ - return hash; \ + return M_HASH_FINAL (hash); \ } #define TUPLE_DEFINE_HASH_FUNC(a) \ M_HASH_UP(hash, TUPLE_GET_HASH a ( e1 -> TUPLE_GET_FIELD a) ); diff --git a/m-variant.h b/m-variant.h index a4a02d96..e7d3832c 100644 --- a/m-variant.h +++ b/m-variant.h @@ -241,7 +241,7 @@ M_MAP2(VARIANTI_DEFINE_HASH_FUNC , name, __VA_ARGS__) \ default: assert(false); break; \ } \ - return hash; \ + return M_HASH_FINAL (hash); \ } #define VARIANTI_DEFINE_HASH_FUNC(name, a) \ case M_C3(name, _, VARIANTI_GET_FIELD a): \