Luna/libluna/src/Hash.cpp

25 lines
509 B
C++
Raw Normal View History

2023-08-26 18:31:16 +00:00
/**
* @file Hash.cpp
* @author apio (cloudapio.eu)
* @brief Common hash functions for use in hash tables.
*
* @copyright Copyright (c) 2023, the Luna authors.
*
*/
#include <luna/CString.h>
2023-06-15 13:50:04 +00:00
#include <luna/Hash.h>
u64 hash_memory(const void* mem, usize size, u64 salt)
{
const char* p = (const char*)mem;
u64 h = salt;
while (--size) h = h * 101 + (u64)*p++;
return h;
}
template <> u64 hash(const char* const& value, u64 salt)
{
return hash_memory(value, strlen(value), salt);
}