diff options
author | msherbakov <[email protected]> | 2022-02-10 16:49:16 +0300 |
---|---|---|
committer | Daniil Cherednik <[email protected]> | 2022-02-10 16:49:16 +0300 |
commit | c224a621661ddd69699f9476922eb316607ef57e (patch) | |
tree | 33f4d878aa0a9faa964005e06bfab0272313aa71 /library/cpp/ipmath/range_set.h | |
parent | 29d0b2eeae154d04156e0698067c0c21a97ea61d (diff) |
Restoring authorship annotation for <[email protected]>. Commit 1 of 2.
Diffstat (limited to 'library/cpp/ipmath/range_set.h')
-rw-r--r-- | library/cpp/ipmath/range_set.h | 132 |
1 files changed, 66 insertions, 66 deletions
diff --git a/library/cpp/ipmath/range_set.h b/library/cpp/ipmath/range_set.h index d9e24518224..23a648fb862 100644 --- a/library/cpp/ipmath/range_set.h +++ b/library/cpp/ipmath/range_set.h @@ -1,66 +1,66 @@ -#pragma once - -#include "ipmath.h" - -#include <util/generic/set.h> -#include <util/ysaveload.h> - - -/// @brief Maintains a disjoint set of added ranges. Allows for efficient membership queries -/// for an address in a set of IP ranges. -class TIpRangeSet { - struct TRangeLess { - bool operator()(const TIpAddressRange& lhs, const TIpAddressRange& rhs) const; - }; - - using TTree = TSet<TIpAddressRange, TRangeLess>; - -public: - using iterator = TTree::iterator; - using const_iterator = TTree::const_iterator; - using value_type = TTree::value_type; - using TIterator = TTree::iterator; - using TConstIterator = TTree::const_iterator; - - TIpRangeSet(); - ~TIpRangeSet(); - - void Add(TIpAddressRange range); - - template <typename TContainer> - void Add(TContainer&& addrs) { - using T = typename std::decay<TContainer>::type::value_type; - static_assert(std::is_convertible<T, TIpAddressRange>::value); - - for (auto&& addr : addrs) { - Add(addr); - } - } - - TIpAddressRange::TIpType Type() const; - - bool IsEmpty() const; - bool Contains(TIpv6Address addr) const; - TConstIterator Find(TIpv6Address addr) const; - - TConstIterator Begin() const { - return Ranges_.begin(); - } - - TConstIterator End() const { - return Ranges_.end(); - } - - TConstIterator begin() const { - return Begin(); - } - - TConstIterator end() const { - return End(); - } - - Y_SAVELOAD_DEFINE(Ranges_); - -private: - TTree Ranges_; -}; +#pragma once + +#include "ipmath.h" + +#include <util/generic/set.h> +#include <util/ysaveload.h> + + +/// @brief Maintains a disjoint set of added ranges. Allows for efficient membership queries +/// for an address in a set of IP ranges. +class TIpRangeSet { + struct TRangeLess { + bool operator()(const TIpAddressRange& lhs, const TIpAddressRange& rhs) const; + }; + + using TTree = TSet<TIpAddressRange, TRangeLess>; + +public: + using iterator = TTree::iterator; + using const_iterator = TTree::const_iterator; + using value_type = TTree::value_type; + using TIterator = TTree::iterator; + using TConstIterator = TTree::const_iterator; + + TIpRangeSet(); + ~TIpRangeSet(); + + void Add(TIpAddressRange range); + + template <typename TContainer> + void Add(TContainer&& addrs) { + using T = typename std::decay<TContainer>::type::value_type; + static_assert(std::is_convertible<T, TIpAddressRange>::value); + + for (auto&& addr : addrs) { + Add(addr); + } + } + + TIpAddressRange::TIpType Type() const; + + bool IsEmpty() const; + bool Contains(TIpv6Address addr) const; + TConstIterator Find(TIpv6Address addr) const; + + TConstIterator Begin() const { + return Ranges_.begin(); + } + + TConstIterator End() const { + return Ranges_.end(); + } + + TConstIterator begin() const { + return Begin(); + } + + TConstIterator end() const { + return End(); + } + + Y_SAVELOAD_DEFINE(Ranges_); + +private: + TTree Ranges_; +}; |