CopperSpice API
1.9.2
|
Template class which provides a set implemented as a hash. More...
Classes | |
class | const_iterator |
Provides an STL style const iterator for QSet More... | |
class | iterator |
Provides an STL style iterator for QSet More... | |
Public Typedefs | |
using | allocator_type = typename std::unordered_set< T, Hash >::allocator_type |
using | const_iterator = typename std::unordered_set< T, Hash >::const_iterator |
using | const_pointer = typename std::unordered_set< T, Hash >::const_pointer |
using | const_reference = typename std::unordered_set< T, Hash >::const_reference |
using | difference_type = typename std::unordered_set< T, Hash >::difference_type |
using | hasher = typename std::unordered_set< T, Hash >::hasher |
using | iterator = typename std::unordered_set< T, Hash >::iterator |
using | Java_Iterator = QSetIterator< T > |
using | Java_MutableIterator = QMutableSetIterator< T > |
using | key_equal = typename std::unordered_set< T, Hash >::key_equal |
using | key_type = typename std::unordered_set< T, Hash >::key_type |
using | pointer = typename std::unordered_set< T, Hash >::pointer |
using | reference = typename std::unordered_set< T, Hash >::reference |
using | size_type = typename std::unordered_set< T, Hash >::difference_type |
using | value_type = typename std::unordered_set< T, Hash >::value_type |
Public Methods | |
QSet () = default | |
QSet (const QSet< T > &other) = default | |
template<class Input_Iterator > | |
QSet (Input_Iterator first, Input_Iterator last) | |
QSet (QSet< T > &&other) = default | |
QSet (std::initializer_list< T > args) | |
iterator | begin () |
const_iterator | begin () const |
size_type | capacity () const |
const_iterator | cbegin () const |
const_iterator | cend () const |
void | clear () |
const_iterator | constBegin () const |
const_iterator | constEnd () const |
const_iterator | constFind (const T &value) const |
bool | contains (const QSet< T > &other) const |
bool | contains (const T &value) const |
size_type | count () const |
bool | empty () const |
iterator | end () |
const_iterator | end () const |
size_type | erase (const key_type &key) |
iterator | erase (const_iterator first, const_iterator last) |
iterator | erase (const_iterator pos) |
iterator | find (const T &value) |
const_iterator | find (const T &value) const |
iterator | insert (const T &value) |
QSet< T > & | intersect (const QSet< T > &other) |
bool | intersects (const QSet< T > &other) const |
bool | isEmpty () const |
bool | operator!= (const QSet< T > &other) const |
QSet< T > | operator& (const QSet< T > &other) const |
QSet< T > & | operator&= (const QSet< T > &other) |
QSet< T > & | operator&= (const T &value) |
QSet< T > | operator+ (const QSet< T > &other) const |
QSet< T > & | operator+= (const QSet< T > &other) |
QSet< T > & | operator+= (const T &value) |
QSet< T > | operator- (const QSet< T > &other) const |
QSet< T > & | operator-= (const QSet< T > &other) |
QSet< T > & | operator-= (const T &value) |
QSet< T > & | operator<< (const T &value) |
QSet< T > & | operator= (const QSet< T > &other) = default |
QSet< T > & | operator= (QSet< T > &&other) = default |
bool | operator== (const QSet< T > &other) const |
QSet< T > | operator| (const QSet< T > &other) const |
QSet< T > & | operator|= (const QSet< T > &other) |
QSet< T > & | operator|= (const T &value) |
bool | remove (const T &value) |
void | reserve (size_type size) |
size_type | size () const |
void | squeeze () |
QSet< T > & | subtract (const QSet< T > &other) |
void | swap (QSet< T > &other) |
QList< T > | toList () const |
QSet< T > & | unite (const QSet< T > &other) |
QList< T > | values () const |
Static Public Methods | |
static QSet< T > | fromList (const QList< T > &list) |
Related Functions | |
These are not member functions | |
QDataStream & | operator<< (QDataStream &stream, const QSet< T > &set) |
QDataStream & | operator>> (QDataStream &stream, QSet< T > &set) |
The QSet class is a template class which provides a set implemented as a hash. This container stores values in an unspecified order and provides very fast lookup of the values.
For an overview and comparison of all containers, refer to the documentation for Container Classes. Refer to the section on Time Complexity for a discussion about which operations will be relatively faster or slower for a given container with a size of n.
The following code is a simple example showing how to declare a QSet.
To insert a value into the set use insert() as shown below.
Another way to insert items into the set is to use operator<<().
To test whether is present in a set use the contains() method.
Items can be removed from the set using remove(). There is also a clear() method that removes all items.
To navigate through all the values stored in a QSet, you can use an iterator. QSet supports both Java style iterators (QSetIterator and QMutableSetIterator) and STL style iterators (QSet::iterator and QSet::const_iterator).
The following shows how to iterate over a QSet<QWidget *> using a Java style iterator.
Here is the same code using an STL style iterator.
QSet is unordered so the iterator sequence can not be assumed to be predictable. If ordering by key is required use a QMap.
To navigate through a QSet you can use a range based for loop.
The QSet value type T should be Default Constructible and Copy Constructible to work with all methods of this class. Data types like QObject are not copy constructible and therefore should never be stored in a container. You can however use a pointer to a QObject or any subclass as the type T.
The type T must provide an operator==()
method and there needs to be a global qHash() function which returns a hash value for an argument of the key's type. Refer to the QHash documentation for a list of types supported by qHash().
The QSet automatically grows and shrinks to provide fast lookups without wasting memory. You can still control the size of the hash table by calling reserve(), if you already know approximately how many elements the QSet will contain, but this is not necessary to obtain good performance. You can also call capacity() to retrieve the hash table's size.
QSet< T >::allocator_type |
Typedef for allocator used by the container.
QSet< T >::const_iterator |
Typedef for std::unordered_set<T>::const_iterator.
QSet< T >::const_pointer |
Typedef for const T *.
QSet< T >::const_reference |
Typedef for const T &;.
QSet< T >::difference_type |
Typedef for const ptrdiff_t.
QSet< T >::hasher |
Typedef for the functor used to hash keys.
QSet< T >::iterator |
Typedef for std::unordered_set<T>::iterator.
QSet< T >::Java_Iterator |
Typedef for the java style const iterator.
QSet< T >::Java_MutableIterator |
Typedef for the java style mutable iterator.
QSet< T >::key_equal |
Typedef for the functor used to compare keys.
QSet< T >::key_type |
Typedef for T.
QSet< T >::pointer |
Typedef for T *.
QSet< T >::reference |
Typedef for T &.
QSet< T >::size_type |
Typedef for int.
QSet< T >::value_type |
Typedef for T.
|
default |
Constructs an empty set.
|
default |
Copy constructs a new QSet from other.
|
default |
Move constructs a new QSet from other.
|
inline |
Construct a set from the std::initializer_list specified by args.
QSet< T >::QSet | ( | Input_Iterator | first, |
Input_Iterator | last | ||
) |
Construct a set containing the elements from first to last.
|
inline |
Returns a non-const STL style iterator positioned at the first item in the set.
|
inline |
Returns a const STL style iterator positioned at the first item in the set.
|
inline |
Returns the number of buckets in the set's internal hash table.
The purpose of this method is to provide a means of fine tuning QSet's memory usage. In general, you will rarely ever need to call this method. If you want to know how many items are in the set, call size().
|
inline |
Returns a const STL style iterator positioned at the first item in the set.
|
inline |
Returns a const STL style iterator pointing to the imaginary item after the last item in the set.
|
inline |
Removes all elements from this QSet.
|
inline |
Returns a const STL style iterator positioned at the first item in the set.
|
inline |
Returns a const STL style iterator pointing to the imaginary item after the last item in the set.
|
inline |
Returns a const iterator positioned at the item value in the set. If the set contains no item value, the method returns constEnd().
|
inline |
|
inline |
|
inline |
Returns true if the QSet is empty.
|
inline |
Returns a non-const STL style iterator pointing to the imaginary item after the last item in the set.
|
inline |
Returns a const STL style iterator positioned at the imaginary item after the last item in the set.
Removes every item matching key from this QSet. Returns how many items were removed.
|
inline |
Removes the items between first and last.
|
inline |
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 method never invalidates iterators. This means that it can safely be called while iterating and will not affect the order of items in the set.
|
inline |
Returns a non-const iterator positioned at the item value in the set. If the set contains no item value, the method returns end().
|
inline |
Returns a const iterator positioned at the item value in the set. If the set contains no item value, the method returns constEnd().
|
static |
Returns a new QSet object containing the data contained in list. Since QSet does not allow duplicates, the resulting QSet might be smaller than the list, because QList can contain duplicates.
|
inline |
Inserts item value into the set, if value is not already in the set, and returns an iterator pointing at the inserted item.
|
inline |
Removes all items from this set that are not contained in the other set. A reference to this set is returned.
|
inline |
Returns true if this set has at least one item in common with other.
|
inline |
Returns true if the set contains no elements, otherwise returns false.
|
inline |
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 method requires the type T to support operator==()
.
|
inline |
Returns a new QSet that is the intersection of this set and the other set.
|
inline |
Equivalent to calling intersect(other).
|
inline |
Removes all elements from this QSet which do not match value.
|
inline |
Returns a new QSet which contains the elements from this QSet combined with elements in other.
|
inline |
Equivalent to calling unite(other).
|
inline |
Inserts a new item value and returns a reference to this QSet. If value already exists, the set is not modified.
|
inline |
Returns a new QSet which contains all elements in this QSet and not in the other QSet.
|
inline |
Equivalent to calling subtract(other).
|
inline |
Removes the occurrence of item value from this set. If the value is not contained in this QSet, nothing is removed. Returns a reference to the set.
|
inline |
Inserts a new item value and returns a reference to the set. If value already exists in the set, the set is left unchanged.
|
default |
Copy assigns from other and returns a reference to this object.
|
default |
Move assigns from other and returns a reference to this object.
|
inline |
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 method requires the type T to support operator==()
.
|
inline |
Returns a new QSet that is the union of this set and the other set.
|
inline |
Equivalent to calling unite(other).
|
inline |
Inserts a new item value and returns a reference to the set. If value already exists in the set, the set is left unchanged.
|
inline |
Removes any occurrence of item value from the set. Returns true if an item was actually removed. otherwise returns false.
|
inline |
Ensures the internal hash table consists of at least size buckets. This method is useful for code which needs to build a huge set and wants to avoid repeated reallocation.
Ideally the size should be slightly larger than the maximum number of elements expected in the set. The size does not need to be a prime number because QSet will round up to the nearest prime number. If size is underestimated the worst which can happen is QSet will be a bit slower. In general, you will rarely need to call this method. The QSet internal hash table automatically shrinks or grows to provide good performance without wasting too much memory.
|
inline |
|
inline |
Reduces the size of the set's internal hash table to save memory.
The purpose of this method is to provide a means to fine tune the internal data structure memory usage. In general, you will rarely ever need to call this method.
|
inline |
Removes all items from this set that are contained in the other set. Returns a reference to this set.
|
inline |
Swaps set other with this set. This operation is very fast and never fails.
QList< T > QSet< T >::toList | ( | ) | const |
Returns a new QList containing the elements in the set. The order of the elements in the QList is undefined.
|
inline |
Each item in the other set that is not already in this set is inserted into this set. A reference to this set is returned.
|
inline |
Returns a new QList containing the elements in the set. The order of the elements in the QList is undefined.
Equivalent to calling toList().
|
related |
Writes the given set to the stream. Returns a reference to the stream. Returns a reference to the stream. This function requires the type T to support operator<<()
.
Refer to Serializing Data Types for additional information.
|
related |
Reads from the stream into the given set. Returns a reference to the stream. This function requires the type T to support operator>>()
.
Refer to Serializing Data Types for additional information.