mirror of
https://github.com/ByteWelder/Tactility.git
synced 2026-02-18 19:03:16 +00:00
25 lines
611 B
C
25 lines
611 B
C
#include "hash.h"
|
|
|
|
uint32_t tt_hash_string_djb2(const char* str) {
|
|
uint32_t hash = 5381;
|
|
char c = (char)*str++;
|
|
while (c != 0) {
|
|
hash = ((hash << 5) + hash) + (uint32_t)c; // hash * 33 + c
|
|
c = (char)*str++;
|
|
}
|
|
return hash;
|
|
}
|
|
|
|
uint32_t tt_hash_bytes_djb2(const void* data, size_t length) {
|
|
uint32_t hash = 5381;
|
|
uint8_t* data_bytes = (uint8_t*)data;
|
|
uint8_t c = *data_bytes++;
|
|
size_t index = 0;
|
|
while (index < length) {
|
|
hash = ((hash << 5) + hash) + (uint32_t)c; // hash * 33 + c
|
|
c = *data_bytes++;
|
|
index++;
|
|
}
|
|
return hash;
|
|
}
|