Luna/libluna/include/luna/Hash.h

30 lines
545 B
C
Raw Normal View History

2023-06-15 13:50:04 +00:00
#pragma once
#include <luna/CString.h>
#include <luna/Types.h>
u64 hash_memory(const void* mem, usize size, u64 salt);
template <typename T> u64 hash(const T& value, u64 salt)
{
return hash_memory(&value, sizeof(value), salt);
}
template <> u64 hash(const char* const& value, u64 salt);
template <typename T> static void swap(T* a, T* b)
{
char* x = (char*)a;
char* y = (char*)b;
usize size = sizeof(T);
while (size--)
{
char t = *x;
*x = *y;
*y = t;
x += 1;
y += 1;
}
}