Ken Van Hoeylandt c87200a80d
Project restructuring (fixes macOS builds) (#198)
- Create `Include/` folder for all main projects
- Fix some issues here and there (found while moving things)
- All includes are now in `Tactility/` subfolder and must be included with that prefix. This fixes issues with clashing POSIX headers (e.g. `<semaphore.h>` versus Tactility's `Semaphore.h`)
2025-02-01 18:13:20 +01:00

29 lines
653 B
C++

#include "Tactility/crypt/Hash.h"
namespace tt::crypt {
uint32_t 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 djb2(const void* data, size_t length) {
uint32_t hash = 5381;
auto* data_bytes = static_cast<const 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;
}
} // namespace