Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qtconcurrentmap.cpp
Go to the documentation of this file.
1
// Copyright (C) 2016 The Qt Company Ltd.
2
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
// Qt-Security score:significant reason:default
4
5
/*!
6
\namespace QtConcurrent
7
\inmodule QtConcurrent
8
\since 4.4
9
\brief The QtConcurrent namespace provides high-level APIs that make it
10
possible to write multi-threaded programs without using low-level
11
threading primitives.
12
13
See the \l {Qt Concurrent} module documentation for an overview of available
14
functions, or see below for detailed information on each function.
15
16
\section1 Optimize includes
17
18
If you include the \c <QtConcurrent> header, the entire Qt Concurrent
19
module with the entire Qt Core module will be included, which may increase
20
compilation times and binary sizes. To use individual functions from the
21
QtConcurrent namespace, you can include more specific headers.
22
23
The table below lists the functions in the QtConcurrent namespace and
24
their corresponding headers:
25
26
\table
27
\header
28
\li Function
29
\li Header
30
\row
31
\li \l {QtConcurrent::run}{QtConcurrent::run()}
32
\li \c <QtConcurrentRun>
33
\row
34
\li \l {QtConcurrent::task}{QtConcurrent::task()}
35
\li \c <QtConcurrentTask>
36
\row
37
\li \l {QtConcurrent::filter}{QtConcurrent::filter()},
38
\l {QtConcurrent::filtered}{QtConcurrent::filtered()},
39
\l {QtConcurrent::filteredReduced}{QtConcurrent::filteredReduced()}
40
\li \c <QtConcurrentFilter>
41
\row
42
\li \l {QtConcurrent::map}{QtConcurrent::map()},
43
\l {QtConcurrent::mapped}{QtConcurrent::mapped()},
44
\l {QtConcurrent::mappedReduced}{QtConcurrent::mappedReduced()}
45
\li \c <QtConcurrentMap>
46
\endtable
47
48
\inheaderfile QtConcurrent
49
\ingroup thread
50
*/
51
52
/*!
53
\enum QtConcurrent::ReduceQueueLimits
54
\internal
55
*/
56
57
/*!
58
\class QtConcurrent::ReduceKernel
59
\inmodule QtConcurrent
60
\internal
61
*/
62
63
/*!
64
\class QtConcurrent::SequenceHolder2
65
\inmodule QtConcurrent
66
\internal
67
*/
68
69
/*!
70
\class QtConcurrent::MapKernel
71
\inmodule QtConcurrent
72
\internal
73
*/
74
75
/*!
76
\class QtConcurrent::MappedReducedKernel
77
\inmodule QtConcurrent
78
\internal
79
*/
80
81
/*!
82
\class QtConcurrent::MappedEachKernel
83
\inmodule QtConcurrent
84
\internal
85
*/
86
87
/*!
88
\class QtConcurrent::SequenceHolder1
89
\inmodule QtConcurrent
90
\internal
91
*/
92
93
/*!
94
\fn [qtconcurrentmapkernel-1] ThreadEngineStarter<void> QtConcurrent::startMap(Iterator begin, Iterator end, Functor &&functor)
95
\internal
96
*/
97
98
/*!
99
\fn [qtconcurrentmapkernel-2] ThreadEngineStarter<T> QtConcurrent::startMapped(Iterator begin, Iterator end, Functor &&functor)
100
\internal
101
*/
102
103
/*!
104
\fn [qtconcurrentmapkernel-3] ThreadEngineStarter<T> QtConcurrent::startMapped(Sequence &&sequence, Functor &&functor)
105
\internal
106
*/
107
108
/*!
109
\fn [qtconcurrentmapkernel-4] ThreadEngineStarter<ResultType> QtConcurrent::startMappedReduced(Sequence &&sequence, MapFunctor &&mapFunctor, ReduceFunctor &&reduceFunctor, ReduceOptions options)
110
\internal
111
*/
112
113
/*!
114
\fn [qtconcurrentmapkernel-5] ThreadEngineStarter<ResultType> QtConcurrent::startMappedReduced(Iterator begin, Iterator end, MapFunctor &&mapFunctor, ReduceFunctor &&reduceFunctor, ReduceOptions options)
115
\internal
116
*/
117
118
/*!
119
\fn [qtconcurrentmapkernel-6] ThreadEngineStarter<ResultType> QtConcurrent::startMappedReduced(Sequence &&sequence, MapFunctor &&mapFunctor, ReduceFunctor &&reduceFunctor, ResultType &&initialValue, ReduceOptions options)
120
\internal
121
*/
122
123
/*!
124
\fn [qtconcurrentmapkernel-7] ThreadEngineStarter<ResultType> QtConcurrent::startMappedReduced(Iterator begin, Iterator end, MapFunctor &&mapFunctor, ReduceFunctor &&reduceFunctor, ResultType &&initialValue, ReduceOptions options)
125
\internal
126
*/
127
128
/*!
129
\enum QtConcurrent::ReduceOption
130
This enum specifies the order of which results from the map or filter
131
function are passed to the reduce function.
132
133
\value UnorderedReduce Reduction is done in an arbitrary order.
134
\value OrderedReduce Reduction is done in the order of the
135
original sequence.
136
\value SequentialReduce Reduction is done sequentially: only one
137
thread will enter the reduce function at a time. (Parallel reduction
138
might be supported in a future version of Qt Concurrent.)
139
*/
140
141
/*!
142
\page qtconcurrentmap.html
143
\title Concurrent Map and Map-Reduce
144
\brief Transforming values from a sequence and combining them, all in parallel.
145
\ingroup thread
146
147
The QtConcurrent::map(), QtConcurrent::mapped() and
148
QtConcurrent::mappedReduced() functions run computations in parallel on
149
the items in a sequence such as a QList. QtConcurrent::map()
150
modifies a sequence in-place, QtConcurrent::mapped() returns a new
151
sequence containing the modified content, and QtConcurrent::mappedReduced()
152
returns a single result.
153
154
These functions are part of the \l {Qt Concurrent} framework.
155
156
Each of the above functions has a blocking variant that returns
157
the final result instead of a QFuture. You use them in the same
158
way as the asynchronous variants.
159
160
\snippet code/src_concurrent_qtconcurrentmap.cpp 7
161
162
Note that the result types above are not QFuture objects, but real result
163
types (in this case, QList<QImage> and QImage).
164
165
\section1 Optimize includes
166
167
If you include the \c <QtConcurrent> header, the entire Qt Concurrent
168
module with the entire Qt Core module will be included, which may increase
169
compilation times and binary sizes. To use the
170
\l {QtConcurrent::map}{QtConcurrent::map()},
171
\l {QtConcurrent::mapped}{QtConcurrent::mapped()}, and
172
\l {QtConcurrent::mappedReduced}{QtConcurrent::mappedReduced()} functions,
173
you can include a more specific header:
174
175
\code
176
#include <QtConcurrentMap>
177
\endcode
178
179
\section1 Concurrent Map
180
181
QtConcurrent::mapped() takes an input sequence and a map function. This map
182
function is then called for each item in the sequence, and a new sequence
183
containing the return values from the map function is returned.
184
185
The map function must be of the form:
186
187
\snippet code/src_concurrent_qtconcurrentmap.cpp 0
188
189
T and U can be any type (and they can even be the same type), but T must
190
match the type stored in the sequence. The function returns the modified
191
or \e mapped content.
192
193
This example shows how to apply a scale function to all the items
194
in a sequence:
195
196
\snippet code/src_concurrent_qtconcurrentmap.cpp 1
197
198
The results of the map are made available through QFuture. See the
199
QFuture and QFutureWatcher documentation for more information on how to
200
use QFuture in your applications.
201
202
If you want to modify a sequence in-place, use QtConcurrent::map(). The
203
map function must then be of the form:
204
205
\snippet code/src_concurrent_qtconcurrentmap.cpp 2
206
207
Note that the return value and return type of the map function are not
208
used.
209
210
Using QtConcurrent::map() is similar to using QtConcurrent::mapped():
211
212
\snippet code/src_concurrent_qtconcurrentmap.cpp 3
213
214
Since the sequence is modified in place, QtConcurrent::map() does not
215
return any results via QFuture. However, you can still use QFuture and
216
QFutureWatcher to monitor the status of the map.
217
218
\section2 Concurrent Mapped and Continuations
219
220
The result of QtConcurrent::mapped() call is a QFuture that contains
221
multiple results. When attaching a \c {.then()} continuation to such
222
QFuture, make sure to use a continuation that takes QFuture as a parameter,
223
otherwise only the first result will be processed:
224
225
\snippet code/src_concurrent_qtconcurrentmap.cpp 18
226
227
In this example \c {badFuture} will only print a single result, while
228
\c {goodFuture} will print all results.
229
230
\section1 Concurrent Map-Reduce
231
232
QtConcurrent::mappedReduced() is similar to QtConcurrent::mapped(), but
233
instead of returning a sequence with the new results, the results are
234
combined into a single value using a reduce function.
235
236
The reduce function must be of the form:
237
238
\snippet code/src_concurrent_qtconcurrentmap.cpp 4
239
240
T is the type of the final result, U is the return type of the map
241
function. Note that the return value and return type of the reduce
242
function are not used.
243
244
Call QtConcurrent::mappedReduced() like this:
245
246
\snippet code/src_concurrent_qtconcurrentmap.cpp 5
247
248
The reduce function will be called once for each result returned by the map
249
function, and should merge the \e{intermediate} into the \e{result}
250
variable. QtConcurrent::mappedReduced() guarantees that only one thread
251
will call reduce at a time, so using a mutex to lock the result variable
252
is not necessary. The QtConcurrent::ReduceOptions enum provides a way to
253
control the order in which the reduction is done. If
254
QtConcurrent::UnorderedReduce is used (the default), the order is
255
undefined, while QtConcurrent::OrderedReduce ensures that the reduction
256
is done in the order of the original sequence.
257
258
\section1 Additional API Features
259
260
\section2 Using Iterators instead of Sequence
261
262
Each of the above functions has a variant that takes an iterator range
263
instead of a sequence. You use them in the same way as the sequence
264
variants:
265
266
\snippet code/src_concurrent_qtconcurrentmap.cpp 6
267
268
\section2 Blocking Variants
269
270
Each of the above functions has a blocking variant that returns
271
the final result instead of a QFuture. You use them in the same
272
way as the asynchronous variants.
273
274
\snippet code/src_concurrent_qtconcurrentmap.cpp 7
275
276
Note that the result types above are not QFuture objects, but real result
277
types (in this case, QList<QImage> and QImage).
278
279
\section2 Using Member Functions
280
281
QtConcurrent::map(), QtConcurrent::mapped(), and
282
QtConcurrent::mappedReduced() accept pointers to member functions.
283
The member function class type must match the type stored in the sequence:
284
285
\snippet code/src_concurrent_qtconcurrentmap.cpp 8
286
287
Note the use of qOverload. It is needed to resolve the ambiguity for the
288
methods, that have multiple overloads.
289
290
Also note that when using QtConcurrent::mappedReduced(), you can mix the use of
291
normal and member functions freely:
292
293
\snippet code/src_concurrent_qtconcurrentmap.cpp 9
294
295
\section2 Using Function Objects
296
297
QtConcurrent::map(), QtConcurrent::mapped(), and
298
QtConcurrent::mappedReduced() accept function objects
299
for the map function. These function objects can be used to
300
add state to a function call:
301
302
\snippet code/src_concurrent_qtconcurrentmap.cpp 14
303
304
Function objects are also supported for the reduce function:
305
306
\snippet code/src_concurrent_qtconcurrentmap.cpp 11
307
308
\section2 Using Lambda Expressions
309
310
QtConcurrent::map(), QtConcurrent::mapped(), and
311
QtConcurrent::mappedReduced() accept lambda expressions for the map and
312
reduce function:
313
314
\snippet code/src_concurrent_qtconcurrentmap.cpp 15
315
316
When using QtConcurrent::mappedReduced() or
317
QtConcurrent::blockingMappedReduced(), you can mix the use of normal
318
functions, member functions and lambda expressions freely.
319
320
\snippet code/src_concurrent_qtconcurrentmap.cpp 16
321
322
You can also pass a lambda as a reduce object:
323
324
\snippet code/src_concurrent_qtconcurrentmap.cpp 17
325
326
\section2 Wrapping Functions that Take Multiple Arguments
327
328
If you want to use a map function that takes more than one argument you can
329
use a lambda function or \c std::bind() to transform it onto a function that
330
takes one argument.
331
332
As an example, we'll use QImage::scaledToWidth():
333
334
\snippet code/src_concurrent_qtconcurrentmap.cpp 10
335
336
scaledToWidth takes three arguments (including the "this" pointer) and
337
can't be used with QtConcurrent::mapped() directly, because
338
QtConcurrent::mapped() expects a function that takes one argument. To use
339
QImage::scaledToWidth() with QtConcurrent::mapped() we have to provide a
340
value for the \e{width} and the \e{transformation mode}:
341
342
\snippet code/src_concurrent_qtconcurrentmap.cpp 13
343
*/
344
345
/*!
346
\fn template <typename Sequence, typename MapFunctor> QFuture<void> QtConcurrent::map(QThreadPool *pool, Sequence &&sequence, MapFunctor &&function)
347
348
Calls \a function once for each item in \a sequence.
349
All calls to \a function are invoked from the threads taken from the QThreadPool \a pool.
350
The \a function takes a reference to the item, so that any modifications done to the item
351
will appear in \a sequence.
352
353
\sa {Concurrent Map and Map-Reduce}
354
*/
355
356
/*!
357
\fn template <typename Sequence, typename MapFunctor> QFuture<void> QtConcurrent::map(Sequence &&sequence, MapFunctor &&function)
358
359
Calls \a function once for each item in \a sequence. The \a function takes
360
a reference to the item, so that any modifications done to the item
361
will appear in \a sequence.
362
363
\sa {Concurrent Map and Map-Reduce}
364
*/
365
366
/*!
367
\fn template <typename Iterator, typename MapFunctor> QFuture<void> QtConcurrent::map(QThreadPool *pool, Iterator begin, Iterator end, MapFunctor &&function)
368
369
Calls \a function once for each item from \a begin to \a end.
370
All calls to \a function are invoked from the threads taken from the QThreadPool \a pool.
371
The \a function takes a reference to the item, so that any modifications
372
done to the item will appear in the sequence which the iterators belong to.
373
374
\sa {Concurrent Map and Map-Reduce}
375
*/
376
377
/*!
378
\fn template <typename Iterator, typename MapFunctor> QFuture<void> QtConcurrent::map(Iterator begin, Iterator end, MapFunctor &&function)
379
380
Calls \a function once for each item from \a begin to \a end. The
381
\a function takes a reference to the item, so that any modifications
382
done to the item will appear in the sequence which the iterators belong to.
383
384
\sa {Concurrent Map and Map-Reduce}
385
*/
386
387
/*!
388
\fn template <typename Sequence, typename MapFunctor> QFuture<QtPrivate::MapResultType<Sequence, MapFunctor>> QtConcurrent::mapped(QThreadPool *pool, Sequence &&sequence, MapFunctor &&function)
389
390
Calls \a function once for each item in \a sequence and returns a future
391
with each mapped item as a result. All calls to \a function are invoked from the
392
threads taken from the QThreadPool \a pool. You can use QFuture::const_iterator or
393
QFutureIterator to iterate through the results.
394
395
\sa {Concurrent Map and Map-Reduce}
396
*/
397
398
/*!
399
\fn template <typename Sequence, typename MapFunctor> QFuture<QtPrivate::MapResultType<Sequence, MapFunctor>> QtConcurrent::mapped(Sequence &&sequence, MapFunctor &&function)
400
401
Calls \a function once for each item in \a sequence and returns a future
402
with each mapped item as a result. You can use QFuture::const_iterator or
403
QFutureIterator to iterate through the results.
404
405
\sa {Concurrent Map and Map-Reduce}
406
*/
407
408
/*!
409
\fn template <typename Iterator, typename MapFunctor> QFuture<QtPrivate::MapResultType<Iterator, MapFunctor>> QtConcurrent::mapped(QThreadPool *pool, Iterator begin, Iterator end, MapFunctor &&function)
410
411
Calls \a function once for each item from \a begin to \a end and returns a
412
future with each mapped item as a result. All calls to \a function are invoked from the
413
threads taken from the QThreadPool \a pool. You can use
414
QFuture::const_iterator or QFutureIterator to iterate through the results.
415
416
\sa {Concurrent Map and Map-Reduce}
417
*/
418
419
/*!
420
\fn template <typename Iterator, typename MapFunctor> QFuture<QtPrivate::MapResultType<Iterator, MapFunctor>> QtConcurrent::mapped(Iterator begin, Iterator end, MapFunctor &&function)
421
422
Calls \a function once for each item from \a begin to \a end and returns a
423
future with each mapped item as a result. You can use
424
QFuture::const_iterator or QFutureIterator to iterate through the results.
425
426
\sa {Concurrent Map and Map-Reduce}
427
*/
428
429
/*!
430
\fn template <typename ResultType, typename Sequence, typename MapFunctor, typename ReduceFunctor> QFuture<ResultType> QtConcurrent::mappedReduced(QThreadPool *pool, Sequence &&sequence, MapFunctor &&mapFunction, ReduceFunctor &&reduceFunction, QtConcurrent::ReduceOptions reduceOptions)
431
432
Calls \a mapFunction once for each item in \a sequence.
433
All calls to \a mapFunction are invoked from the threads taken from the QThreadPool \a pool.
434
The return value of each \a mapFunction is passed to \a reduceFunction.
435
436
Note that while \a mapFunction is called concurrently, only one thread at a
437
time will call \a reduceFunction. The order in which \a reduceFunction is
438
called is determined by \a reduceOptions.
439
440
\sa {Concurrent Map and Map-Reduce}
441
*/
442
443
/*!
444
\fn template <typename ResultType, typename Sequence, typename MapFunctor, typename ReduceFunctor> QFuture<ResultType> QtConcurrent::mappedReduced(Sequence &&sequence, MapFunctor &&mapFunction, ReduceFunctor &&reduceFunction, QtConcurrent::ReduceOptions reduceOptions)
445
446
Calls \a mapFunction once for each item in \a sequence. The return value of
447
each \a mapFunction is passed to \a reduceFunction.
448
449
Note that while \a mapFunction is called concurrently, only one thread at a
450
time will call \a reduceFunction. The order in which \a reduceFunction is
451
called is determined by \a reduceOptions.
452
453
\sa {Concurrent Map and Map-Reduce}
454
*/
455
456
/*!
457
\fn template <typename ResultType, typename Sequence, typename MapFunctor, typename ReduceFunctor, typename InitialValueType> QFuture<ResultType> QtConcurrent::mappedReduced(QThreadPool *pool, Sequence &&sequence, MapFunctor &&mapFunction, ReduceFunctor &&reduceFunction, InitialValueType &&initialValue, QtConcurrent::ReduceOptions reduceOptions)
458
459
Calls \a mapFunction once for each item in \a sequence.
460
All calls to \a mapFunction are invoked from the threads taken from the QThreadPool \a pool.
461
The return value of each \a mapFunction is passed to \a reduceFunction.
462
The result value is initialized to \a initialValue when the function is
463
called, and the first call to \a reduceFunction will operate on
464
this value.
465
466
Note that while \a mapFunction is called concurrently, only one thread at a
467
time will call \a reduceFunction. The order in which \a reduceFunction is
468
called is determined by \a reduceOptions.
469
470
\sa {Concurrent Map and Map-Reduce}
471
*/
472
473
/*!
474
\fn template <typename ResultType, typename Sequence, typename MapFunctor, typename ReduceFunctor, typename InitialValueType> QFuture<ResultType> QtConcurrent::mappedReduced(Sequence &&sequence, MapFunctor &&mapFunction, ReduceFunctor &&reduceFunction, InitialValueType &&initialValue, QtConcurrent::ReduceOptions reduceOptions)
475
476
Calls \a mapFunction once for each item in \a sequence. The return value of
477
each \a mapFunction is passed to \a reduceFunction.
478
The result value is initialized to \a initialValue when the function is
479
called, and the first call to \a reduceFunction will operate on
480
this value.
481
482
Note that while \a mapFunction is called concurrently, only one thread at a
483
time will call \a reduceFunction. The order in which \a reduceFunction is
484
called is determined by \a reduceOptions.
485
486
\sa {Concurrent Map and Map-Reduce}
487
*/
488
489
/*!
490
\fn template <typename ResultType, typename Iterator, typename MapFunctor, typename ReduceFunctor> QFuture<ResultType> QtConcurrent::mappedReduced(QThreadPool *pool, Iterator begin, Iterator end, MapFunctor &&mapFunction, ReduceFunctor &&reduceFunction, QtConcurrent::ReduceOptions reduceOptions)
491
492
Calls \a mapFunction once for each item from \a begin to \a end.
493
All calls to \a mapFunction are invoked from the threads taken from the QThreadPool \a pool.
494
The return value of each \a mapFunction is passed to \a reduceFunction.
495
496
Note that while \a mapFunction is called concurrently, only one thread at a
497
time will call \a reduceFunction. By default, the order in which
498
\a reduceFunction is called is undefined.
499
500
\note QtConcurrent::OrderedReduce results in the ordered reduction.
501
502
\sa {Concurrent Map and Map-Reduce}
503
*/
504
505
/*!
506
\fn template <typename ResultType, typename Iterator, typename MapFunctor, typename ReduceFunctor> QFuture<ResultType> QtConcurrent::mappedReduced(Iterator begin, Iterator end, MapFunctor &&mapFunction, ReduceFunctor &&reduceFunction, QtConcurrent::ReduceOptions reduceOptions)
507
508
Calls \a mapFunction once for each item from \a begin to \a end. The return
509
value of each \a mapFunction is passed to \a reduceFunction.
510
511
Note that while \a mapFunction is called concurrently, only one thread at a
512
time will call \a reduceFunction. By default, the order in which
513
\a reduceFunction is called is undefined.
514
515
\note QtConcurrent::OrderedReduce results in the ordered reduction.
516
517
\sa {Concurrent Map and Map-Reduce}
518
*/
519
520
/*!
521
\fn template <typename ResultType, typename Iterator, typename MapFunctor, typename ReduceFunctor, typename InitialValueType> QFuture<ResultType> QtConcurrent::mappedReduced(QThreadPool *pool, Iterator begin, Iterator end, MapFunctor &&mapFunction, ReduceFunctor &&reduceFunction, InitialValueType &&initialValue, QtConcurrent::ReduceOptions reduceOptions)
522
523
Calls \a mapFunction once for each item from \a begin to \a end.
524
All calls to \a mapFunction are invoked from the threads taken from the QThreadPool \a pool.
525
The return value of each \a mapFunction is passed to \a reduceFunction.
526
The result value is initialized to \a initialValue when the function is
527
called, and the first call to \a reduceFunction will operate on
528
this value.
529
530
Note that while \a mapFunction is called concurrently, only one thread at a
531
time will call \a reduceFunction. By default, the order in which
532
\a reduceFunction is called is undefined.
533
534
\note QtConcurrent::OrderedReduce results in the ordered reduction.
535
536
\sa {Concurrent Map and Map-Reduce}
537
*/
538
539
/*!
540
\fn template <typename ResultType, typename Iterator, typename MapFunctor, typename ReduceFunctor, typename InitialValueType> QFuture<ResultType> QtConcurrent::mappedReduced(Iterator begin, Iterator end, MapFunctor &&mapFunction, ReduceFunctor &&reduceFunction, InitialValueType &&initialValue, QtConcurrent::ReduceOptions reduceOptions)
541
542
Calls \a mapFunction once for each item from \a begin to \a end. The return
543
value of each \a mapFunction is passed to \a reduceFunction.
544
The result value is initialized to \a initialValue when the function is
545
called, and the first call to \a reduceFunction will operate on
546
this value.
547
548
Note that while \a mapFunction is called concurrently, only one thread at a
549
time will call \a reduceFunction. By default, the order in which
550
\a reduceFunction is called is undefined.
551
552
\note QtConcurrent::OrderedReduce results in the ordered reduction.
553
554
\sa {Concurrent Map and Map-Reduce}
555
*/
556
557
/*!
558
\fn template <typename Sequence, typename MapFunctor> void QtConcurrent::blockingMap(QThreadPool *pool, Sequence &&sequence, MapFunctor function)
559
560
Calls \a function once for each item in \a sequence.
561
All calls to \a function are invoked from the threads taken from the QThreadPool \a pool.
562
The \a function takes a reference to the item, so that any modifications done to the item
563
will appear in \a sequence.
564
565
\note This function will block until all items in the sequence have been processed.
566
567
\sa map(), {Concurrent Map and Map-Reduce}
568
*/
569
570
/*!
571
\fn template <typename Sequence, typename MapFunctor> void QtConcurrent::blockingMap(Sequence &&sequence, MapFunctor &&function)
572
573
Calls \a function once for each item in \a sequence. The \a function takes
574
a reference to the item, so that any modifications done to the item
575
will appear in \a sequence.
576
577
\note This function will block until all items in the sequence have been processed.
578
579
\sa map(), {Concurrent Map and Map-Reduce}
580
*/
581
582
/*!
583
\fn template <typename Iterator, typename MapFunctor> void QtConcurrent::blockingMap(QThreadPool *pool, Iterator begin, Iterator end, MapFunctor &&function)
584
585
Calls \a function once for each item from \a begin to \a end.
586
All calls to \a function are invoked from the threads taken from the QThreadPool \a pool.
587
The \a function takes a reference to the item, so that any modifications
588
done to the item will appear in the sequence which the iterators belong to.
589
590
\note This function will block until the iterator reaches the end of the
591
sequence being processed.
592
593
\sa map(), {Concurrent Map and Map-Reduce}
594
*/
595
596
/*!
597
\fn template <typename Iterator, typename MapFunctor> void QtConcurrent::blockingMap(Iterator begin, Iterator end, MapFunctor &&function)
598
599
Calls \a function once for each item from \a begin to \a end. The
600
\a function takes a reference to the item, so that any modifications
601
done to the item will appear in the sequence which the iterators belong to.
602
603
\note This function will block until the iterator reaches the end of the
604
sequence being processed.
605
606
\sa map(), {Concurrent Map and Map-Reduce}
607
*/
608
609
/*!
610
\fn template <typename OutputSequence, typename InputSequence, typename MapFunctor> OutputSequence QtConcurrent::blockingMapped(QThreadPool *pool, InputSequence &&sequence, MapFunctor &&function)
611
612
Calls \a function once for each item in \a sequence and returns an OutputSequence containing
613
the results. All calls to \a function are invoked from the threads taken from the QThreadPool
614
\a pool. The type of the results will match the type returned by the MapFunctor.
615
616
\note This function will block until all items in the sequence have been processed.
617
618
\sa mapped(), {Concurrent Map and Map-Reduce}
619
*/
620
621
/*!
622
\fn template <typename OutputSequence, typename InputSequence, typename MapFunctor> OutputSequence QtConcurrent::blockingMapped(InputSequence &&sequence, MapFunctor &&function)
623
624
Calls \a function once for each item in \a sequence and returns an OutputSequence containing
625
the results. The type of the results will match the type returned by the MapFunctor.
626
627
\note This function will block until all items in the sequence have been processed.
628
629
\sa mapped(), {Concurrent Map and Map-Reduce}
630
*/
631
632
/*!
633
\fn template <typename Sequence, typename Iterator, typename MapFunctor> Sequence QtConcurrent::blockingMapped(QThreadPool *pool, Iterator begin, Iterator end, MapFunctor &&function)
634
635
Calls \a function once for each item from \a begin to \a end and returns a
636
container with the results. All calls to \a function are invoked from the threads
637
taken from the QThreadPool \a pool. You can specify the type of container as the a template
638
argument, like this:
639
640
\code
641
QList<int> ints = QtConcurrent::blockingMapped<QList<int> >(beginIterator, endIterator, fn);
642
\endcode
643
644
\note This function will block until the iterator reaches the end of the
645
sequence being processed.
646
647
\sa mapped(), {Concurrent Map and Map-Reduce}
648
*/
649
650
/*!
651
\fn template <typename Sequence, typename Iterator, typename MapFunctor> Sequence QtConcurrent::blockingMapped(Iterator begin, Iterator end, MapFunctor &&function)
652
653
Calls \a function once for each item from \a begin to \a end and returns a
654
container with the results. You can specify the type of container as the a template
655
argument, like this:
656
657
\code
658
QList<int> ints = QtConcurrent::blockingMapped<QList<int> >(beginIterator, endIterator, fn);
659
\endcode
660
661
\note This function will block until the iterator reaches the end of the
662
sequence being processed.
663
664
\sa mapped(), {Concurrent Map and Map-Reduce}
665
*/
666
667
/*!
668
\fn template <typename ResultType, typename Sequence, typename MapFunctor, typename ReduceFunctor> ResultType QtConcurrent::blockingMappedReduced(QThreadPool *pool, Sequence &&sequence, MapFunctor &&mapFunction, ReduceFunctor &&reduceFunction, QtConcurrent::ReduceOptions reduceOptions)
669
670
Calls \a mapFunction once for each item in \a sequence.
671
All calls to \a mapFunction are invoked from the threads taken from the QThreadPool \a pool.
672
The return value of each \a mapFunction is passed to \a reduceFunction.
673
674
Note that while \a mapFunction is called concurrently, only one thread at a
675
time will call \a reduceFunction. The order in which \a reduceFunction is
676
called is determined by \a reduceOptions.
677
678
\note This function will block until all items in the sequence have been processed.
679
680
\sa mapped(), {Concurrent Map and Map-Reduce}
681
*/
682
683
/*!
684
\fn template <typename ResultType, typename Sequence, typename MapFunctor, typename ReduceFunctor> ResultType QtConcurrent::blockingMappedReduced(Sequence &&sequence, MapFunctor &&mapFunction, ReduceFunctor &&reduceFunction, QtConcurrent::ReduceOptions reduceOptions)
685
686
Calls \a mapFunction once for each item in \a sequence. The return value of
687
each \a mapFunction is passed to \a reduceFunction.
688
689
Note that while \a mapFunction is called concurrently, only one thread at a
690
time will call \a reduceFunction. The order in which \a reduceFunction is
691
called is determined by \a reduceOptions.
692
693
\note This function will block until all items in the sequence have been processed.
694
695
\sa mapped(), {Concurrent Map and Map-Reduce}
696
*/
697
698
/*!
699
\fn template <typename ResultType, typename Sequence, typename MapFunctor, typename ReduceFunctor, typename InitialValueType> ResultType QtConcurrent::blockingMappedReduced(QThreadPool *pool, Sequence &&sequence, MapFunctor &&mapFunction, ReduceFunctor &&reduceFunction, InitialValueType &&initialValue, QtConcurrent::ReduceOptions reduceOptions)
700
701
Calls \a mapFunction once for each item in \a sequence.
702
All calls to \a mapFunction are invoked from the threads taken from the QThreadPool \a pool.
703
The return value of each \a mapFunction is passed to \a reduceFunction.
704
The result value is initialized to \a initialValue when the function is
705
called, and the first call to \a reduceFunction will operate on
706
this value.
707
708
Note that while \a mapFunction is called concurrently, only one thread at a
709
time will call \a reduceFunction. The order in which \a reduceFunction is
710
called is determined by \a reduceOptions.
711
712
\note This function will block until all items in the sequence have been processed.
713
714
\sa mapped(), {Concurrent Map and Map-Reduce}
715
*/
716
717
/*!
718
\fn template <typename ResultType, typename Sequence, typename MapFunctor, typename ReduceFunctor, typename InitialValueType> ResultType QtConcurrent::blockingMappedReduced(Sequence &&sequence, MapFunctor &&mapFunction, ReduceFunctor &&reduceFunction, InitialValueType &&initialValue, QtConcurrent::ReduceOptions reduceOptions)
719
720
Calls \a mapFunction once for each item in \a sequence. The return value of
721
each \a mapFunction is passed to \a reduceFunction.
722
The result value is initialized to \a initialValue when the function is
723
called, and the first call to \a reduceFunction will operate on
724
this value.
725
726
Note that while \a mapFunction is called concurrently, only one thread at a
727
time will call \a reduceFunction. The order in which \a reduceFunction is
728
called is determined by \a reduceOptions.
729
730
\note This function will block until all items in the sequence have been processed.
731
732
\sa mapped(), {Concurrent Map and Map-Reduce}
733
*/
734
735
/*!
736
\fn template <typename ResultType, typename Iterator, typename MapFunctor, typename ReduceFunctor> ResultType QtConcurrent::blockingMappedReduced(QThreadPool *pool, Iterator begin, Iterator end, MapFunctor &&mapFunction, ReduceFunctor &&reduceFunction, QtConcurrent::ReduceOptions reduceOptions)
737
738
Calls \a mapFunction once for each item from \a begin to \a end.
739
All calls to \a mapFunction are invoked from the threads taken from the QThreadPool \a pool.
740
The return value of each \a mapFunction is passed to \a reduceFunction.
741
742
Note that while \a mapFunction is called concurrently, only one thread at a
743
time will call \a reduceFunction. The order in which \a reduceFunction is
744
called is undefined.
745
746
\note This function will block until the iterator reaches the end of the
747
sequence being processed.
748
749
\sa blockingMappedReduced(), {Concurrent Map and Map-Reduce}
750
*/
751
752
/*!
753
\fn template <typename ResultType, typename Iterator, typename MapFunctor, typename ReduceFunctor> ResultType QtConcurrent::blockingMappedReduced(Iterator begin, Iterator end, MapFunctor &&mapFunction, ReduceFunctor &&reduceFunction, QtConcurrent::ReduceOptions reduceOptions)
754
755
Calls \a mapFunction once for each item from \a begin to \a end. The return
756
value of each \a mapFunction is passed to \a reduceFunction.
757
758
Note that while \a mapFunction is called concurrently, only one thread at a
759
time will call \a reduceFunction. The order in which \a reduceFunction is
760
called is undefined.
761
762
\note This function will block until the iterator reaches the end of the
763
sequence being processed.
764
765
\sa blockingMappedReduced(), {Concurrent Map and Map-Reduce}
766
*/
767
768
/*!
769
\fn template <typename ResultType, typename Iterator, typename MapFunctor, typename ReduceFunctor, typename InitialValueType> ResultType QtConcurrent::blockingMappedReduced(QThreadPool *pool, Iterator begin, Iterator end, MapFunctor &&mapFunction, ReduceFunctor &&reduceFunction, InitialValueType &&initialValue, QtConcurrent::ReduceOptions reduceOptions)
770
771
Calls \a mapFunction once for each item from \a begin to \a end.
772
All calls to \a mapFunction are invoked from the threads taken from the QThreadPool \a pool.
773
The return value of each \a mapFunction is passed to \a reduceFunction.
774
The result value is initialized to \a initialValue when the function is
775
called, and the first call to \a reduceFunction will operate on
776
this value.
777
778
Note that while \a mapFunction is called concurrently, only one thread at a
779
time will call \a reduceFunction. The order in which \a reduceFunction is
780
called is undefined.
781
782
\note This function will block until the iterator reaches the end of the
783
sequence being processed.
784
785
\sa blockingMappedReduced(), {Concurrent Map and Map-Reduce}
786
*/
787
788
/*!
789
\fn template <typename ResultType, typename Iterator, typename MapFunctor, typename ReduceFunctor, typename InitialValueType> ResultType QtConcurrent::blockingMappedReduced(Iterator begin, Iterator end, MapFunctor &&mapFunction, ReduceFunctor &&reduceFunction, InitialValueType &&initialValue, QtConcurrent::ReduceOptions reduceOptions)
790
791
Calls \a mapFunction once for each item from \a begin to \a end. The return
792
value of each \a mapFunction is passed to \a reduceFunction.
793
The result value is initialized to \a initialValue when the function is
794
called, and the first call to \a reduceFunction will operate on
795
this value.
796
797
Note that while \a mapFunction is called concurrently, only one thread at a
798
time will call \a reduceFunction. The order in which \a reduceFunction is
799
called is undefined.
800
801
\note This function will block until the iterator reaches the end of the
802
sequence being processed.
803
804
\sa blockingMappedReduced(), {Concurrent Map and Map-Reduce}
805
*/
qtbase
src
concurrent
qtconcurrentmap.cpp
Generated on
for Qt by
1.14.0