util: import a_strhash()

Signed-off-by: Julien Danjou <julien@danjou.info>
This commit is contained in:
Julien Danjou 2009-05-29 14:07:50 +02:00
parent e69f80caf6
commit c00aa8fd5e
1 changed files with 15 additions and 0 deletions

View File

@ -317,6 +317,21 @@ a_strncat(char *dst, ssize_t n, const char *src, ssize_t l)
return dlen + a_strncpy(dst + dlen, n - dlen, src, l);
}
/** Compute a hash for a string.
* This is based on 'djb2' algorithm.
*/
static inline unsigned long
a_strhash(const unsigned char *str)
{
unsigned long hash = 5381;
int c;
while((c = *str++))
hash = ((hash << 5) + hash) + c; /* hash * 33 + c */
return hash;
}
#define fatal(string, ...) _fatal(__LINE__, \
__FUNCTION__, \
string, ## __VA_ARGS__)