From c3a737eae5a33964cfefc895a262230c0b89a206 Mon Sep 17 00:00:00 2001 From: Kayne Ruse Date: Thu, 26 Dec 2024 17:13:46 +1100 Subject: [PATCH] Added a reference file to notes --- .notes/hash.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 .notes/hash.c diff --git a/.notes/hash.c b/.notes/hash.c new file mode 100644 index 0000000..7ba7826 --- /dev/null +++ b/.notes/hash.c @@ -0,0 +1,23 @@ +#include +#include + +uint32_t hash (uint32_t x) { + x = ((x >> 16) ^ x) * 0x45d9f3b; + x = ((x >> 16) ^ x) * 0x45d9f3b; + x = ((x >> 16) ^ x); + return x; +} + +uint32_t unhash ( uint32_t x ) { + x = (( x >> 16) ^ x) * 0x119de1f3; + x = (( x >> 16) ^ x) * 0x119de1f3; + x = (( x >> 16) ^ x); + return x; +} + +int main() { + //I legit didn't know this algorithm could be reversed. Neat. + uint32_t value = 42; + printf("%u %u %u", value, hash(value), unhash(hash(value))); + return 0; +} \ No newline at end of file