Refactor hash definitions to table file

parent 29b1b82a
......@@ -44,22 +44,16 @@ fh_assert_xxhash_version(void)
static const size_t fh_len[FH_LIM] = {
[FH_NONE] = 0,
[FH_SHA256] = FSHA256_LEN,
#ifdef HAVE_XXHASH_H
[FH_XXH32] = sizeof(XXH32_hash_t),
[FH_XXH3_64] = sizeof(XXH64_hash_t),
[FH_XXH3_128] = sizeof(XXH128_hash_t)
#endif
#define FH(up, lo, len) \
[FH_ ## up] = len,
#include "tbl/fellow_hash.tbl.h"
};
const char * const fh_name[FH_LIM] = {
[FH_NONE] = "none",
[FH_SHA256] = "sha256",
#ifdef HAVE_XXHASH_H
[FH_XXH32] = "xxh32",
[FH_XXH3_64] = "xxh3_64",
[FH_XXH3_128] = "xxh3_128"
#endif
#define FH(up, lo, len) \
[FH_ ## up] = #lo,
#include "tbl/fellow_hash.tbl.h"
};
static void __attribute__((constructor))
......@@ -69,12 +63,9 @@ fh_assert_lengths(void)
union fh fhh = {{0}};
(void)fhh;
assert(fh_len[FH_SHA256] == sizeof fhh.sha256);
#ifdef HAVE_XXHASH_H
assert(fh_len[FH_XXH32] == sizeof fhh.xxh32);
assert(fh_len[FH_XXH3_64] == sizeof fhh.xxh3_64);
assert(fh_len[FH_XXH3_128] == sizeof fhh.xxh3_128);
#endif
#define FH(up, lo, len) \
assert(fh_len[FH_ ## up] == sizeof fhh.lo);
#include "tbl/fellow_hash.tbl.h"
}
#define FH_H_SHA256(d, p, l) sha256(d, p, l)
......@@ -88,29 +79,16 @@ fh_assert_lengths(void)
void
fh(uint8_t fht, union fh *fhh, const void *p, size_t l)
{
//lint --e{779,506} == NULL comparison with constant
//lint -e{506} Constant value Boolean (assert)
//lint -e{525} negative indentation
switch (fht) {
case FH_SHA256:
FH_H_SHA256(fhh->sha256, p, l);
#define FH(up, lo, len) \
case FH_ ## up: \
FH_H_ ## up(fhh->lo, p, l); \
break;
#ifdef HAVE_XXHASH_H
case FH_XXH32:
FH_H_XXH32(fhh->xxh32, p, l);
break;
case FH_XXH3_64:
FH_H_XXH3_64(fhh->xxh3_64, p, l);
break;
case FH_XXH3_128:
FH_H_XXH3_128(fhh->xxh3_128, p, l);
break;
#else
case FH_XXH32:
case FH_XXH3_64:
case FH_XXH3_128:
assert("xxhash support not compiled in" == NULL);
#endif
#include "tbl/fellow_hash.tbl.h"
default:
assert("wrong hash type" == NULL);
assert(0 && "wrong hash type");
}
}
......@@ -129,25 +107,15 @@ xxh3_128_cmp(const uint8_t v[16], const void *p, size_t l)
int
fhcmp(uint8_t fht, const union fh *fhh, const void *p, size_t l)
{
//lint --e{779,506} == NULL comparison with constant
//lint -e{506} Constant value Boolean (assert)
//lint -e{525} negative indentation
switch (fht) {
case FH_SHA256:
return (FH_C_SHA256(fhh->sha256, p, l));
#ifdef HAVE_XXHASH_H
case FH_XXH32:
return (FH_C_XXH32(fhh->xxh32, p, l));
case FH_XXH3_64:
return (FH_C_XXH3_64(fhh->xxh3_64, p, l));
case FH_XXH3_128:
return (FH_C_XXH3_128(fhh->xxh3_128, p, l));
#else
case FH_XXH32:
case FH_XXH3_64:
case FH_XXH3_128:
assert("xxhash support not compiled in" == NULL);
#endif
#define FH(up, lo, len) \
case FH_ ## up: \
return(FH_C_ ## up(fhh->lo, p, l));
#include "tbl/fellow_hash.tbl.h"
default:
assert("wrong hash type" == NULL);
assert(0 && "wrong hash type");
}
// SunOS gcc says "control reaches...", flint says not
//lint -e{527}
......
// UPPER, lower, length
FH(SHA256, sha256, FSHA256_LEN)
#ifdef HAVE_XXHASH_H
FH(XXH32, xxh32, sizeof(XXH32_hash_t))
FH(XXH3_64, xxh3_64, sizeof(XXH64_hash_t))
FH(XXH3_128, xxh3_128, sizeof(XXH128_hash_t))
#endif
#undef FH
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment