diff --git a/libs/main/containers/piset.h b/libs/main/containers/piset.h index 6453703a..6eb413dd 100644 --- a/libs/main/containers/piset.h +++ b/libs/main/containers/piset.h @@ -181,6 +181,10 @@ public: return *this; } + //! \~english Tests if element `key` exists in the set. + //! \~russian Проверяет наличие элемента `key` в массиве. + inline bool contains(const T & t) const { return _CSet::contains(t); } + //! Returns if element "t" exists in this set bool operator[](const T & t) const { return _CSet::contains(t); } @@ -192,25 +196,21 @@ public: //! Unite set with "v" PISet & unite(const PISet & v) { - for (typename PIMap::const_iterator i = v.begin(); i != v.end(); ++i) - _CSet::insert(i.key(), 0); + for (const auto & i: v) + _CSet::insert(i, 0); return *this; } //! Subtract set with "v" PISet & subtract(const PISet & v) { - for (typename PIMap::const_iterator i = v.begin(); i != v.end(); ++i) - _CSet::remove(i.key()); + for (const auto & i: v) + _CSet::remove(i); return *this; } //! Intersect set with "v" PISet & intersect(const PISet & v) { - for (typename _CSet::iterator i = _CSet::begin(); i != _CSet::end(); ++i) - if (!v.contains(i.key())) { - _CSet::remove(i.key()); - --i; - } + _CSet::removeWhere([&v](const T & k, uchar) { return v.contains(k); }); return *this; } @@ -229,16 +229,16 @@ public: //! Returns content of set as PIVector PIVector toVector() const { PIVector ret; - for (typename _CSet::const_iterator i = _CSet::begin(); i != _CSet::end(); ++i) - ret << i.key(); + for (const auto & i: *this) + ret << i; return ret; } //! Returns content of set as PIDeque PIDeque toDeque() const { PIDeque ret; - for (typename _CSet::const_iterator i = _CSet::begin(); i != _CSet::end(); ++i) - ret << i.key(); + for (const auto & i: *this) + ret << i; return ret; } };