>* __pieces;
1275
1276 __num_threads = static_cast<_ThreadIndex>
1277 (std::min<_DifferenceType>(__num_threads, __total_length));
1278
1279 # pragma omp parallel num_threads (__num_threads)
1280 {
1281 # pragma omp single
1282 {
1283 __num_threads = omp_get_num_threads();
1284 // Thread __t will have to merge pieces[__iam][0..__k - 1]
1285 __pieces = new std::vector<
1286 std::pair<_DifferenceType, _DifferenceType> >[__num_threads];
1287 for (_ThreadIndex __s = 0; __s < __num_threads; ++__s)
1288 __pieces[__s].resize(__k);
1289
1290 _DifferenceType __num_samples =
1291 __gnu_parallel::_Settings::get().merge_oversampling
1292 * __num_threads;
1293
1294 __splitter(__ne_seqs, __ne_seqs + __k, __length, __total_length,
1295 __comp, __pieces);
1296 } //single
1297
1298 _ThreadIndex __iam = omp_get_thread_num();
1299
1300 _DifferenceType __target_position = 0;
1301
1302 for (_SeqNumber __c = 0; __c < __k; ++__c)
1303 __target_position += __pieces[__iam][__c].first;
1304
1305 seq_type* __chunks = new seq_type[__k];
1306
1307 for (_SeqNumber __s = 0; __s < __k; ++__s)
1308 __chunks[__s] = std::make_pair(__ne_seqs[__s].first
1309 + __pieces[__iam][__s].first,
1310 __ne_seqs[__s].first
1311 + __pieces[__iam][__s].second);
1312
1313 if(__length > __target_position)
1314 __sequential_multiway_merge<__stable, __sentinels>
1315 (__chunks, __chunks + __k, __target + __target_position,
1316 *(__seqs_begin->second), __length - __target_position, __comp);
1317
1318 delete[] __chunks;
1319 } // parallel
1320
1321 #if _GLIBCXX_PARALLEL_ASSERTIONS
1322 _GLIBCXX_PARALLEL_ASSERT(
1323 __is_sorted(__target, __target + __length, __comp));
1324 #endif
1325
1326 __k = 0;
1327 // Update ends of sequences.
1328 for (_RAIterIterator __raii = __seqs_begin;
1329 __raii != __seqs_end; ++__raii)
1330 {
1331 _DifferenceTp __length = _GLIBCXX_PARALLEL_LENGTH(*__raii);
1332 if(__length > 0)
1333 (*__raii).first += __pieces[__num_threads - 1][__k++].second;
1334 }
1335
1336 delete[] __pieces;
1337 delete[] __ne_seqs;
1338
1339 return __target + __length;
1340 }
1341
1342 /**
1343 * @brief Multiway Merge Frontend.
1344 *
1345 * Merge the sequences specified by seqs_begin and __seqs_end into
1346 * __target. __seqs_begin and __seqs_end must point to a sequence of
1347 * pairs. These pairs must contain an iterator to the beginning
1348 * of a sequence in their first entry and an iterator the _M_end of
1349 * the same sequence in their second entry.
1350 *
1351 * Ties are broken arbitrarily. See stable_multiway_merge for a variant
1352 * that breaks ties by sequence number but is slower.
1353 *
1354 * The first entries of the pairs (i.e. the begin iterators) will be moved
1355 * forward.
1356 *
1357 * The output sequence has to provide enough space for all elements
1358 * that are written to it.
1359 *
1360 * This function will merge the input sequences:
1361 *
1362 * - not stable
1363 * - parallel, depending on the input size and Settings
1364 * - using sampling for splitting
1365 * - not using sentinels
1366 *
1367 * Example:
1368 *
1369 *
1370 * int sequences[10][10];
1371 * for (int __i = 0; __i < 10; ++__i)
1372 * for (int __j = 0; __i < 10; ++__j)
1373 * sequences[__i][__j] = __j;
1374 *
1375 * int __out[33];
1376 * std::vector > seqs;
1377 * for (int __i = 0; __i < 10; ++__i)
1378 * { seqs.push(std::make_pair(sequences[__i],
1379 * sequences[__i] + 10)) }
1380 *
1381 * multiway_merge(seqs.begin(), seqs.end(), __target, std::less(), 33);
1382 *
1383 *
1384 * @see stable_multiway_merge
1385 *
1386 * @pre All input sequences must be sorted.
1387 * @pre Target must provide enough space to merge out length elements or
1388 * the number of elements in all sequences, whichever is smaller.
1389 *
1390 * @post [__target, return __value) contains merged __elements from the
1391 * input sequences.
1392 * @post return __value - __target = min(__length, number of elements in all
1393 * sequences).
1394 *
1395 * @tparam _RAIterPairIterator iterator over sequence
1396 * of pairs of iterators
1397 * @tparam _RAIterOut iterator over target sequence
1398 * @tparam _DifferenceTp difference type for the sequence
1399 * @tparam _Compare strict weak ordering type to compare elements
1400 * in sequences
1401 *
1402 * @param __seqs_begin __begin of sequence __sequence
1403 * @param __seqs_end _M_end of sequence __sequence
1404 * @param __target target sequence to merge to.
1405 * @param __comp strict weak ordering to use for element comparison.
1406 * @param __length Maximum length to merge, possibly larger than the
1407 * number of elements available.
1408 *
1409 * @return _M_end iterator of output sequence
1410 */
1411 // multiway_merge
1412 // public interface
1413 template
1417 _RAIterOut
1418 multiway_merge(_RAIterPairIterator __seqs_begin,
1419 _RAIterPairIterator __seqs_end,
1420 _RAIterOut __target,
1421 _DifferenceTp __length, _Compare __comp,
1422 __gnu_parallel::sequential_tag)
1423 {
1424 typedef _DifferenceTp _DifferenceType;
1425 _GLIBCXX_CALL(__seqs_end - __seqs_begin)
1426
1427 // catch special case: no sequences
1428 if (__seqs_begin == __seqs_end)
1429 return __target;
1430
1431 // Execute multiway merge *sequentially*.
1432 return __sequential_multiway_merge
1433 * __stable = */ false, /* __sentinels = */ false>
1434 (__seqs_begin, __seqs_end, __target,
1435 *(__seqs_begin->second), __length, __comp);
1436 }
1437
1438 // public interface
1439 template
1443 _RAIterOut
1444 multiway_merge(_RAIterPairIterator __seqs_begin,
1445 _RAIterPairIterator __seqs_end,
1446 _RAIterOut __target,
1447 _DifferenceTp __length, _Compare __comp,
1448 __gnu_parallel::exact_tag __tag)
1449 {
1450 typedef _DifferenceTp _DifferenceType;
1451 _GLIBCXX_CALL(__seqs_end - __seqs_begin)
1452
1453 // catch special case: no sequences
1454 if (__seqs_begin == __seqs_end)
1455 return __target;
1456
1457 // Execute merge; maybe parallel, depending on the number of merged
1458 // elements and the number of sequences and global thresholds in
1459 // Settings.
1460 if ((__seqs_end - __seqs_begin > 1)
1461 && _GLIBCXX_PARALLEL_CONDITION(
1462 ((__seqs_end - __seqs_begin) >=
1463 __gnu_parallel::_Settings::get().multiway_merge_minimal_k)
1464 && ((_SequenceIndex)__length >=
1465 __gnu_parallel::_Settings::get().multiway_merge_minimal_n)))
1466 return parallel_multiway_merge
1467 * __stable = */ false, /* __sentinels = */ false>
1468 (__seqs_begin, __seqs_end, __target,
1469 multiway_merge_exact_splitting* __stable = */ false,
1470 typename std::iterator_traits<_RAIterPairIterator>
1471 ::value_type*, _Compare, _DifferenceTp>,
1472 static_cast<_DifferenceType>(__length), __comp,
1473 __tag.__get_num_threads());
1474 else
1475 return __sequential_multiway_merge
1476 * __stable = */ false, /* __sentinels = */ false>
1477 (__seqs_begin, __seqs_end, __target,
1478 *(__seqs_begin->second), __length, __comp);
1479 }
1480
1481 // public interface
1482 template
1486 _RAIterOut
1487 multiway_merge(_RAIterPairIterator __seqs_begin,
1488 _RAIterPairIterator __seqs_end,
1489 _RAIterOut __target,
1490 _DifferenceTp __length, _Compare __comp,
1491 __gnu_parallel::sampling_tag __tag)
1492 {
1493 typedef _DifferenceTp _DifferenceType;
1494 _GLIBCXX_CALL(__seqs_end - __seqs_begin)
1495
1496 // catch special case: no sequences
1497 if (__seqs_begin == __seqs_end)
1498 return __target;
1499
1500 // Execute merge; maybe parallel, depending on the number of merged
1501 // elements and the number of sequences and global thresholds in
1502 // Settings.
1503 if ((__seqs_end - __seqs_begin > 1)
1504 && _GLIBCXX_PARALLEL_CONDITION(
1505 ((__seqs_end - __seqs_begin) >=
1506 __gnu_parallel::_Settings::get().multiway_merge_minimal_k)
1507 && ((_SequenceIndex)__length >=
1508 __gnu_parallel::_Settings::get().multiway_merge_minimal_n)))
1509 return parallel_multiway_merge
1510 * __stable = */ false, /* __sentinels = */ false>
1511 (__seqs_begin, __seqs_end, __target,
1512 multiway_merge_exact_splitting* __stable = */ false,
1513 typename std::iterator_traits<_RAIterPairIterator>
1514 ::value_type*, _Compare, _DifferenceTp>,
1515 static_cast<_DifferenceType>(__length), __comp,
1516 __tag.__get_num_threads());
1517 else
1518 return __sequential_multiway_merge
1519 * __stable = */ false, /* __sentinels = */ false>
1520 (__seqs_begin, __seqs_end, __target,
1521 *(__seqs_begin->second), __length, __comp);
1522 }
1523
1524 // public interface
1525 template
1529 _RAIterOut
1530 multiway_merge(_RAIterPairIterator __seqs_begin,
1531 _RAIterPairIterator __seqs_end,
1532 _RAIterOut __target,
1533 _DifferenceTp __length, _Compare __comp,
1534 parallel_tag __tag = parallel_tag(0))
1535 { return multiway_merge(__seqs_begin, __seqs_end, __target, __length,
1536 __comp, exact_tag(__tag.__get_num_threads())); }
1537
1538 // public interface
1539 template
1543 _RAIterOut
1544 multiway_merge(_RAIterPairIterator __seqs_begin,
1545 _RAIterPairIterator __seqs_end,
1546 _RAIterOut __target,
1547 _DifferenceTp __length, _Compare __comp,
1548 default_parallel_tag __tag)
1549 { return multiway_merge(__seqs_begin, __seqs_end, __target, __length,
1550 __comp, exact_tag(__tag.__get_num_threads())); }
1551
1552 // stable_multiway_merge
1553 // public interface
1554 template
1558 _RAIterOut
1559 stable_multiway_merge(_RAIterPairIterator __seqs_begin,
1560 _RAIterPairIterator __seqs_end,
1561 _RAIterOut __target,
1562 _DifferenceTp __length, _Compare __comp,
1563 __gnu_parallel::sequential_tag)
1564 {
1565 typedef _DifferenceTp _DifferenceType;
1566 _GLIBCXX_CALL(__seqs_end - __seqs_begin)
1567
1568 // catch special case: no sequences
1569 if (__seqs_begin == __seqs_end)
1570 return __target;
1571
1572 // Execute multiway merge *sequentially*.
1573 return __sequential_multiway_merge
1574 * __stable = */ true, /* __sentinels = */ false>
1575 (__seqs_begin, __seqs_end, __target,
1576 *(__seqs_begin->second), __length, __comp);
1577 }
1578
1579 // public interface
1580 template
1584 _RAIterOut
1585 stable_multiway_merge(_RAIterPairIterator __seqs_begin,
1586 _RAIterPairIterator __seqs_end,
1587 _RAIterOut __target,
1588 _DifferenceTp __length, _Compare __comp,
1589 __gnu_parallel::exact_tag __tag)
1590 {
1591 typedef _DifferenceTp _DifferenceType;
1592 _GLIBCXX_CALL(__seqs_end - __seqs_begin)
1593
1594 // catch special case: no sequences
1595 if (__seqs_begin == __seqs_end)
1596 return __target;
1597
1598 // Execute merge; maybe parallel, depending on the number of merged
1599 // elements and the number of sequences and global thresholds in
1600 // Settings.
1601 if ((__seqs_end - __seqs_begin > 1)
1602 && _GLIBCXX_PARALLEL_CONDITION(
1603 ((__seqs_end - __seqs_begin) >=
1604 __gnu_parallel::_Settings::get().multiway_merge_minimal_k)
1605 && ((_SequenceIndex)__length >=
1606 __gnu_parallel::_Settings::get().multiway_merge_minimal_n)))
1607 return parallel_multiway_merge
1608 * __stable = */ true, /* __sentinels = */ false>
1609 (__seqs_begin, __seqs_end, __target,
1610 multiway_merge_exact_splitting* __stable = */ true,
1611 typename std::iterator_traits<_RAIterPairIterator>
1612 ::value_type*, _Compare, _DifferenceTp>,
1613 static_cast<_DifferenceType>(__length), __comp,
1614 __tag.__get_num_threads());
1615 else
1616 return __sequential_multiway_merge
1617 * __stable = */ true, /* __sentinels = */ false>
1618 (__seqs_begin, __seqs_end, __target,
1619 *(__seqs_begin->second), __length, __comp);
1620 }
1621
1622 // public interface
1623 template
1627 _RAIterOut
1628 stable_multiway_merge(_RAIterPairIterator __seqs_begin,
1629 _RAIterPairIterator __seqs_end,
1630 _RAIterOut __target,
1631 _DifferenceTp __length, _Compare __comp,
1632 sampling_tag __tag)
1633 {
1634 typedef _DifferenceTp _DifferenceType;
1635 _GLIBCXX_CALL(__seqs_end - __seqs_begin)
1636
1637 // catch special case: no sequences
1638 if (__seqs_begin == __seqs_end)
1639 return __target;
1640
1641 // Execute merge; maybe parallel, depending on the number of merged
1642 // elements and the number of sequences and global thresholds in
1643 // Settings.
1644 if ((__seqs_end - __seqs_begin > 1)
1645 && _GLIBCXX_PARALLEL_CONDITION(
1646 ((__seqs_end - __seqs_begin) >=
1647 __gnu_parallel::_Settings::get().multiway_merge_minimal_k)
1648 && ((_SequenceIndex)__length >=
1649 __gnu_parallel::_Settings::get().multiway_merge_minimal_n)))
1650 return parallel_multiway_merge
1651 * __stable = */ true, /* __sentinels = */ false>
1652 (__seqs_begin, __seqs_end, __target,
1653 multiway_merge_sampling_splitting* __stable = */ true,
1654 typename std::iterator_traits<_RAIterPairIterator>
1655 ::value_type*, _Compare, _DifferenceTp>,
1656 static_cast<_DifferenceType>(__length), __comp,
1657 __tag.__get_num_threads());
1658 else
1659 return __sequential_multiway_merge
1660 * __stable = */ true, /* __sentinels = */ false>
1661 (__seqs_begin, __seqs_end, __target,
1662 *(__seqs_begin->second), __length, __comp);
1663 }
1664
1665 // public interface
1666 template
1670 _RAIterOut
1671 stable_multiway_merge(_RAIterPairIterator __seqs_begin,
1672 _RAIterPairIterator __seqs_end,
1673 _RAIterOut __target,
1674 _DifferenceTp __length, _Compare __comp,
1675 parallel_tag __tag = parallel_tag(0))
1676 {
1677 return stable_multiway_merge
1678 (__seqs_begin, __seqs_end, __target, __length, __comp,
1679 exact_tag(__tag.__get_num_threads()));
1680 }
1681
1682 // public interface
1683 template
1687 _RAIterOut
1688 stable_multiway_merge(_RAIterPairIterator __seqs_begin,
1689 _RAIterPairIterator __seqs_end,
1690 _RAIterOut __target,
1691 _DifferenceTp __length, _Compare __comp,
1692 default_parallel_tag __tag)
1693 {
1694 return stable_multiway_merge
1695 (__seqs_begin, __seqs_end, __target, __length, __comp,
1696 exact_tag(__tag.__get_num_threads()));
1697 }
1698
1699 /**
1700 * @brief Multiway Merge Frontend.
1701 *
1702 * Merge the sequences specified by seqs_begin and __seqs_end into
1703 * __target. __seqs_begin and __seqs_end must point to a sequence of
1704 * pairs. These pairs must contain an iterator to the beginning
1705 * of a sequence in their first entry and an iterator the _M_end of
1706 * the same sequence in their second entry.
1707 *
1708 * Ties are broken arbitrarily. See stable_multiway_merge for a variant
1709 * that breaks ties by sequence number but is slower.
1710 *
1711 * The first entries of the pairs (i.e. the begin iterators) will be moved
1712 * forward accordingly.
1713 *
1714 * The output sequence has to provide enough space for all elements
1715 * that are written to it.
1716 *
1717 * This function will merge the input sequences:
1718 *
1719 * - not stable
1720 * - parallel, depending on the input size and Settings
1721 * - using sampling for splitting
1722 * - using sentinels
1723 *
1724 * You have to take care that the element the _M_end iterator points to is
1725 * readable and contains a value that is greater than any other non-sentinel
1726 * value in all sequences.
1727 *
1728 * Example:
1729 *
1730 *
1731 * int sequences[10][11];
1732 * for (int __i = 0; __i < 10; ++__i)
1733 * for (int __j = 0; __i < 11; ++__j)
1734 * sequences[__i][__j] = __j; // __last one is sentinel!
1735 *
1736 * int __out[33];
1737 * std::vector > seqs;
1738 * for (int __i = 0; __i < 10; ++__i)
1739 * { seqs.push(std::make_pair(sequences[__i],
1740 * sequences[__i] + 10)) }
1741 *
1742 * multiway_merge(seqs.begin(), seqs.end(), __target, std::less(), 33);
1743 *
1744 *
1745 * @pre All input sequences must be sorted.
1746 * @pre Target must provide enough space to merge out length elements or
1747 * the number of elements in all sequences, whichever is smaller.
1748 * @pre For each @c __i, @c __seqs_begin[__i].second must be the end
1749 * marker of the sequence, but also reference the one more __sentinel
1750 * element.
1751 *
1752 * @post [__target, return __value) contains merged __elements from the
1753 * input sequences.
1754 * @post return __value - __target = min(__length, number of elements in all
1755 * sequences).
1756 *
1757 * @see stable_multiway_merge_sentinels
1758 *
1759 * @tparam _RAIterPairIterator iterator over sequence
1760 * of pairs of iterators
1761 * @tparam _RAIterOut iterator over target sequence
1762 * @tparam _DifferenceTp difference type for the sequence
1763 * @tparam _Compare strict weak ordering type to compare elements
1764 * in sequences
1765 *
1766 * @param __seqs_begin __begin of sequence __sequence
1767 * @param __seqs_end _M_end of sequence __sequence
1768 * @param __target target sequence to merge to.
1769 * @param __comp strict weak ordering to use for element comparison.
1770 * @param __length Maximum length to merge, possibly larger than the
1771 * number of elements available.
1772 *
1773 * @return _M_end iterator of output sequence
1774 */
1775 // multiway_merge_sentinels
1776 // public interface
1777 template
1781 _RAIterOut
1782 multiway_merge_sentinels(_RAIterPairIterator __seqs_begin,
1783 _RAIterPairIterator __seqs_end,
1784 _RAIterOut __target,
1785 _DifferenceTp __length, _Compare __comp,
1786 __gnu_parallel::sequential_tag)
1787 {
1788 typedef _DifferenceTp _DifferenceType;
1789 _GLIBCXX_CALL(__seqs_end - __seqs_begin)
1790
1791 // catch special case: no sequences
1792 if (__seqs_begin == __seqs_end)
1793 return __target;
1794
1795 // Execute multiway merge *sequentially*.
1796 return __sequential_multiway_merge
1797 * __stable = */ false, /* __sentinels = */ true>
1798 (__seqs_begin, __seqs_end,
1799 __target, *(__seqs_begin->second), __length, __comp);
1800 }
1801
1802 // public interface
1803 template
1807 _RAIterOut
1808 multiway_merge_sentinels(_RAIterPairIterator __seqs_begin,
1809 _RAIterPairIterator __seqs_end,
1810 _RAIterOut __target,
1811 _DifferenceTp __length, _Compare __comp,
1812 __gnu_parallel::exact_tag __tag)
1813 {
1814 typedef _DifferenceTp _DifferenceType;
1815 _GLIBCXX_CALL(__seqs_end - __seqs_begin)
1816
1817 // catch special case: no sequences
1818 if (__seqs_begin == __seqs_end)
1819 return __target;
1820
1821 // Execute merge; maybe parallel, depending on the number of merged
1822 // elements and the number of sequences and global thresholds in
1823 // Settings.
1824 if ((__seqs_end - __seqs_begin > 1)
1825 && _GLIBCXX_PARALLEL_CONDITION(
1826 ((__seqs_end - __seqs_begin) >=
1827 __gnu_parallel::_Settings::get().multiway_merge_minimal_k)
1828 && ((_SequenceIndex)__length >=
1829 __gnu_parallel::_Settings::get().multiway_merge_minimal_n)))
1830 return parallel_multiway_merge
1831 * __stable = */ false, /* __sentinels = */ true>
1832 (__seqs_begin, __seqs_end, __target,
1833 multiway_merge_exact_splitting* __stable = */ false,
1834 typename std::iterator_traits<_RAIterPairIterator>
1835 ::value_type*, _Compare, _DifferenceTp>,
1836 static_cast<_DifferenceType>(__length), __comp,
1837 __tag.__get_num_threads());
1838 else
1839 return __sequential_multiway_merge
1840 * __stable = */ false, /* __sentinels = */ true>
1841 (__seqs_begin, __seqs_end, __target,
1842 *(__seqs_begin->second), __length, __comp);
1843 }
1844
1845 // public interface
1846 template
1850 _RAIterOut
1851 multiway_merge_sentinels(_RAIterPairIterator __seqs_begin,
1852 _RAIterPairIterator __seqs_end,
1853 _RAIterOut __target,
1854 _DifferenceTp __length, _Compare __comp,
1855 sampling_tag __tag)
1856 {
1857 typedef _DifferenceTp _DifferenceType;
1858 _GLIBCXX_CALL(__seqs_end - __seqs_begin)
1859
1860 // catch special case: no sequences
1861 if (__seqs_begin == __seqs_end)
1862 return __target;
1863
1864 // Execute merge; maybe parallel, depending on the number of merged
1865 // elements and the number of sequences and global thresholds in
1866 // Settings.
1867 if ((__seqs_end - __seqs_begin > 1)
1868 && _GLIBCXX_PARALLEL_CONDITION(
1869 ((__seqs_end - __seqs_begin) >=
1870 __gnu_parallel::_Settings::get().multiway_merge_minimal_k)
1871 && ((_SequenceIndex)__length >=
1872 __gnu_parallel::_Settings::get().multiway_merge_minimal_n)))
1873 return parallel_multiway_merge
1874 * __stable = */ false, /* __sentinels = */ true>
1875 (__seqs_begin, __seqs_end, __target,
1876 multiway_merge_sampling_splitting* __stable = */ false,
1877 typename std::iterator_traits<_RAIterPairIterator>
1878 ::value_type*, _Compare, _DifferenceTp>,
1879 static_cast<_DifferenceType>(__length), __comp,
1880 __tag.__get_num_threads());
1881 else
1882 return __sequential_multiway_merge
1883 * __stable = */false, /* __sentinels = */ true>(
1884 __seqs_begin, __seqs_end, __target,
1885 *(__seqs_begin->second), __length, __comp);
1886 }
1887
1888 // public interface
1889 template
1893 _RAIterOut
1894 multiway_merge_sentinels(_RAIterPairIterator __seqs_begin,
1895 _RAIterPairIterator __seqs_end,
1896 _RAIterOut __target,
1897 _DifferenceTp __length, _Compare __comp,
1898 parallel_tag __tag = parallel_tag(0))
1899 {
1900 return multiway_merge_sentinels
1901 (__seqs_begin, __seqs_end, __target, __length, __comp,
1902 exact_tag(__tag.__get_num_threads()));
1903 }
1904
1905 // public interface
1906 template
1910 _RAIterOut
1911 multiway_merge_sentinels(_RAIterPairIterator __seqs_begin,
1912 _RAIterPairIterator __seqs_end,
1913 _RAIterOut __target,
1914 _DifferenceTp __length, _Compare __comp,
1915 default_parallel_tag __tag)
1916 {
1917 return multiway_merge_sentinels
1918 (__seqs_begin, __seqs_end, __target, __length, __comp,
1919 exact_tag(__tag.__get_num_threads()));
1920 }
1921
1922 // stable_multiway_merge_sentinels
1923 // public interface
1924 template
1928 _RAIterOut
1929 stable_multiway_merge_sentinels(_RAIterPairIterator __seqs_begin,
1930 _RAIterPairIterator __seqs_end,
1931 _RAIterOut __target,
1932 _DifferenceTp __length, _Compare __comp,
1933 __gnu_parallel::sequential_tag)
1934 {
1935 typedef _DifferenceTp _DifferenceType;
1936 _GLIBCXX_CALL(__seqs_end - __seqs_begin)
1937
1938 // catch special case: no sequences
1939 if (__seqs_begin == __seqs_end)
1940 return __target;
1941
1942 // Execute multiway merge *sequentially*.
1943 return __sequential_multiway_merge
1944 * __stable = */ true, /* __sentinels = */ true>
1945 (__seqs_begin, __seqs_end, __target,
1946 *(__seqs_begin->second), __length, __comp);
1947 }
1948
1949 // public interface
1950 template
1954 _RAIterOut
1955 stable_multiway_merge_sentinels(_RAIterPairIterator __seqs_begin,
1956 _RAIterPairIterator __seqs_end,
1957 _RAIterOut __target,
1958 _DifferenceTp __length, _Compare __comp,
1959 __gnu_parallel::exact_tag __tag)
1960 {
1961 typedef _DifferenceTp _DifferenceType;
1962 _GLIBCXX_CALL(__seqs_end - __seqs_begin)
1963
1964 // catch special case: no sequences
1965 if (__seqs_begin == __seqs_end)
1966 return __target;
1967
1968 // Execute merge; maybe parallel, depending on the number of merged
1969 // elements and the number of sequences and global thresholds in
1970 // Settings.
1971 if ((__seqs_end - __seqs_begin > 1)
1972 && _GLIBCXX_PARALLEL_CONDITION(
1973 ((__seqs_end - __seqs_begin) >=
1974 __gnu_parallel::_Settings::get().multiway_merge_minimal_k)
1975 && ((_SequenceIndex)__length >=
1976 __gnu_parallel::_Settings::get().multiway_merge_minimal_n)))
1977 return parallel_multiway_merge
1978 * __stable = */ true, /* __sentinels = */ true>
1979 (__seqs_begin, __seqs_end, __target,
1980 multiway_merge_exact_splitting* __stable = */ true,
1981 typename std::iterator_traits<_RAIterPairIterator>
1982 ::value_type*, _Compare, _DifferenceTp>,
1983 static_cast<_DifferenceType>(__length), __comp,
1984 __tag.__get_num_threads());
1985 else
1986 return __sequential_multiway_merge
1987 * __stable = */ true, /* __sentinels = */ true>
1988 (__seqs_begin, __seqs_end, __target,
1989 *(__seqs_begin->second), __length, __comp);
1990 }
1991
1992 // public interface
1993 template
1997 _RAIterOut
1998 stable_multiway_merge_sentinels(_RAIterPairIterator __seqs_begin,
1999 _RAIterPairIterator __seqs_end,
2000 _RAIterOut __target,
2001 _DifferenceTp __length,
2002 _Compare __comp,
2003 sampling_tag __tag)
2004 {
2005 typedef _DifferenceTp _DifferenceType;
2006 _GLIBCXX_CALL(__seqs_end - __seqs_begin)
2007
2008 // catch special case: no sequences
2009 if (__seqs_begin == __seqs_end)
2010 return __target;
2011
2012 // Execute merge; maybe parallel, depending on the number of merged
2013 // elements and the number of sequences and global thresholds in
2014 // Settings.
2015 if ((__seqs_end - __seqs_begin > 1)
2016 && _GLIBCXX_PARALLEL_CONDITION(
2017 ((__seqs_end - __seqs_begin) >=
2018 __gnu_parallel::_Settings::get().multiway_merge_minimal_k)
2019 && ((_SequenceIndex)__length >=
2020 __gnu_parallel::_Settings::get().multiway_merge_minimal_n)))
2021 return parallel_multiway_merge
2022 * __stable = */ true, /* __sentinels = */ true>
2023 (__seqs_begin, __seqs_end, __target,
2024 multiway_merge_sampling_splitting* __stable = */ true,
2025 typename std::iterator_traits<_RAIterPairIterator>
2026 ::value_type*, _Compare, _DifferenceTp>,
2027 static_cast<_DifferenceType>(__length), __comp,
2028 __tag.__get_num_threads());
2029 else
2030 return __sequential_multiway_merge
2031 * __stable = */ true, /* __sentinels = */ true>
2032 (__seqs_begin, __seqs_end, __target,
2033 *(__seqs_begin->second), __length, __comp);
2034 }
2035
2036 // public interface
2037 template
2041 _RAIterOut
2042 stable_multiway_merge_sentinels(_RAIterPairIterator __seqs_begin,
2043 _RAIterPairIterator __seqs_end,
2044 _RAIterOut __target,
2045 _DifferenceTp __length,
2046 _Compare __comp,
2047 parallel_tag __tag = parallel_tag(0))
2048 {
2049 return stable_multiway_merge_sentinels
2050 (__seqs_begin, __seqs_end, __target, __length, __comp,
2051 exact_tag(__tag.__get_num_threads()));
2052 }
2053
2054 // public interface
2055 template
2059 _RAIterOut
2060 stable_multiway_merge_sentinels(_RAIterPairIterator __seqs_begin,
2061 _RAIterPairIterator __seqs_end,
2062 _RAIterOut __target,
2063 _DifferenceTp __length, _Compare __comp,
2064 default_parallel_tag __tag)
2065 {
2066 return stable_multiway_merge_sentinels
2067 (__seqs_begin, __seqs_end, __target, __length, __comp,
2068 exact_tag(__tag.__get_num_threads()));
2069 }
2070 }; // namespace __gnu_parallel
2071
2072 #endif /* _GLIBCXX_PARALLEL_MULTIWAY_MERGE_H */