Commit 9c626faa authored by Yedidya Feldblum's avatar Yedidya Feldblum Committed by Facebook Github Bot

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
parent f3bbb0b1
...@@ -382,6 +382,38 @@ template<> struct hasher<uint32_t> { ...@@ -382,6 +382,38 @@ template<> struct hasher<uint32_t> {
} }
}; };
template<> struct hasher<int16_t> {
size_t operator()(int16_t key) const {
return hasher<int32_t>()(key); // as impl accident, sign-extends
}
};
template<> struct hasher<uint16_t> {
size_t operator()(uint16_t key) const {
return hasher<uint32_t>()(key);
}
};
template<> struct hasher<int8_t> {
size_t operator()(int8_t key) const {
return hasher<int32_t>()(key); // as impl accident, sign-extends
}
};
template<> struct hasher<uint8_t> {
size_t operator()(uint8_t key) const {
return hasher<uint32_t>()(key);
}
};
template<> struct hasher<char> {
using explicit_type =
std::conditional<std::is_signed<char>::value, int8_t, uint8_t>::type;
size_t operator()(char key) const {
return hasher<explicit_type>()(key); // as impl accident, sign-extends
}
};
template<> struct hasher<int64_t> { template<> struct hasher<int64_t> {
size_t operator()(int64_t key) const { size_t operator()(int64_t key) const {
return static_cast<size_t>(hash::twang_mix64(uint64_t(key))); return static_cast<size_t>(hash::twang_mix64(uint64_t(key)));
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment