]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#1283] Optimized hash
authorFrancis Dupont <fdupont@isc.org>
Sat, 20 Jun 2020 11:54:08 +0000 (13:54 +0200)
committerFrancis Dupont <fdupont@isc.org>
Thu, 23 Jul 2020 19:07:51 +0000 (21:07 +0200)
src/lib/asiolink/io_address.cc
src/lib/asiolink/io_address.h

index a9eb587c337cbd6475a50422bcd500ffd6fd7555..a2a0a788cc2e0044b7d5242a50dcda4607d3f224 100644 (file)
@@ -173,10 +173,15 @@ IOAddress::increase(const IOAddress& addr) {
     return (IOAddress::fromBytes(addr.getFamily(), &packed[0]));
 }
 
-std::size_t
+size_t
 hash_value(const IOAddress& address) {
-    boost::hash<std::vector<uint8_t> > hasher;
-    return (hasher(address.toBytes()));
+    if (address.isV4()) {
+        boost::hash<uint32_t> hasher;
+        return (hasher(address.toUint32()));
+    } else {
+        boost::hash<std::vector<uint8_t> > hasher;
+        return (hasher(address.toBytes()));
+    }
 }
 
 } // namespace asiolink
index 91e415dd9293a53534e79af1683fc618ee76554c..fb1d67b3ea4d462dcec472b3085f4cd16a56ee34 100644 (file)
@@ -305,10 +305,13 @@ operator<<(std::ostream& os, const IOAddress& address);
 /// \brief Hash the IOAddress.
 ///
 /// This method allows boost multi-index hashed indexes on IOAddresses.
+/// It follows the requirement with equality: if two addresses are equal
+/// their hashes are equal, if two addresses are not equal their hashes
+/// are almost surely not equal.
 ///
 /// \param address A \c IOAddress to hash.
 /// \return The hash of the IOAddress.
-std::size_t hash_value(const IOAddress& address);
+size_t hash_value(const IOAddress& address);
 
 } // namespace asiolink
 } // namespace isc