PISet fixes

This commit is contained in:
2024-04-05 20:59:59 +03:00
parent 021411defa
commit 9f29155d07

View File

@@ -181,6 +181,10 @@ public:
return *this; 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 //! Returns if element "t" exists in this set
bool operator[](const T & t) const { return _CSet::contains(t); } bool operator[](const T & t) const { return _CSet::contains(t); }
@@ -192,25 +196,21 @@ public:
//! Unite set with "v" //! Unite set with "v"
PISet<T> & unite(const PISet<T> & v) { PISet<T> & unite(const PISet<T> & v) {
for (typename PIMap<T, uchar>::const_iterator i = v.begin(); i != v.end(); ++i) for (const auto & i: v)
_CSet::insert(i.key(), 0); _CSet::insert(i, 0);
return *this; return *this;
} }
//! Subtract set with "v" //! Subtract set with "v"
PISet<T> & subtract(const PISet<T> & v) { PISet<T> & subtract(const PISet<T> & v) {
for (typename PIMap<T, uchar>::const_iterator i = v.begin(); i != v.end(); ++i) for (const auto & i: v)
_CSet::remove(i.key()); _CSet::remove(i);
return *this; return *this;
} }
//! Intersect set with "v" //! Intersect set with "v"
PISet<T> & intersect(const PISet<T> & v) { PISet<T> & intersect(const PISet<T> & v) {
for (typename _CSet::iterator i = _CSet::begin(); i != _CSet::end(); ++i) _CSet::removeWhere([&v](const T & k, uchar) { return v.contains(k); });
if (!v.contains(i.key())) {
_CSet::remove(i.key());
--i;
}
return *this; return *this;
} }
@@ -229,16 +229,16 @@ public:
//! Returns content of set as PIVector //! Returns content of set as PIVector
PIVector<T> toVector() const { PIVector<T> toVector() const {
PIVector<T> ret; PIVector<T> ret;
for (typename _CSet::const_iterator i = _CSet::begin(); i != _CSet::end(); ++i) for (const auto & i: *this)
ret << i.key(); ret << i;
return ret; return ret;
} }
//! Returns content of set as PIDeque //! Returns content of set as PIDeque
PIDeque<T> toDeque() const { PIDeque<T> toDeque() const {
PIDeque<T> ret; PIDeque<T> ret;
for (typename _CSet::const_iterator i = _CSet::begin(); i != _CSet::end(); ++i) for (const auto & i: *this)
ret << i.key(); ret << i;
return ret; return ret;
} }
}; };