You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficserver.apache.org by bn...@apache.org on 2024/01/30 16:24:13 UTC
(trafficserver-libswoc) branch iprangeset created (now 8801284)
This is an automated email from the ASF dual-hosted git repository.
bneradt pushed a change to branch iprangeset
in repository https://gitbox.apache.org/repos/asf/trafficserver-libswoc.git
at 8801284 Add IPRangeSet.
This branch includes the following new commits:
new 8801284 Add IPRangeSet.
The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
(trafficserver-libswoc) 01/01: Add IPRangeSet.
Posted by bn...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
bneradt pushed a commit to branch iprangeset
in repository https://gitbox.apache.org/repos/asf/trafficserver-libswoc.git
commit 880128443398ee87a61034d0d5657dac83fa71c7
Author: Alan M. Carroll <am...@apache.org>
AuthorDate: Thu Dec 8 16:51:41 2022 -0600
Add IPRangeSet.
---
code/include/swoc/IPRange.h | 102 ++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 102 insertions(+)
diff --git a/code/include/swoc/IPRange.h b/code/include/swoc/IPRange.h
index 09c825c..30295fc 100644
--- a/code/include/swoc/IPRange.h
+++ b/code/include/swoc/IPRange.h
@@ -1061,6 +1061,108 @@ protected:
IP6Space _ip6; ///< sub-space containing IPv6 ranges.
};
+/** An IPSpace that contains only addresses.
+ *
+ * This is to @c IPSpace as @c std::set is to @c std::map. The @c value_type is removed from the API
+ * and only the keys are visible. This suits use cases where the goal is to track the presence of
+ * addresses without any additional data.
+ *
+ * @note Because there is only one value stored, there is no difference between @c mark and @c fill.
+ */
+class IPRangeSet
+{
+ using self_type = IPRangeSet;
+
+public:
+ /// Default construct empty set.
+ IPRangeSet() = default;
+
+ /** Add addresses to the set.
+ *
+ * @param r Range of addresses to add.
+ * @return @a this
+ *
+ * Identical to @c fill.
+ */
+ self_type &mark(swoc::IPRange const &r);
+
+ /** Add addresses to the set.
+ *
+ * @param r Range of addresses to add.
+ * @return @a this
+ *
+ * Identical to @c mark.
+ */
+ self_type &fill(swoc::IPRange const &r);
+
+ /// @return @c true if @a addr is in the set.
+ bool contains(swoc::IPAddr const &addr) const;
+
+ /// @return Number of ranges in the set.
+ size_t count() const;
+
+ /// Remove all addresses in the set.
+ void clear();
+
+protected:
+ /// Empty struct to use for payload.
+ /// This declares the struct and defines the singleton instance used.
+ static inline constexpr struct Mark {
+ using self_type = Mark;
+ /// @internal @c IPSpace requires equality / inequality operators.
+ /// These make all instance equal to each other.
+ bool operator==(self_type const &that);
+ bool operator!=(self_type const &that);
+ } MARK{};
+
+ /// The address set.
+ swoc::IPSpace<Mark> _addrs;
+};
+
+inline auto
+IPRangeSet::mark(swoc::IPRange const &r) -> self_type &
+{
+ _addrs.mark(r, MARK);
+ return *this;
+}
+
+inline auto
+IPRangeSet::fill(swoc::IPRange const &r) -> self_type &
+{
+ _addrs.mark(r, MARK);
+ return *this;
+}
+
+inline bool
+IPRangeSet::contains(swoc::IPAddr const &addr) const
+{
+ return _addrs.find(addr) != _addrs.end();
+}
+
+inline size_t
+IPRangeSet::count() const
+{
+ return _addrs.count();
+}
+
+inline void
+IPRangeSet::clear()
+{
+ _addrs.clear();
+}
+
+inline bool
+IPRangeSet::Mark::operator==(IPRangeSet::Mark::self_type const &)
+{
+ return true;
+}
+
+inline bool
+IPRangeSet::Mark::operator!=(IPRangeSet::Mark::self_type const &)
+{
+ return false;
+}
+
template <typename PAYLOAD>
IPSpace<PAYLOAD>::const_iterator::const_iterator(typename IP4Space::iterator const &iter4, typename IP6Space::iterator const &iter6)
: _iter_4(iter4), _iter_6(iter6) {