Ken Van Hoeylandt 8b6463d060
Wi-Fi improvements (#77)
Refactoring, new features and stability improvements.
2024-11-12 21:36:23 +01:00

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;
}