16 QHash<QString,
int> hash;
29 hash.insert(
"twelve", 12);
35 int num1 = hash[
"thirteen"];
36 int num2 = hash.value(
"thirteen");
43 if (hash.contains(
"TIMEOUT"))
44 timeout = hash.value(
"TIMEOUT");
50 int timeout = hash.value(
"TIMEOUT", 30);
56 QHashIterator<QString,
int> i(hash);
59 cout << qPrintable(i.key()) <<
": " << i.value() << endl;
66 for (
const auto &[key, value] : std::as_const(hash).asKeyValueRange())
67 cout << qPrintable(key) <<
": " << value << endl;
73 for (
auto it = hash.cbegin(); it != hash.cend(); ++it)
74 cout << qPrintable(it.key()) <<
": " << it.value() << endl;
80 for (
auto it = hash.begin(); it != hash.end(); ++it)
87 hash.insert(
"plenty", 100);
88 hash.insert(
"plenty", 2000);
95 QHash<QString,
int> hash;
97 for (
int value : std::as_const(hash))
98 cout << value << endl;
160 QHash<QString,
int> hash;
162 for (
int i = 0; i < 20000; ++i)
163 hash.insert(keys[i], values[i]);
171 QHash<QObject *,
int> objectHash;
173 QHash<QObject *,
int>::iterator i = objectHash.find(obj);
174 while (i != objectHash.end() && i.key() == obj) {
175 if (i.value() == 0) {
176 i = objectHash.erase(i);
188 QMultiHash<QObject *,
int> objectHash;
190 QMultiHash<QObject *,
int>::iterator i = objectHash.find(obj);
191 while (i != objectHash.end() && i.key() == obj) {
192 if (i.value() == 0) {
193 i = objectHash.erase(i);
203 QHash<QString,
int> hash;
205 QHash<QString,
int>::const_iterator i = hash.find(
"HDR");
206 while (i != hash.end() && i.key() ==
"HDR") {
207 cout << i.value() << endl;
215 QHash<QString,
int> hash;
216 hash.insert(
"January", 1);
217 hash.insert(
"February", 2);
219 hash.insert(
"December", 12);
221 for (
auto i = hash.cbegin(), end = hash.cend(); i != end; ++i)
222 cout << qPrintable(i.key()) <<
": " << i.value() << endl;
227 QHash<QString,
int> hash;
230 for (
auto i = hash.begin(), end = hash.end(); i != end; ++i)
236 QHash<QString,
int> hash;
239 erase_if(hash, [](
const QHash<QString,
int>::iterator it) {
return it.value() > 10; });
244 QHash<QString, QString> hash;
245 auto i = hash.begin();
248 if (i.key() ==
"Hello")
249 i.value() =
"Bonjour";
255 QHash<QString,
int> hash;
256 hash.insert(
"January", 1);
257 hash.insert(
"February", 2);
259 hash.insert(
"December", 12);
261 for (
auto i = hash.cbegin(), end = hash.cend(); i != end; ++i)
262 cout << qPrintable(i.key()) <<
": " << i.value() << endl;
268 QMultiHash<QString,
int> hash1, hash2, hash3;
270 hash1.insert(
"plenty", 100);
271 hash1.insert(
"plenty", 2000);
274 hash2.insert(
"plenty", 5000);
277 hash3 = hash1 + hash2;
283 QMultiHash<QString,
int> hash;
286 QList<
int> values = hash.values(
"plenty");
287 for (
auto i : std::as_const(values))
293 QMultiHash<QString,
int> hash;
296 auto i = hash.constFind(
"plenty");
297 while (i != hash.cend() && i.key() ==
"plenty") {
298 cout << i.value() << endl;
305 QMultiHash<
int, QString> hash;
308 for (
auto it = hash.cbegin(), end = hash.cend(); it != end; ++it) {
309 cout <<
"The key: " << it.key() << endl;
310 cout <<
"The value: " << qPrintable(it.value()) << endl;
311 cout <<
"Also the value: " << qPrintable(*it) << endl;
317 QHash<
int,
int> hash;
318 QHash<QObject *,
int> hash2;
319 auto isPrimeNumber = [](
int num) {
return true; };
323 QList<
int> keys = hash.keys();
324 int numPrimes = std::count_if(keys.cbegin(), keys.cend(), isPrimeNumber);
325 qDeleteAll(hash2.keys());
328 int primeNums = std::count_if(hash.keyBegin(), hash.keyEnd(), isPrimeNumber);
329 qDeleteAll(hash2.keyBegin(), hash2.keyEnd());
380 size_t qHash(
K key, size_t seed);
381 size_t qHash(
const K &key, size_t seed);
384 size_t qHash(
const K &key);
390 QHash<QString,
int> hash;
391 hash.insert(
"January", 1);
392 hash.insert(
"February", 2);
394 hash.insert(
"December", 12);
396 for (
auto [key, value] : hash.asKeyValueRange()) {
397 cout << qPrintable(key) <<
": " << value << endl;
405 QMultiHash<QString,
int> hash;
406 hash.insert(
"January", 1);
407 hash.insert(
"February", 2);
409 hash.insert(
"December", 12);
411 for (
auto [key, value] : hash.asKeyValueRange()) {
412 cout << qPrintable(key) <<
": " << value << endl;