From: Otto Moerbeek Date: Wed, 17 Aug 2022 12:22:00 +0000 (+0200) Subject: Introduce standard hash function for Netmask X-Git-Tag: rec-4.9.0-alpha0~22^2~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7da536dfba3bb91c6e4086faf9d139d000bc02e7;p=thirdparty%2Fpdns.git Introduce standard hash function for Netmask --- diff --git a/pdns/iputils.hh b/pdns/iputils.hh index 2049bc35bc..af3c2cc74a 100644 --- a/pdns/iputils.hh +++ b/pdns/iputils.hh @@ -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 { + auto operator()(const Netmask& nm) const { + return Netmask::Hash{}(nm); + } + }; +} + /** Binary tree map implementation with pair. * * This is an binary tree implementation for storing attributes for IPv4 and IPv6 prefixes.