summaryrefslogtreecommitdiffstats
path: root/src/corelib/tools/qhash.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/corelib/tools/qhash.cpp')
-rw-r--r--src/corelib/tools/qhash.cpp56
1 files changed, 28 insertions, 28 deletions
diff --git a/src/corelib/tools/qhash.cpp b/src/corelib/tools/qhash.cpp
index 20202a4896..a2851d15bd 100644
--- a/src/corelib/tools/qhash.cpp
+++ b/src/corelib/tools/qhash.cpp
@@ -694,21 +694,21 @@ void QHashData::checkSanity()
\endlist
Here's an example QHash with QString keys and \c int values:
- \snippet doc/src/snippets/code/src_corelib_tools_qhash.cpp 0
+ \snippet code/src_corelib_tools_qhash.cpp 0
To insert a (key, value) pair into the hash, you can use operator[]():
- \snippet doc/src/snippets/code/src_corelib_tools_qhash.cpp 1
+ \snippet code/src_corelib_tools_qhash.cpp 1
This inserts the following three (key, value) pairs into the
QHash: ("one", 1), ("three", 3), and ("seven", 7). Another way to
insert items into the hash is to use insert():
- \snippet doc/src/snippets/code/src_corelib_tools_qhash.cpp 2
+ \snippet code/src_corelib_tools_qhash.cpp 2
To look up a value, use operator[]() or value():
- \snippet doc/src/snippets/code/src_corelib_tools_qhash.cpp 3
+ \snippet code/src_corelib_tools_qhash.cpp 3
If there is no item with the specified key in the hash, these
functions return a \l{default-constructed value}.
@@ -716,12 +716,12 @@ void QHashData::checkSanity()
If you want to check whether the hash contains a particular key,
use contains():
- \snippet doc/src/snippets/code/src_corelib_tools_qhash.cpp 4
+ \snippet code/src_corelib_tools_qhash.cpp 4
There is also a value() overload that uses its second argument as
a default value if there is no item with the specified key:
- \snippet doc/src/snippets/code/src_corelib_tools_qhash.cpp 5
+ \snippet code/src_corelib_tools_qhash.cpp 5
In general, we recommend that you use contains() and value()
rather than operator[]() for looking up a key in a hash. The
@@ -730,7 +730,7 @@ void QHashData::checkSanity()
const). For example, the following code snippet will create 1000
items in memory:
- \snippet doc/src/snippets/code/src_corelib_tools_qhash.cpp 6
+ \snippet code/src_corelib_tools_qhash.cpp 6
To avoid this problem, replace \c hash[i] with \c hash.value(i)
in the code above.
@@ -751,11 +751,11 @@ void QHashData::checkSanity()
QHash::iterator). Here's how to iterate over a QHash<QString,
int> using a Java-style iterator:
- \snippet doc/src/snippets/code/src_corelib_tools_qhash.cpp 7
+ \snippet code/src_corelib_tools_qhash.cpp 7
Here's the same code, but using an STL-style iterator:
- \snippet doc/src/snippets/code/src_corelib_tools_qhash.cpp 8
+ \snippet code/src_corelib_tools_qhash.cpp 8
QHash is unordered, so an iterator's sequence cannot be assumed
to be predictable. If ordering by key is required, use a QMap.
@@ -764,7 +764,7 @@ void QHashData::checkSanity()
insert() with a key that already exists in the QHash, the
previous value is erased. For example:
- \snippet doc/src/snippets/code/src_corelib_tools_qhash.cpp 9
+ \snippet code/src_corelib_tools_qhash.cpp 9
However, you can store multiple values per key by using
insertMulti() instead of insert() (or using the convenience
@@ -772,19 +772,19 @@ void QHashData::checkSanity()
the values for a single key, you can use values(const Key &key),
which returns a QList<T>:
- \snippet doc/src/snippets/code/src_corelib_tools_qhash.cpp 10
+ \snippet code/src_corelib_tools_qhash.cpp 10
The items that share the same key are available from most
recently to least recently inserted. A more efficient approach is
to call find() to get the iterator for the first item with a key
and iterate from there:
- \snippet doc/src/snippets/code/src_corelib_tools_qhash.cpp 11
+ \snippet code/src_corelib_tools_qhash.cpp 11
If you only need to extract the values from a hash (not the keys),
you can also use \l{foreach}:
- \snippet doc/src/snippets/code/src_corelib_tools_qhash.cpp 12
+ \snippet code/src_corelib_tools_qhash.cpp 12
Items can be removed from the hash in several ways. One way is to
call remove(); this will remove any item with the given key.
@@ -975,7 +975,7 @@ void QHashData::checkSanity()
This function is useful for code that needs to build a huge hash
and wants to avoid repeated reallocation. For example:
- \snippet doc/src/snippets/code/src_corelib_tools_qhash.cpp 14
+ \snippet code/src_corelib_tools_qhash.cpp 14
Ideally, \a size should be slightly more than the maximum number
of items expected in the hash. \a size doesn't have to be prime,
@@ -1284,7 +1284,7 @@ void QHashData::checkSanity()
be called while iterating, and won't affect the order of items in
the hash. For example:
- \snippet doc/src/snippets/code/src_corelib_tools_qhash.cpp 15
+ \snippet code/src_corelib_tools_qhash.cpp 15
\sa remove(), take(), find()
*/
@@ -1303,7 +1303,7 @@ void QHashData::checkSanity()
the iterator. For example, here's some code that iterates over all
the items with the same key:
- \snippet doc/src/snippets/code/src_corelib_tools_qhash.cpp 16
+ \snippet code/src_corelib_tools_qhash.cpp 16
\sa value(), values(), QMultiHash::find()
*/
@@ -1460,7 +1460,7 @@ void QHashData::checkSanity()
start iterating. Here's a typical loop that prints all the (key,
value) pairs stored in a hash:
- \snippet doc/src/snippets/code/src_corelib_tools_qhash.cpp 17
+ \snippet code/src_corelib_tools_qhash.cpp 17
Unlike QMap, which orders its items by key, QHash stores its
items in an arbitrary order. The only guarantee is that items that
@@ -1473,22 +1473,22 @@ void QHashData::checkSanity()
Here's an example that increments every value stored in the QHash
by 2:
- \snippet doc/src/snippets/code/src_corelib_tools_qhash.cpp 18
+ \snippet code/src_corelib_tools_qhash.cpp 18
Here's an example that removes all the items whose key is a
string that starts with an underscore character:
- \snippet doc/src/snippets/code/src_corelib_tools_qhash.cpp 19
+ \snippet code/src_corelib_tools_qhash.cpp 19
The call to QHash::erase() removes the item pointed to by the
iterator from the hash, and returns an iterator to the next item.
Here's another way of removing an item while iterating:
- \snippet doc/src/snippets/code/src_corelib_tools_qhash.cpp 20
+ \snippet code/src_corelib_tools_qhash.cpp 20
It might be tempting to write code like this:
- \snippet doc/src/snippets/code/src_corelib_tools_qhash.cpp 21
+ \snippet code/src_corelib_tools_qhash.cpp 21
However, this will potentially crash in \c{++i}, because \c i is
a dangling iterator after the call to erase().
@@ -1514,7 +1514,7 @@ void QHashData::checkSanity()
called on an uninitialized iterator. Use operator=() to assign a
value to it before using it.
- \sa QHash::begin() QHash::end()
+ \sa QHash::begin(), QHash::end()
*/
/*! \fn QHash::iterator::iterator(void *node)
@@ -1540,7 +1540,7 @@ void QHashData::checkSanity()
You can change the value of an item by using value() on
the left side of an assignment, for example:
- \snippet doc/src/snippets/code/src_corelib_tools_qhash.cpp 22
+ \snippet code/src_corelib_tools_qhash.cpp 22
\sa key(), operator*()
*/
@@ -1684,7 +1684,7 @@ void QHashData::checkSanity()
QHash::find() before you can start iterating. Here's a typical
loop that prints all the (key, value) pairs stored in a hash:
- \snippet doc/src/snippets/code/src_corelib_tools_qhash.cpp 23
+ \snippet code/src_corelib_tools_qhash.cpp 23
Unlike QMap, which orders its items by key, QHash stores its
items in an arbitrary order. The only guarantee is that items that
@@ -1710,7 +1710,7 @@ void QHashData::checkSanity()
called on an uninitialized iterator. Use operator=() to assign a
value to it before using it.
- \sa QHash::constBegin() QHash::constEnd()
+ \sa QHash::constBegin(), QHash::constEnd()
*/
/*! \fn QHash::const_iterator::const_iterator(void *node)
@@ -1897,7 +1897,7 @@ void QHashData::checkSanity()
operator+=().
Example:
- \snippet doc/src/snippets/code/src_corelib_tools_qhash.cpp 24
+ \snippet code/src_corelib_tools_qhash.cpp 24
Unlike QHash, QMultiHash provides no operator[]. Use value() or
replace() if you want to access the most recently inserted item
@@ -1906,7 +1906,7 @@ void QHashData::checkSanity()
If you want to retrieve all the values for a single key, you can
use values(const Key &key), which returns a QList<T>:
- \snippet doc/src/snippets/code/src_corelib_tools_qhash.cpp 25
+ \snippet code/src_corelib_tools_qhash.cpp 25
The items that share the same key are available from most
recently to least recently inserted.
@@ -1915,7 +1915,7 @@ void QHashData::checkSanity()
the STL-style iterator for the first item with a key and iterate from
there:
- \snippet doc/src/snippets/code/src_corelib_tools_qhash.cpp 26
+ \snippet code/src_corelib_tools_qhash.cpp 26
QMultiHash's key and value data types must be \l{assignable data
types}. You cannot, for example, store a QWidget as a value;