From 1fdc58a58061f044f5a701f8b96af2eb80027b52 Mon Sep 17 00:00:00 2001 From: vivek Date: Tue, 28 Apr 2015 23:33:56 +0200 Subject: [PATCH] eina: add crc hash function to eina hash module. Summary: Added eina_hash_crc function in eina hash module to generate hash code using crc-32. Signed-off-by: vivek Reviewers: Sergeant_Whitespace, cedric Subscribers: Sergeant_Whitespace, cedric Differential Revision: https://phab.enlightenment.org/D2273 Signed-off-by: Cedric BAIL --- src/lib/eina/eina_hash.h | 11 +++++++++++ src/lib/eina/eina_inline_hash.x | 12 ++++++++++++ 2 files changed, 23 insertions(+) diff --git a/src/lib/eina/eina_hash.h b/src/lib/eina/eina_hash.h index 460af00442..5f953bf865 100644 --- a/src/lib/eina/eina_hash.h +++ b/src/lib/eina/eina_hash.h @@ -1157,6 +1157,17 @@ static inline int eina_hash_int64(const unsigned long long int *pkey, static inline int eina_hash_murmur3(const char *key, int len) EINA_ARG_NONNULL(1); +/** + * @brief + * Hash function using crc-32 algorithm and and 0xEDB88320 polynomial + * + * @param key The key to hash + * @param len The length of the key + * @return The hash value + */ +static inline int eina_hash_crc(const char *key, + int len) EINA_ARG_NONNULL(1); + #include "eina_inline_hash.x" /** diff --git a/src/lib/eina/eina_inline_hash.x b/src/lib/eina/eina_inline_hash.x index 630e3479ba..71b0208c9c 100644 --- a/src/lib/eina/eina_inline_hash.x +++ b/src/lib/eina/eina_inline_hash.x @@ -19,6 +19,8 @@ #ifndef EINA_INLINE_HASH_X_ #define EINA_INLINE_HASH_X_ +#include "eina_crc.h" + EAPI extern unsigned int eina_seed; /* @@ -150,4 +152,14 @@ eina_hash_murmur3(const char *key, int len) return _fmix32(h1); } + +static inline int +eina_hash_crc(const char *key, int len) +{ + unsigned int crc; + unsigned int seed = 0xFFFFFFFF; + + crc = eina_crc(key, len, seed, EINA_TRUE); + return (int)crc; +} #endif