types: Migrate to stdplus hash
Trivial refactor to remove duplicate code.
Change-Id: I20ab453f9f85b5802ddcae0d389caf3b41381a86
Signed-off-by: William A. Kennington III <wak@google.com>
diff --git a/src/system_queries.cpp b/src/system_queries.cpp
index 0ce674f..e922504 100644
--- a/src/system_queries.cpp
+++ b/src/system_queries.cpp
@@ -10,6 +10,7 @@
#include <phosphor-logging/lg2.hpp>
#include <stdplus/fd/create.hpp>
+#include <stdplus/hash/tuple.hpp>
#include <stdplus/util/cexec.hpp>
#include <algorithm>
diff --git a/src/types.cpp b/src/types.cpp
index 8467b76..0a46b1f 100644
--- a/src/types.cpp
+++ b/src/types.cpp
@@ -2,6 +2,8 @@
#include <fmt/format.h>
+#include <stdplus/hash.hpp>
+
void phosphor::network::IfAddr::invalidPfx(uint8_t pfx)
{
throw std::invalid_argument(fmt::format("Invalid prefix {}", pfx));
@@ -9,19 +11,18 @@
std::size_t std::hash<in_addr>::operator()(in_addr addr) const noexcept
{
- return std::hash<decltype(addr.s_addr)>{}(addr.s_addr);
+ return stdplus::hashMulti(addr.s_addr);
}
std::size_t std::hash<in6_addr>::operator()(in6_addr addr) const noexcept
{
- return phosphor::network::hash_multi(addr.s6_addr32[0], addr.s6_addr32[1],
- addr.s6_addr32[2], addr.s6_addr32[3]);
+ return stdplus::hashMulti(addr.s6_addr32);
}
std::size_t std::hash<phosphor::network::IfAddr>::operator()(
phosphor::network::IfAddr addr) const noexcept
{
- return phosphor::network::hash_multi(addr.getAddr(), addr.getPfx());
+ return stdplus::hashMulti(addr.getAddr(), addr.getPfx());
}
std::string std::to_string(ether_addr value)
diff --git a/src/types.hpp b/src/types.hpp
index 45c15aa..53a3c89 100644
--- a/src/types.hpp
+++ b/src/types.hpp
@@ -134,18 +134,6 @@
}
};
-constexpr std::size_t hash_multi() noexcept
-{
- return 0;
-}
-
-template <typename T, typename... Args>
-constexpr std::size_t hash_multi(const T& v, const Args&... args) noexcept
-{
- const std::size_t seed = hash_multi(args...);
- return seed ^ (std::hash<T>{}(v) + 0x9e3779b9 + (seed << 6) + (seed >> 2));
-}
-
namespace detail
{
@@ -733,15 +721,6 @@
} // namespace network
} // namespace phosphor
-template <typename... Ts>
-struct std::hash<std::tuple<Ts...>>
-{
- constexpr auto operator()(const std::tuple<Ts...>& t) const noexcept
- {
- return std::apply(phosphor::network::hash_multi<Ts...>, t);
- }
-};
-
template <>
struct std::hash<in_addr>
{