2018-10-10 05:53:07 -04:00
|
|
|
#pragma once
|
|
|
|
|
2018-10-27 03:33:24 -04:00
|
|
|
#include "HashFunctions.h"
|
2019-05-28 05:53:16 -04:00
|
|
|
#include "kstdio.h"
|
2018-10-10 05:53:07 -04:00
|
|
|
|
|
|
|
namespace AK {
|
|
|
|
|
|
|
|
template<typename T>
|
2019-06-29 13:14:03 -04:00
|
|
|
struct GenericTraits {
|
2019-08-14 05:47:38 -04:00
|
|
|
using PeekType = T;
|
2019-08-07 09:05:10 -04:00
|
|
|
static constexpr bool is_trivial() { return false; }
|
2019-06-29 13:14:03 -04:00
|
|
|
static bool equals(const T& a, const T& b) { return a == b; }
|
|
|
|
};
|
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
struct Traits : public GenericTraits<T> {
|
2018-10-10 05:53:07 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
template<>
|
2019-06-29 13:14:03 -04:00
|
|
|
struct Traits<int> : public GenericTraits<int> {
|
2019-08-07 05:53:21 -04:00
|
|
|
static constexpr bool is_trivial() { return true; }
|
2019-01-31 11:31:23 -05:00
|
|
|
static unsigned hash(int i) { return int_hash(i); }
|
2018-10-17 04:55:43 -04:00
|
|
|
static void dump(int i) { kprintf("%d", i); }
|
2018-10-10 05:53:07 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
template<>
|
2019-06-29 13:14:03 -04:00
|
|
|
struct Traits<unsigned> : public GenericTraits<unsigned> {
|
2019-08-07 05:53:21 -04:00
|
|
|
static constexpr bool is_trivial() { return true; }
|
2019-01-31 11:31:23 -05:00
|
|
|
static unsigned hash(unsigned u) { return int_hash(u); }
|
2018-10-17 04:55:43 -04:00
|
|
|
static void dump(unsigned u) { kprintf("%u", u); }
|
2018-10-10 05:53:07 -04:00
|
|
|
};
|
|
|
|
|
2019-03-13 11:05:56 -04:00
|
|
|
template<>
|
2019-07-03 15:17:35 -04:00
|
|
|
struct Traits<u16> : public GenericTraits<u16> {
|
2019-08-07 05:53:21 -04:00
|
|
|
static constexpr bool is_trivial() { return true; }
|
2019-07-03 15:17:35 -04:00
|
|
|
static unsigned hash(u16 u) { return int_hash(u); }
|
|
|
|
static void dump(u16 u) { kprintf("%u", u); }
|
2019-03-13 11:05:56 -04:00
|
|
|
};
|
|
|
|
|
2020-01-03 01:56:33 -05:00
|
|
|
template<>
|
|
|
|
struct Traits<u64> : public GenericTraits<u64> {
|
|
|
|
static constexpr bool is_trivial() { return true; }
|
|
|
|
static unsigned hash(u64 u) { return u64_hash(u); }
|
|
|
|
static void dump(u64 u) { kprintf("%u", (unsigned)u); } // FIXME: Implement unsigned long long printf specifier, instead of this sadness :(
|
|
|
|
};
|
|
|
|
|
2019-08-07 05:53:21 -04:00
|
|
|
template<>
|
|
|
|
struct Traits<char> : public GenericTraits<char> {
|
|
|
|
static constexpr bool is_trivial() { return true; }
|
|
|
|
static unsigned hash(char c) { return int_hash(c); }
|
|
|
|
static void dump(char c) { kprintf("%c", c); }
|
|
|
|
};
|
|
|
|
|
2018-10-11 10:52:30 -04:00
|
|
|
template<typename T>
|
2019-08-14 05:47:38 -04:00
|
|
|
struct Traits<T*> : public GenericTraits<T*> {
|
2018-10-27 03:33:24 -04:00
|
|
|
static unsigned hash(const T* p)
|
|
|
|
{
|
2019-06-22 15:21:57 -04:00
|
|
|
return int_hash((unsigned)(__PTRDIFF_TYPE__)p);
|
2018-10-27 03:33:24 -04:00
|
|
|
}
|
2019-08-07 05:53:21 -04:00
|
|
|
static constexpr bool is_trivial() { return true; }
|
2018-10-17 04:55:43 -04:00
|
|
|
static void dump(const T* p) { kprintf("%p", p); }
|
2019-06-29 13:14:03 -04:00
|
|
|
static bool equals(const T* a, const T* b) { return a == b; }
|
2018-10-11 10:52:30 -04:00
|
|
|
};
|
|
|
|
|
2018-10-10 05:53:07 -04:00
|
|
|
}
|