mirror of
https://github.com/owntone/owntone-server.git
synced 2025-11-21 18:26:06 -05:00
Add DJB hash function to misc.[ch] and use it
This commit is contained in:
16
src/misc.c
16
src/misc.c
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user