Browse Source

use boost hash function for FixedHash, asio adress. Style fixes

cl-refactor
arkpar 10 years ago
parent
commit
de3ff170c8
  1. 42
      libdevcore/FixedHash.h
  2. 2
      libdevcrypto/Common.h
  3. 4
      libp2p/Common.h
  4. 6
      libp2p/NodeTable.cpp

42
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 <unsigned P, unsigned M> inline FixedHash& shiftBloom(FixedHash<M> 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<uint64_t const*>(value.data());
return boost::hash_range(data, data + 4);
}
/// Stream I/O for the FixedHash class.

2
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<h160>;
/// A vector of secrets.

4
libp2p/Common.h

@ -213,14 +213,14 @@ template <> struct hash<bi::address>
size_t operator()(bi::address const& _a) const
{
if (_a.is_v4())
return _a.to_v4().to_ulong();
return std::hash<unsigned long>()(_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<size_t>(0x3487194039229152ul); // Some random value
return static_cast<size_t>(0x3487194039229152ul); // Chosen by fair dice roll, guaranteed to be random
return std::hash<std::string>()(_a.to_string());
}
};

6
libp2p/NodeTable.cpp

@ -293,9 +293,9 @@ vector<shared_ptr<NodeEntry>> NodeTable::nearestNodeEntries(NodeId _target)
}
vector<shared_ptr<NodeEntry>> 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);
}

Loading…
Cancel
Save