diff --git a/libdevcore/FixedHash.h b/libdevcore/FixedHash.h index 5ba96b9a8..60c9acad8 100644 --- a/libdevcore/FixedHash.h +++ b/libdevcore/FixedHash.h @@ -150,7 +150,7 @@ public: struct hash { /// Make a hash of the object's data. - size_t operator()(FixedHash const& value) const; + size_t operator()(FixedHash const& _value) const { return boost::hash_range(_value.m_data.cbegin(), _value.m_data.cend()); } }; template inline FixedHash& shiftBloom(FixedHash const& _h) @@ -208,47 +208,11 @@ template<> inline bool FixedHash<32>::operator==(FixedHash<32> const& _other) co return (hash1[0] == hash2[0]) && (hash1[1] == hash2[1]) && (hash1[2] == hash2[2]) && (hash1[3] == hash2[3]); } -/// Fast std::hash compatible hash function object for h64. -template<> inline size_t FixedHash<8>::hash::operator()(FixedHash<8> const& value) const -{ - const uint64_t*data = (const uint64_t*)value.data(); - return (size_t)(*data); -} - -/// Fast std::hash compatible hash function object for h160. -template<> inline size_t FixedHash<20>::hash::operator()(FixedHash<20> const& value) const -{ - const uint64_t*data = (const uint64_t*)value.data(); - uint64_t hash = data[0]; - hash ^= data[1]; - hash ^= ((const uint32_t*)value.data())[4]; - return (size_t)hash; -} - /// Fast std::hash compatible hash function object for h256. template<> inline size_t FixedHash<32>::hash::operator()(FixedHash<32> const& value) const { - const uint64_t*data = (const uint64_t*)value.data(); - uint64_t hash = data[0]; - hash ^= data[1]; - hash ^= data[2]; - hash ^= data[3]; - return (size_t)hash; -} - -/// Fast std::hash compatible hash function object for h512. -template<> inline size_t FixedHash<64>::hash::operator()(FixedHash<64> const& value) const -{ - const uint64_t*data = (const uint64_t*)value.data(); - uint64_t hash = data[0]; - hash ^= data[1]; - hash ^= data[2]; - hash ^= data[3]; - hash ^= data[4]; - hash ^= data[5]; - hash ^= data[6]; - hash ^= data[7]; - return (size_t)hash; + uint64_t const* data = reinterpret_cast(value.data()); + return boost::hash_range(data, data + 4); } /// Stream I/O for the FixedHash class. diff --git a/libdevcrypto/Common.h b/libdevcrypto/Common.h index b854e76a3..d5d44b6f6 100644 --- a/libdevcrypto/Common.h +++ b/libdevcrypto/Common.h @@ -68,7 +68,7 @@ extern Address ZeroAddress; /// A vector of Ethereum addresses. using Addresses = h160s; -/// A hash table of Ethereum addresses. +/// A hash set of Ethereum addresses. using AddressHash = std::unordered_set; /// A vector of secrets. diff --git a/libp2p/Common.h b/libp2p/Common.h index 96b8b9683..56121aedc 100644 --- a/libp2p/Common.h +++ b/libp2p/Common.h @@ -213,14 +213,14 @@ template <> struct hash size_t operator()(bi::address const& _a) const { if (_a.is_v4()) - return _a.to_v4().to_ulong(); + return std::hash()(_a.to_v4().to_ulong()); if (_a.is_v6()) { auto const& range = _a.to_v6().to_bytes(); return boost::hash_range(range.begin(), range.end()); } if (_a.is_unspecified()) - return static_cast(0x3487194039229152ul); // Some random value + return static_cast(0x3487194039229152ul); // Chosen by fair dice roll, guaranteed to be random return std::hash()(_a.to_string()); } }; diff --git a/libp2p/NodeTable.cpp b/libp2p/NodeTable.cpp index 7a68cae10..f0b8d148c 100644 --- a/libp2p/NodeTable.cpp +++ b/libp2p/NodeTable.cpp @@ -293,9 +293,9 @@ vector> NodeTable::nearestNodeEntries(NodeId _target) } vector> ret; - for (auto n: found) - if (n.second->endpoint.isAllowed()) - ret.push_back(n.second); + for (auto n: found) + if (n.second->endpoint.isAllowed()) + ret.push_back(n.second); return move(ret); }