From 9c626faa547649a8e110cea91126c17bcfcb0f3f Mon Sep 17 00:00:00 2001 From: Yedidya Feldblum Date: Wed, 10 May 2017 22:41:55 -0700 Subject: [PATCH] hasher instances for 8-bit and 16-bit integral types Summary: [Folly] `hasher` instances for 8-bit and 16-bit integral types. Allowing the use of `Hash` with such types. They are not necessarily the ideal algorithms for those widths, essentially forwarding to the 32-bit instances. Reviewed By: luciang Differential Revision: D5043094 fbshipit-source-id: 6ef96dfc8d1baf0a15b9bdd585b7c7672099e4f0 --- folly/Hash.h | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/folly/Hash.h b/folly/Hash.h index e64633d2..1df1ff67 100644 --- a/folly/Hash.h +++ b/folly/Hash.h @@ -382,6 +382,38 @@ template<> struct hasher { } }; +template<> struct hasher { + size_t operator()(int16_t key) const { + return hasher()(key); // as impl accident, sign-extends + } +}; + +template<> struct hasher { + size_t operator()(uint16_t key) const { + return hasher()(key); + } +}; + +template<> struct hasher { + size_t operator()(int8_t key) const { + return hasher()(key); // as impl accident, sign-extends + } +}; + +template<> struct hasher { + size_t operator()(uint8_t key) const { + return hasher()(key); + } +}; + +template<> struct hasher { + using explicit_type = + std::conditional::value, int8_t, uint8_t>::type; + size_t operator()(char key) const { + return hasher()(key); // as impl accident, sign-extends + } +}; + template<> struct hasher { size_t operator()(int64_t key) const { return static_cast(hash::twang_mix64(uint64_t(key))); -- 2.34.1