Add DJB hash function to misc.[ch] and use it

This commit is contained in:
Julien BLACHE
2009-04-30 14:51:36 +02:00
parent 0a1c4545dc
commit e5cc417e96
4 changed files with 26 additions and 6 deletions

View File

@@ -23,6 +23,7 @@
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <stdint.h>
#include <limits.h>
#include "daapd.h"
@@ -94,3 +95,18 @@ safe_atol(const char *str, long *val)
return 0;
}
uint32_t
djb_hash(void *data, size_t len)
{
unsigned char *bytes = data;
uint32_t hash = 5381;
while (len--)
{
hash = ((hash << 5) + hash) + *bytes;
bytes++;
}
return hash;
}