mirror of
https://github.com/RGBCube/serenity
synced 2025-07-28 21:07:35 +00:00
Better int hashing. This was going to bite me sooner or later.
This commit is contained in:
parent
ec07761d0f
commit
601d0d1739
4 changed files with 32 additions and 5 deletions
14
AK/Traits.h
14
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<int> {
|
||||
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<unsigned> {
|
||||
static unsigned hash(unsigned u) { return u; }
|
||||
static unsigned hash(unsigned u) { return intHash(u); }
|
||||
static void dump(unsigned u) { kprintf("%u", u); }
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
struct Traits<T*> {
|
||||
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); }
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue