| 1 | /****************************************************************************
|
|---|
| 2 | **
|
|---|
| 3 | ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
|
|---|
| 4 | ** All rights reserved.
|
|---|
| 5 | ** Contact: Nokia Corporation ([email protected])
|
|---|
| 6 | **
|
|---|
| 7 | ** This file is part of the documentation of the Qt Toolkit.
|
|---|
| 8 | **
|
|---|
| 9 | ** $QT_BEGIN_LICENSE:FDL$
|
|---|
| 10 | ** Commercial Usage
|
|---|
| 11 | ** Licensees holding valid Qt Commercial licenses may use this file in
|
|---|
| 12 | ** accordance with the Qt Commercial License Agreement provided with the
|
|---|
| 13 | ** Software or, alternatively, in accordance with the terms contained in a
|
|---|
| 14 | ** written agreement between you and Nokia.
|
|---|
| 15 | **
|
|---|
| 16 | ** GNU Free Documentation License
|
|---|
| 17 | ** Alternatively, this file may be used under the terms of the GNU Free
|
|---|
| 18 | ** Documentation License version 1.3 as published by the Free Software
|
|---|
| 19 | ** Foundation and appearing in the file included in the packaging of this
|
|---|
| 20 | ** file.
|
|---|
| 21 | **
|
|---|
| 22 | ** If you have questions regarding the use of this file, please contact
|
|---|
| 23 | ** Nokia at [email protected].
|
|---|
| 24 | ** $QT_END_LICENSE$
|
|---|
| 25 | **
|
|---|
| 26 | ****************************************************************************/
|
|---|
| 27 |
|
|---|
| 28 | /*!
|
|---|
| 29 | \class QSet
|
|---|
| 30 | \brief The QSet class is a template class that provides a hash-table-based set.
|
|---|
| 31 |
|
|---|
| 32 | \ingroup tools
|
|---|
| 33 | \ingroup shared
|
|---|
| 34 | \reentrant
|
|---|
| 35 |
|
|---|
| 36 |
|
|---|
| 37 | QSet<T> is one of Qt's generic \l{container classes}. It stores
|
|---|
| 38 | values in an unspecified order and provides very fast lookup of
|
|---|
| 39 | the values. Internally, QSet<T> is implemented as a QHash.
|
|---|
| 40 |
|
|---|
| 41 | Here's an example QSet with QString values:
|
|---|
| 42 |
|
|---|
| 43 | \snippet doc/src/snippets/code/doc_src_qset.qdoc 0
|
|---|
| 44 |
|
|---|
| 45 | To insert a value into the set, use insert():
|
|---|
| 46 |
|
|---|
| 47 | \snippet doc/src/snippets/code/doc_src_qset.qdoc 1
|
|---|
| 48 |
|
|---|
| 49 | Another way to insert items into the set is to use operator<<():
|
|---|
| 50 |
|
|---|
| 51 | \snippet doc/src/snippets/code/doc_src_qset.qdoc 2
|
|---|
| 52 |
|
|---|
| 53 | To test whether an item belongs to the set or not, use contains():
|
|---|
| 54 |
|
|---|
| 55 | \snippet doc/src/snippets/code/doc_src_qset.qdoc 3
|
|---|
| 56 |
|
|---|
| 57 | If you want to navigate through all the values stored in a QSet,
|
|---|
| 58 | you can use an iterator. QSet supports both \l{Java-style
|
|---|
| 59 | iterators} (QSetIterator and QMutableSetIterator) and \l{STL-style
|
|---|
| 60 | iterators} (QSet::iterator and QSet::const_iterator). Here's how
|
|---|
| 61 | to iterate over a QSet<QWidget *> using a Java-style iterator:
|
|---|
| 62 |
|
|---|
| 63 | \snippet doc/src/snippets/code/doc_src_qset.qdoc 4
|
|---|
| 64 |
|
|---|
| 65 | Here's the same code, but using an STL-style iterator:
|
|---|
| 66 |
|
|---|
| 67 | \snippet doc/src/snippets/code/doc_src_qset.qdoc 5
|
|---|
| 68 |
|
|---|
| 69 | QSet is unordered, so an iterator's sequence cannot be assumed to
|
|---|
| 70 | be predictable. If ordering by key is required, use a QMap.
|
|---|
| 71 |
|
|---|
| 72 | To navigate through a QSet, you can also use \l{foreach}:
|
|---|
| 73 |
|
|---|
| 74 | \snippet doc/src/snippets/code/doc_src_qset.qdoc 6
|
|---|
| 75 |
|
|---|
| 76 | Items can be removed from the set using remove(). There is also a
|
|---|
| 77 | clear() function that removes all items.
|
|---|
| 78 |
|
|---|
| 79 | QSet's value data type must be an \l{assignable data type}. You
|
|---|
| 80 | cannot, for example, store a QWidget as a value; instead, store a
|
|---|
| 81 | QWidget *. In addition, the type must provide \c operator==(), and
|
|---|
| 82 | there must also be a global qHash() function that returns a hash
|
|---|
| 83 | value for an argument of the key's type. See the QHash
|
|---|
| 84 | documentation for a list of types supported by qHash().
|
|---|
| 85 |
|
|---|
| 86 | Internally, QSet uses a hash table to perform lookups. The hash
|
|---|
| 87 | table automatically grows and shrinks to provide fast lookups
|
|---|
| 88 | without wasting memory. You can still control the size of the hash
|
|---|
| 89 | table by calling reserve(), if you already know approximately how
|
|---|
| 90 | many elements the QSet will contain, but this isn't necessary to
|
|---|
| 91 | obtain good performance. You can also call capacity() to retrieve
|
|---|
| 92 | the hash table's size.
|
|---|
| 93 |
|
|---|
| 94 | \sa QSetIterator, QMutableSetIterator, QHash, QMap
|
|---|
| 95 | */
|
|---|
| 96 |
|
|---|
| 97 | /*!
|
|---|
| 98 | \fn QSet::QSet()
|
|---|
| 99 |
|
|---|
| 100 | Constructs an empty set.
|
|---|
| 101 |
|
|---|
| 102 | \sa clear()
|
|---|
| 103 | */
|
|---|
| 104 |
|
|---|
| 105 | /*!
|
|---|
| 106 | \fn QSet::QSet(const QSet<T> &other)
|
|---|
| 107 |
|
|---|
| 108 | Constructs a copy of \a other.
|
|---|
| 109 |
|
|---|
| 110 | This operation occurs in \l{constant time}, because QSet is
|
|---|
| 111 | \l{implicitly shared}. This makes returning a QSet from a
|
|---|
| 112 | function very fast. If a shared instance is modified, it will be
|
|---|
| 113 | copied (copy-on-write), and this takes \l{linear time}.
|
|---|
| 114 |
|
|---|
| 115 | \sa operator=()
|
|---|
| 116 | */
|
|---|
| 117 |
|
|---|
| 118 | /*!
|
|---|
| 119 | \fn QSet<T> &QSet::operator=(const QSet<T> &other)
|
|---|
| 120 |
|
|---|
| 121 | Assigns the \a other set to this set and returns a reference to
|
|---|
| 122 | this set.
|
|---|
| 123 | */
|
|---|
| 124 |
|
|---|
| 125 | /*!
|
|---|
| 126 | \fn bool QSet::operator==(const QSet<T> &other) const
|
|---|
| 127 |
|
|---|
| 128 | Returns true if the \a other set is equal to this set; otherwise
|
|---|
| 129 | returns false.
|
|---|
| 130 |
|
|---|
| 131 | Two sets are considered equal if they contain the same elements.
|
|---|
| 132 |
|
|---|
| 133 | This function requires the value type to implement \c operator==().
|
|---|
| 134 |
|
|---|
| 135 | \sa operator!=()
|
|---|
| 136 | */
|
|---|
| 137 |
|
|---|
| 138 | /*!
|
|---|
| 139 | \fn bool QSet::operator!=(const QSet<T> &other) const
|
|---|
| 140 |
|
|---|
| 141 | Returns true if the \a other set is not equal to this set; otherwise
|
|---|
| 142 | returns false.
|
|---|
| 143 |
|
|---|
| 144 | Two sets are considered equal if they contain the same elements.
|
|---|
| 145 |
|
|---|
| 146 | This function requires the value type to implement \c operator==().
|
|---|
| 147 |
|
|---|
| 148 | \sa operator==()
|
|---|
| 149 | */
|
|---|
| 150 |
|
|---|
| 151 | /*!
|
|---|
| 152 | \fn int QSet::size() const
|
|---|
| 153 |
|
|---|
| 154 | Returns the number of items in the set.
|
|---|
| 155 |
|
|---|
| 156 | \sa isEmpty(), count()
|
|---|
| 157 | */
|
|---|
| 158 |
|
|---|
| 159 | /*!
|
|---|
| 160 | \fn bool QSet::isEmpty() const
|
|---|
| 161 |
|
|---|
| 162 | Returns true if the set contains no elements; otherwise returns
|
|---|
| 163 | false.
|
|---|
| 164 |
|
|---|
| 165 | \sa size()
|
|---|
| 166 | */
|
|---|
| 167 |
|
|---|
| 168 | /*!
|
|---|
| 169 | \fn int QSet::capacity() const
|
|---|
| 170 |
|
|---|
| 171 | Returns the number of buckets in the set's internal hash
|
|---|
| 172 | table.
|
|---|
| 173 |
|
|---|
| 174 | The sole purpose of this function is to provide a means of fine
|
|---|
| 175 | tuning QSet's memory usage. In general, you will rarely ever need
|
|---|
| 176 | to call this function. If you want to know how many items are in
|
|---|
| 177 | the set, call size().
|
|---|
| 178 |
|
|---|
| 179 | \sa reserve(), squeeze()
|
|---|
| 180 | */
|
|---|
| 181 |
|
|---|
| 182 | /*! \fn void QSet::reserve(int size)
|
|---|
| 183 |
|
|---|
| 184 | Ensures that the set's internal hash table consists of at
|
|---|
| 185 | least \a size buckets.
|
|---|
| 186 |
|
|---|
| 187 | This function is useful for code that needs to build a huge set
|
|---|
| 188 | and wants to avoid repeated reallocation. For example:
|
|---|
| 189 |
|
|---|
| 190 | \snippet doc/src/snippets/code/doc_src_qset.qdoc 7
|
|---|
| 191 |
|
|---|
| 192 | Ideally, \a size should be slightly more than the maximum number
|
|---|
| 193 | of elements expected in the set. \a size doesn't have to be prime,
|
|---|
| 194 | because QSet will use a prime number internally anyway. If \a size
|
|---|
| 195 | is an underestimate, the worst that will happen is that the QSet
|
|---|
| 196 | will be a bit slower.
|
|---|
| 197 |
|
|---|
| 198 | In general, you will rarely ever need to call this function.
|
|---|
| 199 | QSet's internal hash table automatically shrinks or grows to
|
|---|
| 200 | provide good performance without wasting too much memory.
|
|---|
| 201 |
|
|---|
| 202 | \sa squeeze(), capacity()
|
|---|
| 203 | */
|
|---|
| 204 |
|
|---|
| 205 | /*!
|
|---|
| 206 | \fn void QSet::squeeze()
|
|---|
| 207 |
|
|---|
| 208 | Reduces the size of the set's internal hash table to save
|
|---|
| 209 | memory.
|
|---|
| 210 |
|
|---|
| 211 | The sole purpose of this function is to provide a means of fine
|
|---|
| 212 | tuning QSet's memory usage. In general, you will rarely ever
|
|---|
| 213 | need to call this function.
|
|---|
| 214 |
|
|---|
| 215 | \sa reserve(), capacity()
|
|---|
| 216 | */
|
|---|
| 217 |
|
|---|
| 218 | /*!
|
|---|
| 219 | \fn void QSet::detach()
|
|---|
| 220 |
|
|---|
| 221 | \internal
|
|---|
| 222 |
|
|---|
| 223 | Detaches this set from any other sets with which it may share
|
|---|
| 224 | data.
|
|---|
| 225 |
|
|---|
| 226 | \sa isDetached()
|
|---|
| 227 | */
|
|---|
| 228 |
|
|---|
| 229 | /*! \fn bool QSet::isDetached() const
|
|---|
| 230 |
|
|---|
| 231 | \internal
|
|---|
| 232 |
|
|---|
| 233 | Returns true if the set's internal data isn't shared with any
|
|---|
| 234 | other set object; otherwise returns false.
|
|---|
| 235 |
|
|---|
| 236 | \sa detach()
|
|---|
| 237 | */
|
|---|
| 238 |
|
|---|
| 239 | /*!
|
|---|
| 240 | \fn void QSet::setSharable(bool sharable)
|
|---|
| 241 | \internal
|
|---|
| 242 | */
|
|---|
| 243 |
|
|---|
| 244 | /*!
|
|---|
| 245 | \fn void QSet::clear()
|
|---|
| 246 |
|
|---|
| 247 | Removes all elements from the set.
|
|---|
| 248 |
|
|---|
| 249 | \sa remove()
|
|---|
| 250 | */
|
|---|
| 251 |
|
|---|
| 252 | /*!
|
|---|
| 253 | \fn bool QSet::remove(const T &value)
|
|---|
| 254 |
|
|---|
| 255 | Removes any occurrence of item \a value from the set. Returns
|
|---|
| 256 | true if an item was actually removed; otherwise returns false.
|
|---|
| 257 |
|
|---|
| 258 | \sa contains(), insert()
|
|---|
| 259 | */
|
|---|
| 260 |
|
|---|
| 261 | /*!
|
|---|
| 262 | \fn QSet::iterator QSet::erase(iterator pos)
|
|---|
| 263 | \since 4.2
|
|---|
| 264 |
|
|---|
| 265 | Removes the item at the iterator position \a pos from the set, and
|
|---|
| 266 | returns an iterator positioned at the next item in the set.
|
|---|
| 267 |
|
|---|
| 268 | Unlike remove(), this function never causes QSet to rehash its
|
|---|
| 269 | internal data structure. This means that it can safely be called
|
|---|
| 270 | while iterating, and won't affect the order of items in the set.
|
|---|
| 271 |
|
|---|
| 272 | \sa remove(), find()
|
|---|
| 273 | */
|
|---|
| 274 |
|
|---|
| 275 | /*! \fn QSet::const_iterator QSet::find(const T &value) const
|
|---|
| 276 | \since 4.2
|
|---|
| 277 |
|
|---|
| 278 | Returns a const iterator positioned at the item \a value in the
|
|---|
| 279 | set. If the set contains no item \a value, the function returns
|
|---|
| 280 | constEnd().
|
|---|
| 281 |
|
|---|
| 282 | \sa constFind(), contains()
|
|---|
| 283 | */
|
|---|
| 284 |
|
|---|
| 285 | /*! \fn QSet::iterator QSet::find(const T &value)
|
|---|
| 286 | \since 4.2
|
|---|
| 287 | \overload
|
|---|
| 288 |
|
|---|
| 289 | Returns a non-const iterator positioned at the item \a value in
|
|---|
| 290 | the set. If the set contains no item \a value, the function
|
|---|
| 291 | returns end().
|
|---|
| 292 | */
|
|---|
| 293 |
|
|---|
| 294 | /*! \fn QSet::const_iterator QSet::constFind(const T &value) const
|
|---|
| 295 | \since 4.2
|
|---|
| 296 |
|
|---|
| 297 | Returns a const iterator positioned at the item \a value in the
|
|---|
| 298 | set. If the set contains no item \a value, the function returns
|
|---|
| 299 | constEnd().
|
|---|
| 300 |
|
|---|
| 301 | \sa find(), contains()
|
|---|
| 302 | */
|
|---|
| 303 |
|
|---|
| 304 | /*!
|
|---|
| 305 | \fn bool QSet::contains(const T &value) const
|
|---|
| 306 |
|
|---|
| 307 | Returns true if the set contains item \a value; otherwise returns
|
|---|
| 308 | false.
|
|---|
| 309 |
|
|---|
| 310 | \sa insert(), remove(), find()
|
|---|
| 311 | */
|
|---|
| 312 |
|
|---|
| 313 | /*!
|
|---|
| 314 | \fn bool QSet::contains(const QSet<T> &other) const
|
|---|
| 315 | \since 4.6
|
|---|
| 316 |
|
|---|
| 317 | Returns true if the set contains all items from the \a other set;
|
|---|
| 318 | otherwise returns false.
|
|---|
| 319 |
|
|---|
| 320 | \sa insert(), remove(), find()
|
|---|
| 321 | */
|
|---|
| 322 |
|
|---|
| 323 | /*! \fn QSet::const_iterator QSet::begin() const
|
|---|
| 324 |
|
|---|
| 325 | Returns a const \l{STL-style iterator} positioned at the first
|
|---|
| 326 | item in the set.
|
|---|
| 327 |
|
|---|
| 328 | \sa constBegin(), end()
|
|---|
| 329 | */
|
|---|
| 330 |
|
|---|
| 331 | /*! \fn QSet::iterator QSet::begin()
|
|---|
| 332 | \since 4.2
|
|---|
| 333 | \overload
|
|---|
| 334 |
|
|---|
| 335 | Returns a non-const \l{STL-style iterator} positioned at the first
|
|---|
| 336 | item in the set.
|
|---|
| 337 | */
|
|---|
| 338 |
|
|---|
| 339 | /*! \fn QSet::const_iterator QSet::constBegin() const
|
|---|
| 340 |
|
|---|
| 341 | Returns a const \l{STL-style iterator} positioned at the first
|
|---|
| 342 | item in the set.
|
|---|
| 343 |
|
|---|
| 344 | \sa begin(), constEnd()
|
|---|
| 345 | */
|
|---|
| 346 |
|
|---|
| 347 | /*! \fn QSet::const_iterator QSet::end() const
|
|---|
| 348 |
|
|---|
| 349 | Returns a const \l{STL-style iterator} positioned at the imaginary
|
|---|
| 350 | item after the last item in the set.
|
|---|
| 351 |
|
|---|
| 352 | \sa constEnd(), begin()
|
|---|
| 353 | */
|
|---|
| 354 |
|
|---|
| 355 | /*! \fn QSet::iterator QSet::end()
|
|---|
| 356 | \since 4.2
|
|---|
| 357 | \overload
|
|---|
| 358 |
|
|---|
| 359 | Returns a non-const \l{STL-style iterator} pointing to the
|
|---|
| 360 | imaginary item after the last item in the set.
|
|---|
| 361 | */
|
|---|
| 362 |
|
|---|
| 363 | /*! \fn QSet::const_iterator QSet::constEnd() const
|
|---|
| 364 |
|
|---|
| 365 | Returns a const \l{STL-style iterator} pointing to the imaginary
|
|---|
| 366 | item after the last item in the set.
|
|---|
| 367 |
|
|---|
| 368 | \sa constBegin(), end()
|
|---|
| 369 | */
|
|---|
| 370 |
|
|---|
| 371 | /*!
|
|---|
| 372 | \typedef QSet::Iterator
|
|---|
| 373 | \since 4.2
|
|---|
| 374 |
|
|---|
| 375 | Qt-style synonym for QSet::iterator.
|
|---|
| 376 | */
|
|---|
| 377 |
|
|---|
| 378 | /*!
|
|---|
| 379 | \typedef QSet::ConstIterator
|
|---|
| 380 |
|
|---|
| 381 | Qt-style synonym for QSet::const_iterator.
|
|---|
| 382 | */
|
|---|
| 383 |
|
|---|
| 384 | /*!
|
|---|
| 385 | \typedef QSet::const_pointer
|
|---|
| 386 |
|
|---|
| 387 | Typedef for const T *. Provided for STL compatibility.
|
|---|
| 388 | */
|
|---|
| 389 |
|
|---|
| 390 | /*!
|
|---|
| 391 | \typedef QSet::const_reference
|
|---|
| 392 |
|
|---|
| 393 | Typedef for const T &. Provided for STL compatibility.
|
|---|
| 394 | */
|
|---|
| 395 |
|
|---|
| 396 | /*!
|
|---|
| 397 | \typedef QSet::difference_type
|
|---|
| 398 |
|
|---|
| 399 | Typedef for const ptrdiff_t. Provided for STL compatibility.
|
|---|
| 400 | */
|
|---|
| 401 |
|
|---|
| 402 | /*!
|
|---|
| 403 | \typedef QSet::key_type
|
|---|
| 404 |
|
|---|
| 405 | Typedef for T. Provided for STL compatibility.
|
|---|
| 406 | */
|
|---|
| 407 |
|
|---|
| 408 | /*!
|
|---|
| 409 | \typedef QSet::pointer
|
|---|
| 410 |
|
|---|
| 411 | Typedef for T *. Provided for STL compatibility.
|
|---|
| 412 | */
|
|---|
| 413 |
|
|---|
| 414 | /*!
|
|---|
| 415 | \typedef QSet::reference
|
|---|
| 416 |
|
|---|
| 417 | Typedef for T &. Provided for STL compatibility.
|
|---|
| 418 | */
|
|---|
| 419 |
|
|---|
| 420 | /*!
|
|---|
| 421 | \typedef QSet::size_type
|
|---|
| 422 |
|
|---|
| 423 | Typedef for int. Provided for STL compatibility.
|
|---|
| 424 | */
|
|---|
| 425 |
|
|---|
| 426 | /*!
|
|---|
| 427 | \typedef QSet::value_type
|
|---|
| 428 |
|
|---|
| 429 | Typedef for T. Provided for STL compatibility.
|
|---|
| 430 | */
|
|---|
| 431 |
|
|---|
| 432 | /*!
|
|---|
| 433 | \fn QSet::const_iterator QSet::insert(const T &value)
|
|---|
| 434 |
|
|---|
| 435 | Inserts item \a value into the set, if \a value isn't already
|
|---|
| 436 | in the set, and returns an iterator pointing at the inserted
|
|---|
| 437 | item.
|
|---|
| 438 |
|
|---|
| 439 | \sa operator<<(), remove(), contains()
|
|---|
| 440 | */
|
|---|
| 441 |
|
|---|
| 442 | /*!
|
|---|
| 443 | \fn QSet<T> &QSet::unite(const QSet<T> &other)
|
|---|
| 444 |
|
|---|
| 445 | Each item in the \a other set that isn't already in this set is
|
|---|
| 446 | inserted into this set. A reference to this set is returned.
|
|---|
| 447 |
|
|---|
| 448 | \sa operator|=(), intersect(), subtract()
|
|---|
| 449 | */
|
|---|
| 450 |
|
|---|
| 451 | /*!
|
|---|
| 452 | \fn QSet<T> &QSet::intersect(const QSet<T> &other)
|
|---|
| 453 |
|
|---|
| 454 | Removes all items from this set that are not contained in the
|
|---|
| 455 | \a other set. A reference to this set is returned.
|
|---|
| 456 |
|
|---|
| 457 | \sa operator&=(), unite(), subtract()
|
|---|
| 458 | */
|
|---|
| 459 |
|
|---|
| 460 | /*!
|
|---|
| 461 | \fn QSet<T> &QSet::subtract(const QSet<T> &other)
|
|---|
| 462 |
|
|---|
| 463 | Removes all items from this set that are contained in the
|
|---|
| 464 | \a other set. Returns a reference to this set.
|
|---|
| 465 |
|
|---|
| 466 | \sa operator-=(), unite(), intersect()
|
|---|
| 467 | */
|
|---|
| 468 |
|
|---|
| 469 | /*!
|
|---|
| 470 | \fn bool QSet::empty() const
|
|---|
| 471 |
|
|---|
| 472 | Returns true if the set is empty. This function is provided
|
|---|
| 473 | for STL compatibility. It is equivalent to isEmpty().
|
|---|
| 474 | */
|
|---|
| 475 |
|
|---|
| 476 | /*!
|
|---|
| 477 | \fn bool QSet::count() const
|
|---|
| 478 |
|
|---|
| 479 | Same as size().
|
|---|
| 480 | */
|
|---|
| 481 |
|
|---|
| 482 | /*!
|
|---|
| 483 | \fn QSet<T> &QSet::operator<<(const T &value)
|
|---|
| 484 | \fn QSet<T> &QSet::operator+=(const T &value)
|
|---|
| 485 | \fn QSet<T> &QSet::operator|=(const T &value)
|
|---|
| 486 |
|
|---|
| 487 | Inserts a new item \a value and returns a reference to the set.
|
|---|
| 488 | If \a value already exists in the set, the set is left unchanged.
|
|---|
| 489 |
|
|---|
| 490 | \sa insert()
|
|---|
| 491 | */
|
|---|
| 492 |
|
|---|
| 493 | /*!
|
|---|
| 494 | \fn QSet<T> &QSet::operator-=(const T &value)
|
|---|
| 495 |
|
|---|
| 496 | Removes the occurrence of item \a value from the set, if
|
|---|
| 497 | it is found, and returns a reference to the set. If the
|
|---|
| 498 | \a value is not contained the set, nothing is removed.
|
|---|
| 499 |
|
|---|
| 500 | \sa remove()
|
|---|
| 501 | */
|
|---|
| 502 |
|
|---|
| 503 | /*!
|
|---|
| 504 | \fn QSet<T> &QSet::operator|=(const QSet<T> &other)
|
|---|
| 505 | \fn QSet<T> &QSet::operator+=(const QSet<T> &other)
|
|---|
| 506 |
|
|---|
| 507 | Same as unite(\a other).
|
|---|
| 508 |
|
|---|
| 509 | \sa operator|(), operator&=(), operator-=()
|
|---|
| 510 | */
|
|---|
| 511 |
|
|---|
| 512 | /*!
|
|---|
| 513 | \fn QSet<T> &QSet::operator&=(const QSet<T> &other)
|
|---|
| 514 |
|
|---|
| 515 | Same as intersect(\a other).
|
|---|
| 516 |
|
|---|
| 517 | \sa operator&(), operator|=(), operator-=()
|
|---|
| 518 | */
|
|---|
| 519 |
|
|---|
| 520 | /*!
|
|---|
| 521 | \fn QSet<T> &QSet::operator&=(const T &value)
|
|---|
| 522 |
|
|---|
| 523 | \overload
|
|---|
| 524 |
|
|---|
| 525 | Same as intersect(\e{other}), if we consider \e{other} to be a set
|
|---|
| 526 | that contains the singleton \a value.
|
|---|
| 527 | */
|
|---|
| 528 |
|
|---|
| 529 |
|
|---|
| 530 | /*!
|
|---|
| 531 | \fn QSet<T> &QSet::operator-=(const QSet<T> &other)
|
|---|
| 532 |
|
|---|
| 533 | Same as subtract(\a{other}).
|
|---|
| 534 |
|
|---|
| 535 | \sa operator-(), operator|=(), operator&=()
|
|---|
| 536 | */
|
|---|
| 537 |
|
|---|
| 538 | /*!
|
|---|
| 539 | \fn QSet<T> QSet::operator|(const QSet<T> &other) const
|
|---|
| 540 | \fn QSet<T> QSet::operator+(const QSet<T> &other) const
|
|---|
| 541 |
|
|---|
| 542 | Returns a new QSet that is the union of this set and the
|
|---|
| 543 | \a other set.
|
|---|
| 544 |
|
|---|
| 545 | \sa unite(), operator|=(), operator&(), operator-()
|
|---|
| 546 | */
|
|---|
| 547 |
|
|---|
| 548 | /*!
|
|---|
| 549 | \fn QSet<T> QSet::operator&(const QSet<T> &other) const
|
|---|
| 550 |
|
|---|
| 551 | Returns a new QSet that is the intersection of this set and the
|
|---|
| 552 | \a other set.
|
|---|
| 553 |
|
|---|
| 554 | \sa intersect(), operator&=(), operator|(), operator-()
|
|---|
| 555 | */
|
|---|
| 556 |
|
|---|
| 557 | /*!
|
|---|
| 558 | \fn QSet<T> QSet::operator-(const QSet<T> &other) const
|
|---|
| 559 |
|
|---|
| 560 | Returns a new QSet that is the set difference of this set and
|
|---|
| 561 | the \a other set, i.e., this set - \a other set.
|
|---|
| 562 |
|
|---|
| 563 | \sa subtract(), operator-=(), operator|(), operator&()
|
|---|
| 564 | */
|
|---|
| 565 |
|
|---|
| 566 | /*!
|
|---|
| 567 | \fn QSet<T> QSet::operator-(const QSet<T> &other)
|
|---|
| 568 | \fn QSet<T> QSet::operator|(const QSet<T> &other)
|
|---|
| 569 | \fn QSet<T> QSet::operator+(const QSet<T> &other)
|
|---|
| 570 | \fn QSet<T> QSet::operator&(const QSet<T> &other)
|
|---|
| 571 | \internal
|
|---|
| 572 |
|
|---|
| 573 | These will go away in Qt 5.
|
|---|
| 574 | */
|
|---|
| 575 |
|
|---|
| 576 | /*!
|
|---|
| 577 | \class QSet::iterator
|
|---|
| 578 | \since 4.2
|
|---|
| 579 | \brief The QSet::iterator class provides an STL-style non-const iterator for QSet.
|
|---|
| 580 |
|
|---|
| 581 | QSet features both \l{STL-style iterators} and
|
|---|
| 582 | \l{Java-style iterators}. The STL-style iterators are more
|
|---|
| 583 | low-level and more cumbersome to use; on the other hand, they are
|
|---|
| 584 | slightly faster and, for developers who already know STL, have
|
|---|
| 585 | the advantage of familiarity.
|
|---|
| 586 |
|
|---|
| 587 | QSet<T>::iterator allows you to iterate over a QSet and to remove
|
|---|
| 588 | items (using QSet::erase()) while you iterate. (QSet doesn't let
|
|---|
| 589 | you \e modify a value through an iterator, because that
|
|---|
| 590 | would potentially require moving the value in the internal hash
|
|---|
| 591 | table used by QSet.) If you want to iterate over a const QSet,
|
|---|
| 592 | you should use QSet::const_iterator. It is generally good
|
|---|
| 593 | practice to use QSet::const_iterator on a non-const QSet as well,
|
|---|
| 594 | unless you need to change the QSet through the iterator. Const
|
|---|
| 595 | iterators are slightly faster, and can improve code readability.
|
|---|
| 596 |
|
|---|
| 597 | QSet\<T\>::iterator allows you to iterate over a QSet\<T\> and
|
|---|
| 598 | modify it as you go (using QSet::erase()). However,
|
|---|
| 599 |
|
|---|
| 600 | The default QSet::iterator constructor creates an uninitialized
|
|---|
| 601 | iterator. You must initialize it using a function like
|
|---|
| 602 | QSet::begin(), QSet::end(), or QSet::insert() before you can
|
|---|
| 603 | start iterating. Here's a typical loop that prints all the items
|
|---|
| 604 | stored in a set:
|
|---|
| 605 |
|
|---|
| 606 | \snippet doc/src/snippets/code/doc_src_qset.qdoc 8
|
|---|
| 607 |
|
|---|
| 608 | Here's a loop that removes certain items (all those that start
|
|---|
| 609 | with 'J') from a set while iterating:
|
|---|
| 610 |
|
|---|
| 611 | \snippet doc/src/snippets/code/doc_src_qset.qdoc 9
|
|---|
| 612 |
|
|---|
| 613 | STL-style iterators can be used as arguments to \l{generic
|
|---|
| 614 | algorithms}. For example, here's how to find an item in the set
|
|---|
| 615 | using the qFind() algorithm:
|
|---|
| 616 |
|
|---|
| 617 | \snippet doc/src/snippets/code/doc_src_qset.qdoc 10
|
|---|
| 618 |
|
|---|
| 619 | Multiple iterators can be used on the same set. However, you may
|
|---|
| 620 | not attempt to modify the container while iterating on it.
|
|---|
| 621 |
|
|---|
| 622 | \sa QSet::const_iterator, QMutableSetIterator
|
|---|
| 623 | */
|
|---|
| 624 |
|
|---|
| 625 | /*!
|
|---|
| 626 | \class QSet::const_iterator
|
|---|
| 627 | \brief The QSet::const_iterator class provides an STL-style const iterator for QSet.
|
|---|
| 628 | \since 4.2
|
|---|
| 629 |
|
|---|
| 630 | QSet features both \l{STL-style iterators} and
|
|---|
| 631 | \l{Java-style iterators}. The STL-style iterators are more
|
|---|
| 632 | low-level and more cumbersome to use; on the other hand, they are
|
|---|
| 633 | slightly faster and, for developers who already know STL, have
|
|---|
| 634 | the advantage of familiarity.
|
|---|
| 635 |
|
|---|
| 636 | QSet\<Key, T\>::const_iterator allows you to iterate over a QSet.
|
|---|
| 637 | If you want to modify the QSet as you iterate over it, you must
|
|---|
| 638 | use QSet::iterator instead. It is generally good practice to use
|
|---|
| 639 | QSet::const_iterator on a non-const QSet as well, unless you need
|
|---|
| 640 | to change the QSet through the iterator. Const iterators are
|
|---|
| 641 | slightly faster, and can improve code readability.
|
|---|
| 642 |
|
|---|
| 643 | The default QSet::const_iterator constructor creates an
|
|---|
| 644 | uninitialized iterator. You must initialize it using a function
|
|---|
| 645 | like QSet::begin(), QSet::end(), or QSet::insert() before you can
|
|---|
| 646 | start iterating. Here's a typical loop that prints all the items
|
|---|
| 647 | stored in a set:
|
|---|
| 648 |
|
|---|
| 649 | \snippet doc/src/snippets/code/doc_src_qset.qdoc 11
|
|---|
| 650 |
|
|---|
| 651 | STL-style iterators can be used as arguments to \l{generic
|
|---|
| 652 | algorithms}. For example, here's how to find an item in the set
|
|---|
| 653 | using the qFind() algorithm:
|
|---|
| 654 |
|
|---|
| 655 | \snippet doc/src/snippets/code/doc_src_qset.qdoc 12
|
|---|
| 656 |
|
|---|
| 657 | Multiple iterators can be used on the same set. However, you may
|
|---|
| 658 | not attempt to modify the container while iterating on it.
|
|---|
| 659 |
|
|---|
| 660 | \sa QSet::iterator, QSetIterator
|
|---|
| 661 | */
|
|---|
| 662 |
|
|---|
| 663 | /*!
|
|---|
| 664 | \fn QSet::iterator::iterator()
|
|---|
| 665 | \fn QSet::const_iterator::const_iterator()
|
|---|
| 666 |
|
|---|
| 667 | Constructs an uninitialized iterator.
|
|---|
| 668 |
|
|---|
| 669 | Functions like operator*() and operator++() should not be called
|
|---|
| 670 | on an uninitialized iterator. Use operator=() to assign a value
|
|---|
| 671 | to it before using it.
|
|---|
| 672 |
|
|---|
| 673 | \sa QSet::begin(), QSet::end()
|
|---|
| 674 | */
|
|---|
| 675 |
|
|---|
| 676 | /*!
|
|---|
| 677 | \fn QSet::iterator::iterator(typename Hash::iterator i)
|
|---|
| 678 | \fn QSet::const_iterator::const_iterator(typename Hash::const_iterator i)
|
|---|
| 679 |
|
|---|
| 680 | \internal
|
|---|
| 681 | */
|
|---|
| 682 |
|
|---|
| 683 | /*!
|
|---|
| 684 | \typedef QSet::iterator::iterator_category
|
|---|
| 685 | \typedef QSet::const_iterator::iterator_category
|
|---|
| 686 |
|
|---|
| 687 | Synonyms for \e {std::bidirectional_iterator_tag} indicating
|
|---|
| 688 | these iterators are bidirectional iterators.
|
|---|
| 689 | */
|
|---|
| 690 |
|
|---|
| 691 | /*!
|
|---|
| 692 | \typedef QSet::iterator::difference_type
|
|---|
| 693 | \typedef QSet::const_iterator::difference_type
|
|---|
| 694 |
|
|---|
| 695 | \internal
|
|---|
| 696 | */
|
|---|
| 697 |
|
|---|
| 698 | /*!
|
|---|
| 699 | \typedef QSet::iterator::value_type
|
|---|
| 700 | \typedef QSet::const_iterator::value_type
|
|---|
| 701 |
|
|---|
| 702 | \internal
|
|---|
| 703 | */
|
|---|
| 704 |
|
|---|
| 705 | /*!
|
|---|
| 706 | \typedef QSet::iterator::pointer
|
|---|
| 707 | \typedef QSet::const_iterator::pointer
|
|---|
| 708 |
|
|---|
| 709 | \internal
|
|---|
| 710 | */
|
|---|
| 711 |
|
|---|
| 712 | /*!
|
|---|
| 713 | \typedef QSet::iterator::reference
|
|---|
| 714 | \typedef QSet::const_iterator::reference
|
|---|
| 715 |
|
|---|
| 716 | \internal
|
|---|
| 717 | */
|
|---|
| 718 |
|
|---|
| 719 | /*!
|
|---|
| 720 | \fn QSet::iterator::iterator(const iterator &other)
|
|---|
| 721 | \fn QSet::const_iterator::const_iterator(const const_iterator &other)
|
|---|
| 722 |
|
|---|
| 723 | Constructs a copy of \a other.
|
|---|
| 724 | */
|
|---|
| 725 |
|
|---|
| 726 | /*!
|
|---|
| 727 | \fn QSet::const_iterator::const_iterator(const iterator &other)
|
|---|
| 728 | \since 4.2
|
|---|
| 729 | \overload
|
|---|
| 730 |
|
|---|
| 731 | Constructs a copy of \a other.
|
|---|
| 732 | */
|
|---|
| 733 |
|
|---|
| 734 | /*!
|
|---|
| 735 | \fn QSet::iterator &QSet::iterator::operator=(const iterator &other)
|
|---|
| 736 | \fn QSet::const_iterator &QSet::const_iterator::operator=(const const_iterator &other)
|
|---|
| 737 |
|
|---|
| 738 | Assigns \a other to this iterator.
|
|---|
| 739 | */
|
|---|
| 740 |
|
|---|
| 741 | /*!
|
|---|
| 742 | \fn const T &QSet::iterator::operator*() const
|
|---|
| 743 | \fn const T &QSet::const_iterator::operator*() const
|
|---|
| 744 |
|
|---|
| 745 | Returns a reference to the current item.
|
|---|
| 746 |
|
|---|
| 747 | \sa operator->()
|
|---|
| 748 | */
|
|---|
| 749 |
|
|---|
| 750 | /*!
|
|---|
| 751 | \fn const T *QSet::iterator::operator->() const
|
|---|
| 752 | \fn const T *QSet::const_iterator::operator->() const
|
|---|
| 753 |
|
|---|
| 754 | Returns a pointer to the current item.
|
|---|
| 755 |
|
|---|
| 756 | \sa operator*()
|
|---|
| 757 | */
|
|---|
| 758 |
|
|---|
| 759 | /*!
|
|---|
| 760 | \fn bool QSet::iterator::operator==(const iterator &other) const
|
|---|
| 761 | \fn bool QSet::const_iterator::operator==(const const_iterator &other) const
|
|---|
| 762 |
|
|---|
| 763 | Returns true if \a other points to the same item as this
|
|---|
| 764 | iterator; otherwise returns false.
|
|---|
| 765 |
|
|---|
| 766 | \sa operator!=()
|
|---|
| 767 | */
|
|---|
| 768 |
|
|---|
| 769 | /*!
|
|---|
| 770 | \fn bool QSet::iterator::operator==(const const_iterator &other) const
|
|---|
| 771 | \fn bool QSet::iterator::operator!=(const const_iterator &other) const
|
|---|
| 772 |
|
|---|
| 773 | \overload
|
|---|
| 774 | */
|
|---|
| 775 |
|
|---|
| 776 | /*!
|
|---|
| 777 | \fn bool QSet::iterator::operator!=(const iterator &other) const
|
|---|
| 778 | \fn bool QSet::const_iterator::operator!=(const const_iterator &other) const
|
|---|
| 779 |
|
|---|
| 780 | Returns true if \a other points to a different item than this
|
|---|
| 781 | iterator; otherwise returns false.
|
|---|
| 782 |
|
|---|
| 783 | \sa operator==()
|
|---|
| 784 | */
|
|---|
| 785 |
|
|---|
| 786 | /*!
|
|---|
| 787 | \fn QSet::iterator &QSet::iterator::operator++()
|
|---|
| 788 | \fn QSet::const_iterator &QSet::const_iterator::operator++()
|
|---|
| 789 |
|
|---|
| 790 | The prefix ++ operator (\c{++it}) advances the iterator to the
|
|---|
| 791 | next item in the set and returns an iterator to the new current
|
|---|
| 792 | item.
|
|---|
| 793 |
|
|---|
| 794 | Calling this function on QSet::constEnd() leads to
|
|---|
| 795 | undefined results.
|
|---|
| 796 |
|
|---|
| 797 | \sa operator--()
|
|---|
| 798 | */
|
|---|
| 799 |
|
|---|
| 800 | /*!
|
|---|
| 801 | \fn QSet::iterator QSet::iterator::operator++(int)
|
|---|
| 802 | \fn QSet::const_iterator QSet::const_iterator::operator++(int)
|
|---|
| 803 |
|
|---|
| 804 | \overload
|
|---|
| 805 |
|
|---|
| 806 | The postfix ++ operator (\c{it++}) advances the iterator to the
|
|---|
| 807 | next item in the set and returns an iterator to the previously
|
|---|
| 808 | current item.
|
|---|
| 809 | */
|
|---|
| 810 |
|
|---|
| 811 | /*!
|
|---|
| 812 | \fn QSet::iterator &QSet::iterator::operator--()
|
|---|
| 813 | \fn QSet::const_iterator &QSet::const_iterator::operator--()
|
|---|
| 814 |
|
|---|
| 815 | The prefix -- operator (\c{--it}) makes the preceding item
|
|---|
| 816 | current and returns an iterator to the new current item.
|
|---|
| 817 |
|
|---|
| 818 | Calling this function on QSet::begin() leads to undefined
|
|---|
| 819 | results.
|
|---|
| 820 |
|
|---|
| 821 | \sa operator++()
|
|---|
| 822 | */
|
|---|
| 823 |
|
|---|
| 824 | /*!
|
|---|
| 825 | \fn QSet::iterator QSet::iterator::operator--(int)
|
|---|
| 826 | \fn QSet::const_iterator QSet::const_iterator::operator--(int)
|
|---|
| 827 |
|
|---|
| 828 | \overload
|
|---|
| 829 |
|
|---|
| 830 | The postfix -- operator (\c{it--}) makes the preceding item
|
|---|
| 831 | current and returns an iterator to the previously current item.
|
|---|
| 832 | */
|
|---|
| 833 |
|
|---|
| 834 | /*!
|
|---|
| 835 | \fn QSet::iterator QSet::iterator::operator+(int j) const
|
|---|
| 836 | \fn QSet::const_iterator QSet::const_iterator::operator+(int j) const
|
|---|
| 837 |
|
|---|
| 838 | Returns an iterator to the item at \a j positions forward from
|
|---|
| 839 | this iterator. (If \a j is negative, the iterator goes backward.)
|
|---|
| 840 |
|
|---|
| 841 | This operation can be slow for large \a j values.
|
|---|
| 842 |
|
|---|
| 843 | \sa operator-()
|
|---|
| 844 | */
|
|---|
| 845 |
|
|---|
| 846 | /*!
|
|---|
| 847 | \fn QSet::iterator QSet::iterator::operator-(int j) const
|
|---|
| 848 | \fn QSet::const_iterator QSet::const_iterator::operator-(int j) const
|
|---|
| 849 |
|
|---|
| 850 | Returns an iterator to the item at \a j positions backward from
|
|---|
| 851 | this iterator. (If \a j is negative, the iterator goes forward.)
|
|---|
| 852 |
|
|---|
| 853 | This operation can be slow for large \a j values.
|
|---|
| 854 |
|
|---|
| 855 | \sa operator+()
|
|---|
| 856 | */
|
|---|
| 857 |
|
|---|
| 858 | /*!
|
|---|
| 859 | \fn QSet::iterator &QSet::iterator::operator+=(int j)
|
|---|
| 860 | \fn QSet::const_iterator &QSet::const_iterator::operator+=(int j)
|
|---|
| 861 |
|
|---|
| 862 | Advances the iterator by \a j items. (If \a j is negative, the
|
|---|
| 863 | iterator goes backward.)
|
|---|
| 864 |
|
|---|
| 865 | This operation can be slow for large \a j values.
|
|---|
| 866 |
|
|---|
| 867 | \sa operator-=(), operator+()
|
|---|
| 868 | */
|
|---|
| 869 |
|
|---|
| 870 | /*!
|
|---|
| 871 | \fn QSet::iterator &QSet::iterator::operator-=(int j)
|
|---|
| 872 | \fn QSet::const_iterator &QSet::const_iterator::operator-=(int j)
|
|---|
| 873 |
|
|---|
| 874 | Makes the iterator go back by \a j items. (If \a j is negative,
|
|---|
| 875 | the iterator goes forward.)
|
|---|
| 876 |
|
|---|
| 877 | This operation can be slow for large \a j values.
|
|---|
| 878 |
|
|---|
| 879 | \sa operator+=(), operator-()
|
|---|
| 880 | */
|
|---|
| 881 |
|
|---|
| 882 | /*! \fn QList<T> QSet<T>::toList() const
|
|---|
| 883 |
|
|---|
| 884 | Returns a new QList containing the elements in the set. The
|
|---|
| 885 | order of the elements in the QList is undefined.
|
|---|
| 886 |
|
|---|
| 887 | Example:
|
|---|
| 888 |
|
|---|
| 889 | \snippet doc/src/snippets/code/doc_src_qset.qdoc 13
|
|---|
| 890 |
|
|---|
| 891 | \sa fromList(), QList::fromSet(), qSort()
|
|---|
| 892 | */
|
|---|
| 893 |
|
|---|
| 894 | /*! \fn QList<T> QSet<T>::values() const
|
|---|
| 895 |
|
|---|
| 896 | Returns a new QList containing the elements in the set. The
|
|---|
| 897 | order of the elements in the QList is undefined.
|
|---|
| 898 |
|
|---|
| 899 | This is the same as toList().
|
|---|
| 900 |
|
|---|
| 901 | \sa fromList(), QList::fromSet(), qSort()
|
|---|
| 902 | */
|
|---|
| 903 |
|
|---|
| 904 |
|
|---|
| 905 | /*! \fn QSet<T> QSet<T>::fromList(const QList<T> &list)
|
|---|
| 906 |
|
|---|
| 907 | Returns a new QSet object containing the data contained in \a
|
|---|
| 908 | list. Since QSet doesn't allow duplicates, the resulting QSet
|
|---|
| 909 | might be smaller than the \a list, because QList can contain
|
|---|
| 910 | duplicates.
|
|---|
| 911 |
|
|---|
| 912 | Example:
|
|---|
| 913 |
|
|---|
| 914 | \snippet doc/src/snippets/code/doc_src_qset.qdoc 14
|
|---|
| 915 |
|
|---|
| 916 | \sa toList(), QList::toSet()
|
|---|
| 917 | */
|
|---|
| 918 |
|
|---|
| 919 | /*!
|
|---|
| 920 | \fn QDataStream &operator<<(QDataStream &out, const QSet<T> &set)
|
|---|
| 921 | \relates QSet
|
|---|
| 922 |
|
|---|
| 923 | Writes the \a set to stream \a out.
|
|---|
| 924 |
|
|---|
| 925 | This function requires the value type to implement \c operator<<().
|
|---|
| 926 |
|
|---|
| 927 | \sa \link datastreamformat.html Format of the QDataStream operators \endlink
|
|---|
| 928 | */
|
|---|
| 929 |
|
|---|
| 930 | /*!
|
|---|
| 931 | \fn QDataStream &operator>>(QDataStream &in, QSet<T> &set)
|
|---|
| 932 | \relates QSet
|
|---|
| 933 |
|
|---|
| 934 | Reads a set from stream \a in into \a set.
|
|---|
| 935 |
|
|---|
| 936 | This function requires the value type to implement \c operator>>().
|
|---|
| 937 |
|
|---|
| 938 | \sa \link datastreamformat.html Format of the QDataStream operators \endlink
|
|---|
| 939 | */
|
|---|