Move djb2 to hash.c

This commit is contained in:
twinaphex 2015-06-03 09:46:13 +02:00
parent 58a8004d38
commit ae41de8d57
3 changed files with 15 additions and 13 deletions

View File

@ -31,17 +31,6 @@
#include <stdint.h>
static INLINE uint32_t djb2(const char *str)
{
const unsigned char *aux = (const unsigned char*)str;
uint32_t hash = 5381;
while ( *aux )
hash = ( hash << 5 ) + hash + *aux++;
return hash;
}
#define DB_QUERY_ENTRY 0x1c310956U
#define DB_QUERY_ENTRY_PUBLISHER 0x125e594dU
#define DB_QUERY_ENTRY_DEVELOPER 0xcbd89be5U
@ -68,7 +57,7 @@ int database_info_build_query(char *s, size_t len,
strlcpy(s, "{'", len);
value = djb2(label);
value = djb2_calculate(label);
switch (value)
{
@ -210,7 +199,7 @@ static int database_cursor_iterate(libretrodb_cursor_t *cur,
if (!key || !val)
continue;
value = djb2(key->string.buff);
value = djb2_calculate(key->string.buff);
switch (value)
{

11
hash.c
View File

@ -522,3 +522,14 @@ error:
close(fd);
return -1;
}
uint32_t djb2_calculate(const char *str)
{
const unsigned char *aux = (const unsigned char*)str;
uint32_t hash = 5381;
while ( *aux )
hash = ( hash << 5 ) + hash + *aux++;
return hash;
}

2
hash.h
View File

@ -76,5 +76,7 @@ typedef struct SHA1Context
int sha1_calculate(const char *path, char *result);
uint32_t djb2_calculate(const char *str);
#endif