diff --git a/AK/HashFunctions.h b/AK/HashFunctions.h new file mode 100644 index 0000000000..6f9829c0cb --- /dev/null +++ b/AK/HashFunctions.h @@ -0,0 +1,20 @@ +#pragma once + +#include "Types.h" + +inline unsigned intHash(dword key) +{ + key += ~(key << 15); + key ^= (key >> 10); + key += (key << 3); + key ^= (key >> 6); + key += ~(key << 11); + key ^= (key >> 16); + return key; +} + +inline unsigned pairIntHash(dword key1, dword key2) +{ + return intHash((intHash(key1) * 209) ^ (intHash(key2 * 413))); +} + diff --git a/AK/Traits.h b/AK/Traits.h index aa0d307e57..d9e64b0435 100644 --- a/AK/Traits.h +++ b/AK/Traits.h @@ -1,6 +1,7 @@ #pragma once #include "kstdio.h" +#include "HashFunctions.h" namespace AK { @@ -11,19 +12,26 @@ struct Traits template<> struct Traits { - static unsigned hash(int i) { return i; } + static unsigned hash(int i) { return intHash(i); } static void dump(int i) { kprintf("%d", i); } }; template<> struct Traits { - static unsigned hash(unsigned u) { return u; } + static unsigned hash(unsigned u) { return intHash(u); } static void dump(unsigned u) { kprintf("%u", u); } }; template struct Traits { - static unsigned hash(const T* p) { return (unsigned)p; } + static unsigned hash(const T* p) + { +#ifdef SERENITY + return intHash((dword)p); +#else + return intHash((ptrdiff_t)p & 0xffffffff); +#endif + } static void dump(const T* p) { kprintf("%p", p); } }; diff --git a/AK/test.cpp b/AK/test.cpp index a181da2c4d..0b359d59bc 100644 --- a/AK/test.cpp +++ b/AK/test.cpp @@ -33,7 +33,6 @@ int main(int, char**) for (auto& it : tab) { printf("%s\n", it.value.s.characters()); } - return 0; } { diff --git a/Widgets/Makefile b/Widgets/Makefile index 52835f08f5..32add4ee28 100644 --- a/Widgets/Makefile +++ b/Widgets/Makefile @@ -47,5 +47,5 @@ clean: rm -f $(OBJS) $(PROGRAM) $(PROGRAM): $(OBJS) - $(CXX) $(LDFLAGS) -o $@ $(OBJS) + $(CXX) -o $@ $(OBJS) $(LDFLAGS)