Commit 07f90764 authored by Amol Bhave's avatar Amol Bhave Committed by Facebook Github Bot

Add implementation for std::hash<MacAddress>

Summary:
Add implementation for std::hash<MacAddress> so that it can be used in
maps.

Reviewed By: yfeldblum

Differential Revision: D10004544

fbshipit-source-id: 46cb177577123b1248cd8ff679f0fbe286596819
parent b7ac6b77
......@@ -231,3 +231,15 @@ typename std::enable_if<IsSomeString<Tgt>::value>::type toAppend(
std::ostream& operator<<(std::ostream& os, MacAddress address);
} // namespace folly
namespace std {
// Provide an implementation for std::hash<MacAddress>
template <>
struct hash<folly::MacAddress> {
size_t operator()(const folly::MacAddress& address) const {
return std::hash<uint64_t>()(address.u64HBO());
}
};
} // namespace std
......@@ -167,3 +167,12 @@ TEST(MacAddress, ordering) {
testCmp("01:00:00:00:00:00", "02:00:00:00:00:00");
testCmp("00:00:00:00:00:01", "00:00:00:00:01:00");
}
TEST(MacAddress, hash) {
EXPECT_EQ(
std::hash<MacAddress>()(MacAddress("00:11:22:33:44:55")),
std::hash<MacAddress>()(MacAddress("00-11-22-33-44-55")));
EXPECT_NE(
std::hash<MacAddress>()(MacAddress("00:11:22:33:44:55")),
std::hash<MacAddress>()(MacAddress("00:11:22:33:44:56")));
}
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