QSet Class | Qt Core 5.15.18 (original) (raw)
Member Function Documentation
QSet<T> QSet::operator+(const QSet<T> &other) const
QSet<T> QSet::operator|(const QSet<T> &other) const
Returns a new QSet that is the union of this set and the other set.
See also unite(), operator|=(), operator&(), and operator-().
QSet<T> &QSet::operator+=(const QSet<T> &other)
QSet<T> &QSet::operator|=(const QSet<T> &other)
Same as unite(other).
See also operator|(), operator&=(), and operator-=().
QSet<T> &QSet::operator+=(const T &value)
QSet<T> &QSet::operator<<(const T &value)
QSet<T> &QSet::operator|=(const T &value)
Inserts a new item value and returns a reference to the set. If value already exists in the set, the set is left unchanged.
See also insert().
template QSet::QSet(InputIterator first, InputIterator last)
Constructs a set with the contents in the iterator range [first, last).
The value type of InputIterator
must be convertible to T
.
Note: If the range [first, last) contains duplicate elements, the first one is retained.
This function was introduced in Qt 5.14.
QSet::QSet(std::initializer_list<T> list)
Constructs a set with a copy of each of the elements in the initializer list list.
This function was introduced in Qt 5.1.
QSet::QSet()
Constructs an empty set.
See also clear().
QSet::const_iterator QSet::begin() const
Returns a const STL-style iterator positioned at the first item in the set.
See also constBegin() and end().
QSet::iterator QSet::begin()
This is an overloaded function.
Returns a non-const STL-style iterator positioned at the first item in the set.
This function was introduced in Qt 4.2.
int QSet::capacity() const
Returns the number of buckets in the set's internal hash table.
The sole purpose of this function is to provide a means of fine tuning QSet's memory usage. In general, you will rarely ever need to call this function. If you want to know how many items are in the set, call size().
See also reserve() and squeeze().
QSet::const_iterator QSet::cbegin() const
Returns a const STL-style iterator positioned at the first item in the set.
This function was introduced in Qt 5.0.
QSet::const_iterator QSet::cend() const
Returns a const STL-style iterator pointing to the imaginary item after the last item in the set.
This function was introduced in Qt 5.0.
void QSet::clear()
Removes all elements from the set.
See also remove().
QSet::const_iterator QSet::constBegin() const
Returns a const STL-style iterator positioned at the first item in the set.
See also begin() and constEnd().
QSet::const_iterator QSet::constEnd() const
Returns a const STL-style iterator pointing to the imaginary item after the last item in the set.
See also constBegin() and end().
QSet::const_iterator QSet::constFind(const T &value) const
Returns a const iterator positioned at the item value in the set. If the set contains no item value, the function returns constEnd().
This function was introduced in Qt 4.2.
See also find() and contains().
bool QSet::contains(const T &value) const
Returns true
if the set contains item value; otherwise returns false.
See also insert(), remove(), and find().
bool QSet::contains(const QSet<T> &other) const
Returns true
if the set contains all items from the other set; otherwise returns false
.
This function was introduced in Qt 4.6.
See also insert(), remove(), and find().
int QSet::count() const
Same as size().
bool QSet::empty() const
Returns true
if the set is empty. This function is provided for STL compatibility. It is equivalent to isEmpty().
QSet::const_iterator QSet::end() const
Returns a const STL-style iterator positioned at the imaginary item after the last item in the set.
See also constEnd() and begin().
QSet::iterator QSet::end()
This is an overloaded function.
Returns a non-const STL-style iterator pointing to the imaginary item after the last item in the set.
This function was introduced in Qt 4.2.
QSet::iterator QSet::erase(QSet::const_iterator pos)
Removes the item at the iterator position pos from the set, and returns an iterator positioned at the next item in the set.
Unlike remove(), this function never causes QSet to rehash its internal data structure. This means that it can safely be called while iterating, and won't affect the order of items in the set.
This function was introduced in Qt 5.7.
QSet::iterator QSet::erase(QSet::iterator pos)
This is an overloaded function.
This function was introduced in Qt 4.2.
QSet::const_iterator QSet::find(const T &value) const
Returns a const iterator positioned at the item value in the set. If the set contains no item value, the function returns constEnd().
This function was introduced in Qt 4.2.
See also constFind() and contains().
QSet::iterator QSet::find(const T &value)
This is an overloaded function.
Returns a non-const iterator positioned at the item value in the set. If the set contains no item value, the function returns end().
This function was introduced in Qt 4.2.
QSet::iterator QSet::insert(const T &value)
Inserts item value into the set, if value isn't already in the set, and returns an iterator pointing at the inserted item.
See also operator<<(), remove(), and contains().
QSet<T> &QSet::intersect(const QSet<T> &other)
Removes all items from this set that are not contained in the other set. A reference to this set is returned.
See also intersects(), operator&=(), unite(), and subtract().
bool QSet::intersects(const QSet<T> &other) const
Returns true
if this set has at least one item in common with other.
This function was introduced in Qt 5.6.
See also contains() and intersect().
bool QSet::isEmpty() const
Returns true
if the set contains no elements; otherwise returns false.
See also size().
bool QSet::remove(const T &value)
Removes any occurrence of item value from the set. Returns true if an item was actually removed; otherwise returns false
.
See also contains() and insert().
void QSet::reserve(int size)
Ensures that the set's internal hash table consists of at least size buckets.
This function is useful for code that needs to build a huge set and wants to avoid repeated reallocation. For example:
QSet<QString> set; set.reserve(20000); for (int i = 0; i < 20000; ++i) set.insert(values[i]);
Ideally, size should be slightly more than the maximum number of elements expected in the set. size doesn't have to be prime, because QSet will use a prime number internally anyway. If size is an underestimate, the worst that will happen is that the QSet will be a bit slower.
In general, you will rarely ever need to call this function. QSet's internal hash table automatically shrinks or grows to provide good performance without wasting too much memory.
See also squeeze() and capacity().
int QSet::size() const
Returns the number of items in the set.
See also isEmpty() and count().
void QSet::squeeze()
Reduces the size of the set's internal hash table to save memory.
The sole purpose of this function is to provide a means of fine tuning QSet's memory usage. In general, you will rarely ever need to call this function.
See also reserve() and capacity().
QSet<T> &QSet::subtract(const QSet<T> &other)
Removes all items from this set that are contained in the other set. Returns a reference to this set.
See also operator-=(), unite(), and intersect().
void QSet::swap(QSet<T> &other)
Swaps set other with this set. This operation is very fast and never fails.
QSet<T> &QSet::unite(const QSet<T> &other)
Each item in the other set that isn't already in this set is inserted into this set. A reference to this set is returned.
See also operator|=(), intersect(), and subtract().
QList<T> QSet::values() const
Returns a new QList containing the elements in the set. The order of the elements in the QList is undefined.
Note: Since Qt 5.14, range constructors are available for Qt's generic container classes and should be used in place of this method.
For example, if you have code like
QSet set; // ... QList list = set.values();
you can rewrite it as
See also QList::QList(InputIterator, InputIterator).
bool QSet::operator!=(const QSet<T> &other) const
Returns true
if the other set is not equal to this set; otherwise returns false
.
Two sets are considered equal if they contain the same elements.
This function requires the value type to implement operator==()
.
See also operator==().
QSet<T> QSet::operator&(const QSet<T> &other) const
Returns a new QSet that is the intersection of this set and the other set.
See also intersect(), operator&=(), operator|(), and operator-().
QSet<T> &QSet::operator&=(const QSet<T> &other)
Same as intersect(other).
See also operator&(), operator|=(), and operator-=().
QSet<T> &QSet::operator&=(const T &value)
This is an overloaded function.
Same as intersect(other), if we consider other to be a set that contains the singleton value.
QSet<T> QSet::operator-(const QSet<T> &other) const
Returns a new QSet that is the set difference of this set and the other set, i.e., this set - other set.
See also subtract(), operator-=(), operator|(), and operator&().
QSet<T> &QSet::operator-=(const QSet<T> &other)
Same as subtract(other).
See also operator-(), operator|=(), and operator&=().
QSet<T> &QSet::operator-=(const T &value)
Removes the occurrence of item value from the set, if it is found, and returns a reference to the set. If the value is not contained the set, nothing is removed.
See also remove().
bool QSet::operator==(const QSet<T> &other) const
Returns true
if the other set is equal to this set; otherwise returns false
.
Two sets are considered equal if they contain the same elements.
This function requires the value type to implement operator==()
.
See also operator!=().