From d87a4ef28c1dfdeb65b4530c47ce9b5628f9e992 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adrien=20B=C3=A9raud?= Date: Fri, 6 Oct 2017 15:25:31 +0200 Subject: [PATCH] InfoHash: add operator== --- include/opendht/infohash.h | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/include/opendht/infohash.h b/include/opendht/infohash.h index 087f7ec2..ab50d5a7 100644 --- a/include/opendht/infohash.h +++ b/include/opendht/infohash.h @@ -250,8 +250,16 @@ public: return v; } - bool - operator<(const InfoHash& o) const { + bool operator==(const InfoHash& h) const { + auto a = reinterpret_cast(data()); + auto b = reinterpret_cast(h.data()); + for (size_t i=0; i<(size()/sizeof(uint32_t)); i++) + if (a[i] != b[i]) + return false; + return true; + } + + bool operator<(const InfoHash& o) const { for(unsigned i = 0; i < HASH_LEN; i++) { if((*this)[i] != o[i]) return (*this)[i] < o[i];