From: Yedidya Feldblum Date: Thu, 11 May 2017 05:41:55 +0000 (-0700) Subject: hasher instances for 8-bit and 16-bit integral types X-Git-Tag: v2017.05.15.00~12 X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=9c626faa547649a8e110cea91126c17bcfcb0f3f;p=folly.git 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 --- 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)));