From: Arnaud Giersch Date: Tue, 12 Jun 2012 13:39:50 +0000 (+0200) Subject: Inline functions without their definitions don't make much sense. X-Git-Tag: v3_8~636^2~5 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/3347b50014c1857b9d9f3a035d27b67a54beaea8?ds=sidebyside Inline functions without their definitions don't make much sense. Declare xbt_dict_hash() and xbt_dict_hash_ext() as static inline, and move their definitions in header file. --- diff --git a/include/xbt/str.h b/include/xbt/str.h index ea8dcc309d..63a3826f39 100644 --- a/include/xbt/str.h +++ b/include/xbt/str.h @@ -49,9 +49,88 @@ XBT_PUBLIC(char *) xbt_str_diff(const char *a, const char *b); XBT_PUBLIC(char *) xbt_str_from_file(FILE * file); -XBT_INLINE XBT_PUBLIC(unsigned int) xbt_dict_hash_ext(const char *str, - int str_len); -XBT_INLINE XBT_PUBLIC(unsigned int) xbt_dict_hash(const char *str); +#define DJB2_HASH_FUNCTION +//#define FNV_HASH_FUNCTION + +/** + * @brief Returns the hash code of a string. + */ +static XBT_INLINE unsigned int xbt_dict_hash_ext(const char *str, int str_len) +{ + +#ifdef DJB2_HASH_FUNCTION + /* fast implementation of djb2 algorithm */ + int c; + register unsigned int hash = 5381; + + while (str_len--) { + c = *str++; + hash = ((hash << 5) + hash) + c; /* hash * 33 + c */ + } +# elif defined(FNV_HASH_FUNCTION) + register unsigned int hash = 0x811c9dc5; + unsigned char *bp = (unsigned char *) str; /* start of buffer */ + unsigned char *be = bp + str_len; /* beyond end of buffer */ + + while (bp < be) { + /* multiply by the 32 bit FNV magic prime mod 2^32 */ + hash += + (hash << 1) + (hash << 4) + (hash << 7) + (hash << 8) + + (hash << 24); + + /* xor the bottom with the current octet */ + hash ^= (unsigned int) *bp++; + } + +# else + register unsigned int hash = 0; + + while (str_len--) { + hash += (*str) * (*str); + str++; + } +#endif + + return hash; +} + +/** + * @brief Returns the hash code of a string. + */ +static XBT_INLINE unsigned int xbt_dict_hash(const char *str) +{ +#ifdef DJB2_HASH_FUNCTION + /* fast implementation of djb2 algorithm */ + int c; + register unsigned int hash = 5381; + + while ((c = *str++)) { + hash = ((hash << 5) + hash) + c; /* hash * 33 + c */ + } + +# elif defined(FNV_HASH_FUNCTION) + register unsigned int hash = 0x811c9dc5; + + while (*str) { + /* multiply by the 32 bit FNV magic prime mod 2^32 */ + hash += + (hash << 1) + (hash << 4) + (hash << 7) + (hash << 8) + + (hash << 24); + + /* xor the bottom with the current byte */ + hash ^= (unsigned int) *str++; + } + +# else + register unsigned int hash = 0; + + while (*str) { + hash += (*str) * (*str); + str++; + } +#endif + return hash; +} /** @brief Classical alias to (char*) * diff --git a/src/xbt/xbt_str.c b/src/xbt/xbt_str.c index 920df6c642..de49953b81 100644 --- a/src/xbt/xbt_str.c +++ b/src/xbt/xbt_str.c @@ -6,9 +6,6 @@ /* This program is free software; you can redistribute it and/or modify it * under the terms of the license (GNU LGPL) which comes with this package. */ -#define DJB2_HASH_FUNCTION -//#define FNV_HASH_FUNCTION - #include "portable.h" #include "xbt/misc.h" #include "xbt/sysdep.h" @@ -906,87 +903,6 @@ char *xbt_str_from_file(FILE * file) return res; } -/** - * @brief Returns the hash code of a string. - */ -XBT_INLINE unsigned int xbt_dict_hash_ext(const char *str, - int str_len) -{ - -#ifdef DJB2_HASH_FUNCTION - /* fast implementation of djb2 algorithm */ - int c; - register unsigned int hash = 5381; - - while (str_len--) { - c = *str++; - hash = ((hash << 5) + hash) + c; /* hash * 33 + c */ - } -# elif defined(FNV_HASH_FUNCTION) - register unsigned int hash = 0x811c9dc5; - unsigned char *bp = (unsigned char *) str; /* start of buffer */ - unsigned char *be = bp + str_len; /* beyond end of buffer */ - - while (bp < be) { - /* multiply by the 32 bit FNV magic prime mod 2^32 */ - hash += - (hash << 1) + (hash << 4) + (hash << 7) + (hash << 8) + - (hash << 24); - - /* xor the bottom with the current octet */ - hash ^= (unsigned int) *bp++; - } - -# else - register unsigned int hash = 0; - - while (str_len--) { - hash += (*str) * (*str); - str++; - } -#endif - - return hash; -} - -/** - * @brief Returns the hash code of a string. - */ -XBT_INLINE unsigned int xbt_dict_hash(const char *str) -{ -#ifdef DJB2_HASH_FUNCTION - /* fast implementation of djb2 algorithm */ - int c; - register unsigned int hash = 5381; - - while ((c = *str++)) { - hash = ((hash << 5) + hash) + c; /* hash * 33 + c */ - } - -# elif defined(FNV_HASH_FUNCTION) - register unsigned int hash = 0x811c9dc5; - - while (*str) { - /* multiply by the 32 bit FNV magic prime mod 2^32 */ - hash += - (hash << 1) + (hash << 4) + (hash << 7) + (hash << 8) + - (hash << 24); - - /* xor the bottom with the current byte */ - hash ^= (unsigned int) *str++; - } - -# else - register unsigned int hash = 0; - - while (*str) { - hash += (*str) * (*str); - str++; - } -#endif - return hash; -} - #ifdef SIMGRID_TEST #include "xbt/str.h"