30 lines
545 B
C
30 lines
545 B
C
|
#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;
|
||
|
}
|
||
|
}
|