]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
Introduce standard hash function for Netmask
authorOtto Moerbeek <otto.moerbeek@open-xchange.com>
Wed, 17 Aug 2022 12:22:00 +0000 (14:22 +0200)
committerOtto Moerbeek <otto.moerbeek@open-xchange.com>
Wed, 24 Aug 2022 09:42:57 +0000 (11:42 +0200)
pdns/iputils.hh

index 2049bc35bcc25ac7735228c214277e5750f5c5cd..af3c2cc74ab9e28bd066b6914a767f6510dc6211 100644 (file)
@@ -693,12 +693,28 @@ public:
     return d_network.getBit(bit);
   }
 
+  struct Hash {
+    size_t operator()(const Netmask& nm) const
+    {
+      return burtle(&nm.d_bits, 1, ComboAddress::addressOnlyHash()(nm.d_network));
+    }
+  };
+
 private:
   ComboAddress d_network;
   uint32_t d_mask;
   uint8_t d_bits;
 };
 
+namespace std {
+  template<>
+  struct hash<Netmask> {
+    auto operator()(const Netmask& nm) const {
+      return Netmask::Hash{}(nm);
+    }
+  };
+}
+
 /** Binary tree map implementation with <Netmask,T> pair.
  *
  * This is an binary tree implementation for storing attributes for IPv4 and IPv6 prefixes.