Compare commits

..

110 Commits

Author SHA1 Message Date
1c5f74ae25 Merge doc fixes to master 2022-07-06 08:22:07 -07:00
1cfd9592f7 New features for the 1.80.0 release 2022-06-29 14:03:25 -07:00
559835eaa5 Merge branch 'develop' 2022-06-23 21:09:11 -07:00
3b3bd8d3db Merge changes from develop for the 1.76.0 release 2021-04-07 09:28:02 -07:00
ca77e55428 Bug fixes for 1/75/0 2020-11-17 15:45:39 -08:00
7f527f3c4d Merge changes from develop for the 1.74.0 release 2020-06-24 09:47:23 -07:00
e59958cc4d Merge include + doc fixes to master for 1.72 release 2019-12-03 16:53:16 -08:00
44527f4c81 Algorithm: Merge example fixes master for 1.72.0 2019-12-03 07:48:39 -08:00
1b65b8de02 Merge bug fixes to master for 1.71 2019-07-10 15:14:08 -07:00
5af3e3b174 Merge bug fixes to master 2018-12-04 09:35:03 -08:00
badf1b3f0c Merge broken links to master. NFC 2018-07-31 22:57:40 -07:00
4f9afb0682 Merge for the 1.68.0 beta 2018-07-04 11:27:27 -07:00
6d0126df8a Catch up with the changes; apply_permutation; constexpr, etc 2018-05-01 08:17:06 -07:00
daef6d41c5 C++17 algorithms 2017-06-28 20:13:38 -07:00
055075aa61 Bug fixes and is_partititioned_XXX for the 1.65.0 release 2017-06-14 18:49:39 -07:00
d029402f05 Add, and update, documentation build targets. 2016-10-10 11:24:26 -05:00
24d2cceb27 Fix a couple of test failures for the 1.62.0 release 2016-08-17 18:11:47 -07:00
c5b41eba46 Merge to master for 1.62.0 release 2016-08-17 13:32:45 -07:00
e5ea93bab1 Revert "Merge pull request #14 from nigels-com/merge-hex_lower"
This reverts commit 5412438df5, reversing
changes made to a09963bf93.
2016-03-07 15:43:55 -08:00
5412438df5 Merge pull request #14 from nigels-com/merge-hex_lower
Implement algorithm::hex_lower (Trac ticket #7064)
2016-03-07 14:57:34 -08:00
baa6eca18c Test coverage for algorithm::hex_lower, adapting existing coverage for algorithm::hex 2016-01-31 20:18:22 +10:00
073eb62f64 Another overload of algorithm::hex_lower as lower-case alternative to algorithm::hex 2016-01-31 20:17:23 +10:00
cc1392cae6 Implement algorithm::hex_lower as lower-case alternative to algorithm::hex 2016-01-31 19:11:11 +10:00
a09963bf93 Merge from develop; new feature 'power'; doc fixes; remove usage of C++11 versions of the algorithms 2015-03-18 21:31:53 -07:00
cf249c090c Merge from develop: clean up is_permutation; fix clamp interface, and merge fix for bug #9335 as well 2014-03-31 12:03:45 -07:00
645be22fa7 Setting merge point for git merges 2014-03-23 14:33:14 -07:00
28b12d7264 Algorithm: Remove obsolete MSVC version checks.
[SVN r86024]
2014-03-23 14:30:10 -07:00
4d28d579e3 Remove BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
Process #ifdef...#endif blocks.

[SVN r86243]
2014-03-23 14:27:55 -07:00
5adab54486 Remove BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
Process #ifdef...#else...#endif blocks.

[SVN r86246]
2014-03-23 14:27:55 -07:00
685a76f094 Merge a bunch of minor Boost.Algorithm changes to release
[SVN r86757]
2013-11-18 16:52:09 +00:00
5988a55b96 Minor merging; removing tabs from source files
[SVN r86323]
2013-10-15 15:44:55 +00:00
850fc02667 Merge bug fix for #9063 to release
[SVN r86218]
2013-10-09 18:09:40 +00:00
5279c8f061 Merge minor Boost.Algorithm doc fixes to the release branch
[SVN r86200]
2013-10-08 15:31:14 +00:00
8b89b5ba27 Merged changes from trunk.
[SVN r85804]
2013-09-20 17:40:42 +00:00
ca23b6f4f8 Merge bug fix to Release; Fixes #8546
[SVN r85134]
2013-07-23 16:48:27 +00:00
55cb3afefa Merge test fixup to release
[SVN r84825]
2013-06-18 14:48:37 +00:00
beeedadba9 Merge doc changes from trunk
[SVN r84743]
2013-06-11 16:21:22 +00:00
1a70166889 Merge c++14 changes to release
[SVN r84415]
2013-05-22 15:10:49 +00:00
63da6f5713 Merge Algorithm changes to release; hex code cleanups; gather iterator requirements; copy_while and copy_until interface changes
[SVN r83347]
2013-03-07 15:37:08 +00:00
2381d0bdac Merge bug fix to release; Fixes #7989
[SVN r83193]
2013-02-27 23:37:21 +00:00
40b5941652 One more failed merge
[SVN r83192]
2013-02-27 23:36:16 +00:00
00dfda98b2 more merge failures
[SVN r83171]
2013-02-26 22:05:42 +00:00
52eef989da Clean up merge failure
[SVN r83170]
2013-02-26 22:03:44 +00:00
8132864884 Merged boost::algorithm::gather and updated tests for Utility, Algorithm and Utility libraries
[SVN r83154]
2013-02-25 18:43:26 +00:00
6e098b27aa Merge Michael Morin's typo fixes for Boost.Algorithm to release; no functionality change.
[SVN r82240]
2012-12-28 18:19:25 +00:00
60010b4165 Merge bug fix and test to release; Fixes #7784
[SVN r82238]
2012-12-28 17:39:08 +00:00
1660dc9d48 merge bug fix for minmax_element to release; Fixes #7752
[SVN r82049]
2012-12-17 16:02:38 +00:00
5ae4f848b3 Remove tabs from Boost.Algorithm tests.
[SVN r81857]
2012-12-11 16:56:30 +00:00
fe3e0bb9c4 merge K-M-P doc updates to release; Fixes #7656
[SVN r81840]
2012-12-10 21:13:08 +00:00
311e169376 Merge extra tests for Boost.StringAlgo.Split to release
[SVN r81835]
2012-12-10 20:10:12 +00:00
3dddfa1930 Merge from trunk; Fixes #7346
[SVN r81832]
2012-12-10 19:23:54 +00:00
be6d8f9665 Merge URL fix for boyer-moore; Fixes #7781
[SVN r81825]
2012-12-10 15:40:23 +00:00
bced4ed8dd Merge doc fix for minmax; Fixes #7751
[SVN r81823]
2012-12-10 15:28:36 +00:00
1b57e905ab Merge bug fixes to release; Fixes #7339
[SVN r80808]
2012-10-01 15:31:51 +00:00
29bd9f53d9 Merge bug fixes to release; Fixes #7399 Fixes #7400 Fixes #7401
[SVN r80670]
2012-09-23 14:56:41 +00:00
6341cfb1a6 Merge doc typo corrections to release; fixes #6595; fixes #7182
[SVN r80057]
2012-08-16 05:16:42 +00:00
7f4acd6170 Merged typos in comments to release; no functionality; Fixes #7210
[SVN r79929]
2012-08-08 16:30:33 +00:00
314f6dcfe0 Merge changes from [79588] to Release; fixes a unhex bug
[SVN r79604]
2012-07-19 15:12:33 +00:00
167aa6e31c Get rid of tabs in Boost.Algorithm tests
[SVN r79603]
2012-07-19 15:00:27 +00:00
d228e91494 Merge Boost.Algorithm changes to release; Fixes #7104
[SVN r79538]
2012-07-15 16:28:35 +00:00
9cc573fbd0 Fixed errors in the doxygen comments. Fixes #7083.
[SVN r79285]
2012-07-05 15:30:17 +00:00
28a7d3eb4b Merge doc changes to release; fixes #7073
[SVN r79264]
2012-07-04 16:15:35 +00:00
883cce61a8 Merge algorithm's html redirect.
[SVN r78855]
2012-06-07 20:05:17 +00:00
96d4708367 Merge Boost.Algorithm inspection report changes to release. No functionality change
[SVN r78689]
2012-05-27 15:45:18 +00:00
563fe27a59 Merged changes for Boost.Algorithm to release; Fixes #6596; Fixes #6689; Fixes #3215; Fixes #6840
[SVN r78557]
2012-05-23 16:25:48 +00:00
76cd99ed53 Merge Boost.Algorithm to release branch
[SVN r78025]
2012-04-16 18:54:41 +00:00
0f2399fef0 Merge changes to release; fixes #5589
[SVN r76527]
2012-01-15 16:49:25 +00:00
044d667e79 Merge changes to release; fixes #3634
[SVN r76522]
2012-01-15 16:05:55 +00:00
be9da63894 Merge fix for #4937 to release
[SVN r76267]
2012-01-01 21:18:47 +00:00
787c94bc53 Merge Change 68161 to release
[SVN r76266]
2012-01-01 21:17:02 +00:00
e87ce37b34 Merge Change 76213 to release; Fixes #4811
[SVN r76265]
2012-01-01 21:12:58 +00:00
199a89a1e9 merged from trunk
[SVN r72380]
2011-06-03 21:13:37 +00:00
01492a93c6 trunk changes merged
[SVN r67922]
2011-01-10 19:36:38 +00:00
50703b8c97 Merge documentation fixes to release.
[SVN r66285]
2010-10-30 17:34:45 +00:00
0f8d556130 Merge r65004 from trunk
Fix #4551,#4553,#4575 by removing unused parameter.



[SVN r65168]
2010-09-01 16:18:07 +00:00
bbd3220a1e Merging changes from trunk
[SVN r63824]
2010-07-10 20:29:03 +00:00
9068069106 Spirit: merging from trunk upto rev. 61489
[SVN r63640]
2010-07-04 22:38:38 +00:00
a37af3c81e Merge documentation fixes.
* Use `doc/src/*.css` instead of `doc/html/*.css`.
* Remove wiki and people directories.
* Some documentation fixes.
* Left out `minimal.css` changes and boostbook changes because of clashes.


[SVN r63347]
2010-06-26 12:30:09 +00:00
f5885c6fb0 Merge minmax from the trunk
[SVN r62088]
2010-05-18 17:53:36 +00:00
d45bb3545e Merge some link fixes and release notes.
[SVN r61474]
2010-04-21 23:00:35 +00:00
d735b9fa1e rm cmake from the release branch before it goes out broken. Policy dictates that you never commit to release, you commit to trunk and merge to release.
[SVN r56941]
2009-10-17 01:10:45 +00:00
62ec675581 Merged changes from trunk
[SVN r56176]
2009-09-13 19:10:55 +00:00
e7cd4da67b Add basic copyright/license to keep cmake out of the inspection report
[SVN r55095]
2009-07-22 21:51:01 +00:00
6076f5a18e Merge [53520] from the trunk
[SVN r53909]
2009-06-14 22:56:08 +00:00
60cd5a0500 Merge [53062] from the trunk
[SVN r53270]
2009-05-26 01:17:07 +00:00
c33dad924d Fixed almost all tab and min/max issues found by inspect tool
[SVN r53142]
2009-05-20 19:41:20 +00:00
2f2935f07e Merged revisions 45283,48266 via svnmerge from
https://svn.boost.org/svn/boost/trunk

........
  r45283 | danieljames | 2008-05-11 14:49:20 +0100 (Sun, 11 May 2008) | 1 line
  
  Quote href values - our tools don't support unquoted values.
........
  r48266 | danieljames | 2008-08-20 20:32:23 +0100 (Wed, 20 Aug 2008) | 1 line
  
  Fix the link to the limits documentation.
........


[SVN r51902]
2009-03-22 17:30:02 +00:00
3cbaafc27f Merge PDF build changes from Trunk.
[SVN r51417]
2009-02-23 18:39:32 +00:00
c067b348bf Merge [51045] from the trunk
[SVN r51226]
2009-02-12 18:47:06 +00:00
c33935fa1f merge of cmake build files from trunk per beman
[SVN r50756]
2009-01-24 18:57:20 +00:00
98a8b08afb Memory management fixes for is_any_of predicate merged from the trunk
[SVN r49172]
2008-10-07 21:59:57 +00:00
fc0f3dcffc Cummulative merge of updates from the main trunk
[SVN r46505]
2008-06-19 12:07:24 +00:00
822636418b Merged revisions 43211,43214-43219,43222-43225,43227-43238,43242,43244-43245,43249-43250,43257-43259,43261,43263,43265,43267-43268,43270-43271,43273,43275-43279,43284-43289,43291,43295,43297-43298,43304-43305,43307,43313,43315,43324,43326-43327,43331,43333,43339-43343,43345,43348,43350,43352-43353,43355-43356,43358,43360,43366-43367,43369-43370,43372-43376,43378-43389,43394,43396-43398,43400-43401,43403-43404,43406-43408,43413-43415,43417-43418,43420,43422-43423 via svnmerge from
https://svn.boost.org/svn/boost/trunk

........
  r43417 | danieljames | 2008-02-26 22:04:55 +0000 (Tue, 26 Feb 2008) | 2 lines
  
  Fix a link to Boost.Bimap.
........
  r43418 | danieljames | 2008-02-26 22:07:25 +0000 (Tue, 26 Feb 2008) | 2 lines
  
  Change another link that's no longer in the repository to link to the website.
........
  r43422 | danieljames | 2008-02-27 18:51:14 +0000 (Wed, 27 Feb 2008) | 1 line
  
  Fix broken copyright urls. Fixes #1573.
........
  r43423 | danieljames | 2008-02-27 19:22:01 +0000 (Wed, 27 Feb 2008) | 1 line
  
  Fix incorrect links to copyright of the form 'http:#www.boost.org
........


[SVN r43425]
2008-02-27 20:00:24 +00:00
352e16aade Merged revisions 43206,43208-43213 via svnmerge from
https://svn.boost.org/svn/boost/trunk

........
  r43206 | danieljames | 2008-02-10 09:55:03 +0000 (Sun, 10 Feb 2008) | 1 line
  
  Fix some broken links.
........
  r43209 | danieljames | 2008-02-10 14:56:22 +0000 (Sun, 10 Feb 2008) | 1 line
  
  Link to people pages on the website, as they've been removed from the download.
........
  r43210 | danieljames | 2008-02-10 15:02:17 +0000 (Sun, 10 Feb 2008) | 1 line
  
  Point links to the pages that used to be in 'more' to the site.
........
  r43212 | danieljames | 2008-02-10 16:10:16 +0000 (Sun, 10 Feb 2008) | 1 line
  
  Fix links on the home page as well.
........
  r43213 | danieljames | 2008-02-10 16:21:22 +0000 (Sun, 10 Feb 2008) | 1 line
  
  Generated documentation which is no longer generated.
........


[SVN r43214]
2008-02-10 16:39:38 +00:00
89c76ea1bb Full merge from trunk at revision 41356 of entire boost-root tree.
[SVN r41370]
2007-11-25 18:38:02 +00:00
50b5726a6f Full merge from trunk at revision 41356 of entire boost-root tree.
[SVN r41369]
2007-11-25 18:07:19 +00:00
d4b95734dd Starting point for releases
[SVN r39706]
2007-10-05 14:25:06 +00:00
05af96f84c This commit was manufactured by cvs2svn to create tag
'Version_1_34_1'.

[SVN r38286]
2007-07-24 19:28:14 +00:00
5bdbb2b308 Documentation for iter_find/iter_split added
[SVN r37842]
2007-06-01 13:50:51 +00:00
1a02969303 release notes - fix the incorrect functionname spelling
[SVN r37533]
2007-04-29 07:04:58 +00:00
6309379618 release notes for 1.34 added
[SVN r37532]
2007-04-29 07:02:21 +00:00
37581bac55 documentation typo fixed
[SVN r36843]
2007-01-30 07:59:28 +00:00
a71a4ed5b1 Merged copyright and license addition
[SVN r35907]
2006-11-07 19:27:00 +00:00
c509c3fbad Remove obsolete Boost.Build v1 files.
[SVN r35880]
2006-11-06 17:10:46 +00:00
d8683f2498 unused parameters removed
[SVN r35753]
2006-10-27 17:37:37 +00:00
7c0101aa51 Copyright added to index.html
unneeded file removed


[SVN r34908]
2006-08-20 20:14:48 +00:00
6f3e85528f License added to the xml documentation files
[SVN r34894]
2006-08-16 07:10:48 +00:00
8af639b7cf missing 'using' directives for join_if and join_if_regex added
missing #include <boost/algorithm/string/join.hpp> added to string_algo.hpp


[SVN r34122]
2006-05-30 19:13:08 +00:00
d9bc7e800b Merged patch from main trunk for borland by Nicola Musatti
[SVN r33723]
2006-04-17 17:16:11 +00:00
b4ed9beb90 This commit was manufactured by cvs2svn to create branch 'RC_1_34_0'.
[SVN r33417]
2006-03-21 02:26:31 +00:00
24 changed files with 52 additions and 724 deletions

View File

@ -16,18 +16,18 @@ using quickbook ;
using doxygen ;
using boostbook ;
doxygen autodoc
:
[ glob ../../../boost/algorithm/*.hpp
doxygen autodoc
:
[ glob ../../../boost/algorithm/*.hpp
../../../boost/algorithm/searching/*.hpp
../../../boost/algorithm/cxx11/*.hpp
../../../boost/algorithm/cxx14/*.hpp
../../../boost/algorithm/cxx17/*.hpp
]
:
:
<doxygen:param>"PREDEFINED=\"BOOST_ALGORITHM_DOXYGEN=1\""
<doxygen:param>WARNINGS=YES # Default NO, but useful to see warnings, especially in a logfile.
;
;
xml algorithm : algorithm.qbk ;
@ -36,7 +36,7 @@ boostbook standalone
:
algorithm
:
<dependency>autodoc
<dependency>autodoc
<xsl:param>boost.root=../../../..
<xsl:param>"boost.doxygen.reftitle=Boost.Algorithms C++ Reference"
<xsl:param>chapter.autolabel=0

View File

@ -233,8 +233,6 @@ Convert a sequence of hexadecimal characters into a sequence of integers or char
Convert a sequence of integral types into a lower case hexadecimal sequence of characters
[endsect:hex_lower]
[include indirect_sort.qbk]
[include is_palindrome.qbk]
[include is_partitioned_until.qbk]

View File

@ -16,12 +16,12 @@ The routine `apply_permutation` takes a item sequence and a order sequence. It r
The routine `apply_reverse_permutation` takes a item sequence and a order sequence. It will reshuffle item sequence according to order sequence. Every value in order sequence means where the item goes to. Order sequence needs to be exactly a permutation of the sequence [0, 1, ... , N], where N is the biggest index in the item sequence (zero-indexed).
Implementations are based on these articles:
https://devblogs.microsoft.com/oldnewthing/20170102-00/?p=95095
https://devblogs.microsoft.com/oldnewthing/20170103-00/?p=95105
https://devblogs.microsoft.com/oldnewthing/20170104-00/?p=95115
https://devblogs.microsoft.com/oldnewthing/20170109-00/?p=95145
https://devblogs.microsoft.com/oldnewthing/20170110-00/?p=95155
https://devblogs.microsoft.com/oldnewthing/20170111-00/?p=95165
https://blogs.msdn.microsoft.com/oldnewthing/20170102-00/?p=95095
https://blogs.msdn.microsoft.com/oldnewthing/20170103-00/?p=95105
https://blogs.msdn.microsoft.com/oldnewthing/20170104-00/?p=95115
https://blogs.msdn.microsoft.com/oldnewthing/20170109-00/?p=95145
https://blogs.msdn.microsoft.com/oldnewthing/20170110-00/?p=95155
https://blogs.msdn.microsoft.com/oldnewthing/20170111-00/?p=95165
The routines come in 2 forms; the first one takes two iterators to define the item range and one iterator to define the beginning of index range. The second form takes range to define the item sequence and range to define index sequence.

View File

@ -1,111 +0,0 @@
[/ File indirect_sort.qbk]
[section:indirect_sort indirect_sort ]
[/license
Copyright (c) 2023 Marshall Clow
Distributed under the Boost Software License, Version 1.0.
(See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
]
There are times that you want a sorted version of a sequence, but for some reason you don't want to modify it. Maybe the elements in the sequence can't be moved/copied, e.g. the sequence is const, or they're just really expensive to move around. An example of this might be a sequence of records from a database.
That's where indirect sorting comes in. In a "normal" sort, the elements of the sequence to be sorted are shuffled in place. In indirect sorting, the elements are unchanged, but the sort algorithm returns a "permutation" of the elements that, when applied, will put the elements in the sequence in a sorted order.
Assume have a sequence `[first, last)` of 1000 items that are expensive to swap:
```
std::sort(first, last); // ['O(N ln N)] comparisons and ['O(N ln N)] swaps (of the element type).
```
On the other hand, using indirect sorting:
```
auto perm = indirect_sort(first, last); // ['O(N lg N)] comparisons and ['O(N lg N)] swaps (of size_t).
apply_permutation(first, last, perm.begin(), perm.end()); // ['O(N)] swaps (of the element type)
```
If the element type is sufficiently expensive to swap, then 10,000 swaps of size_t + 1000 swaps of the element_type could be cheaper than 10,000 swaps of the element_type.
Or maybe you don't need the elements to actually be sorted - you just want to traverse them in a sorted order:
```
auto permutation = indirect_sort(first, last);
for (size_t idx: permutation)
std::cout << first[idx] << std::endl;
```
Assume that instead of an "array of structures", you have a "struct of arrays".
```
struct AType {
Type0 key;
Type1 value1;
Type1 value2;
};
std::array<AType, 1000> arrayOfStruct;
```
versus:
```
template <size_t N>
struct AType {
std::array<Type0, N> key;
std::array<Type1, N> value1;
std::array<Type2, N> value2;
};
AType<1000> structOfArrays;
```
Sorting the first one is easy, because each set of fields (`key`, `value1`, `value2`) are part of the same struct. But with indirect sorting, the second one is easy to sort as well - just sort the keys, then apply the permutation to the keys and the values:
```
auto perm = indirect_sort(std::begin(structOfArrays.key), std::end(structOfArrays.key));
apply_permutation(structOfArrays.key.begin(), structOfArrays.key.end(), perm.begin(), perm.end());
apply_permutation(structOfArrays.value1.begin(), structOfArrays.value1.end(), perm.begin(), perm.end());
apply_permutation(structOfArrays.value2.begin(), structOfArrays.value2.end(), perm.begin(), perm.end());
```
[heading interface]
The function `indirect_sort` returns a `vector<size_t>` containing the permutation necessary to put the input sequence into a sorted order. One version uses `std::less` to do the comparisons; the other lets the caller pass predicate to do the comparisons.
There is also a variant called `indirect_stable_sort`; it bears the same relation to `indirect_sort` that `std::stable_sort` does to `std::sort`.
```
template <typename RAIterator>
std::vector<size_t> indirect_sort (RAIterator first, RAIterator last);
template <typename RAIterator, typename BinaryPredicate>
std::vector<size_t> indirect_sort (RAIterator first, RAIterator last, BinaryPredicate pred);
template <typename RAIterator>
std::vector<size_t> indirect_stable_sort (RAIterator first, RAIterator last);
template <typename RAIterator, typename BinaryPredicate>
std::vector<size_t> indirect_stable_sort (RAIterator first, RAIterator last, BinaryPredicate pred);
```
[heading Examples]
[heading Iterator Requirements]
`indirect_sort` requires random-access iterators.
[heading Complexity]
Both of the variants of `indirect_sort` run in ['O(N lg N)] time; they are not more (or less) efficient than `std::sort`. There is an extra layer of indirection on each comparison, but all of the swaps are done on values of type `size_t`
[heading Exception Safety]
[heading Notes]
In numpy, this algorithm is known as `argsort`.
[endsect]
[/ File indirect_sort.qbk
Copyright 2023 Marshall Clow
Distributed under the Boost Software License, Version 1.0.
(See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt).
]

View File

@ -20,7 +20,7 @@
#include <functional> // for plus and multiplies
#include <boost/config.hpp>
#include <boost/core/enable_if.hpp> // for boost::disable_if
#include <boost/utility/enable_if.hpp> // for boost::disable_if
#include <boost/type_traits/is_integral.hpp>
namespace boost { namespace algorithm {

View File

@ -27,7 +27,7 @@
#include <boost/range/begin.hpp>
#include <boost/range/end.hpp>
#include <boost/type_traits/type_identity.hpp> // for boost::type_identity
#include <boost/core/enable_if.hpp> // for boost::disable_if
#include <boost/utility/enable_if.hpp> // for boost::disable_if
namespace boost { namespace algorithm {

View File

@ -20,7 +20,7 @@
#include <boost/config.hpp>
#include <boost/range/begin.hpp>
#include <boost/range/end.hpp>
#include <boost/core/enable_if.hpp>
#include <boost/utility/enable_if.hpp>
#include <boost/type_traits/is_same.hpp>
namespace boost { namespace algorithm {

View File

@ -20,7 +20,7 @@
#include <boost/range/begin.hpp>
#include <boost/range/end.hpp>
#include <boost/core/enable_if.hpp>
#include <boost/utility/enable_if.hpp>
#include <boost/type_traits/is_same.hpp>
#include <boost/type_traits/type_identity.hpp> // for boost::type_identity

View File

@ -1,4 +1,4 @@
/*
/*
Copyright 2008 Adobe Systems Incorporated
Distributed under the Boost Software License, Version 1.0. (See accompanying
@ -84,7 +84,7 @@ namespace boost { namespace algorithm {
template <
typename BidirectionalIterator, // models BidirectionalIterator
typename Pred> // models UnaryPredicate
std::pair<BidirectionalIterator, BidirectionalIterator> gather
std::pair<BidirectionalIterator, BidirectionalIterator> gather
( BidirectionalIterator first, BidirectionalIterator last, BidirectionalIterator pivot, Pred pred )
{
// The first call partitions everything up to (but not including) the pivot element,
@ -106,11 +106,11 @@ template <
typename BidirectionalRange, //
typename Pred> // Pred models UnaryPredicate
std::pair<
typename boost::range_iterator<BidirectionalRange>::type,
typename boost::range_iterator<BidirectionalRange>::type>
typename boost::range_iterator<const BidirectionalRange>::type,
typename boost::range_iterator<const BidirectionalRange>::type>
gather (
BidirectionalRange &range,
typename boost::range_iterator<BidirectionalRange>::type pivot,
const BidirectionalRange &range,
typename boost::range_iterator<const BidirectionalRange>::type pivot,
Pred pred )
{
return boost::algorithm::gather ( boost::begin ( range ), boost::end ( range ), pivot, pred );

View File

@ -30,7 +30,7 @@
#include <boost/exception/info.hpp>
#include <boost/throw_exception.hpp>
#include <boost/core/enable_if.hpp>
#include <boost/utility/enable_if.hpp>
#include <boost/type_traits/is_integral.hpp>

View File

@ -1,207 +0,0 @@
/*
Copyright (c) Marshall Clow 2023.
Distributed under the Boost Software License, Version 1.0. (See accompanying
file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
*/
/// \file indirect_sort.hpp
/// \brief indirect sorting algorithms
/// \author Marshall Clow
///
#ifndef BOOST_ALGORITHM_INDIRECT_SORT
#define BOOST_ALGORITHM_INDIRECT_SORT
#include <algorithm> // for std::sort (and others)
#include <functional> // for std::less
#include <vector> // for std::vector
#include <boost/algorithm/cxx11/iota.hpp>
namespace boost { namespace algorithm {
typedef std::vector<size_t> Permutation;
namespace detail {
template <class Predicate, class Iter>
struct indirect_predicate {
indirect_predicate (Predicate pred, Iter iter)
: pred_(pred), iter_(iter) {}
bool operator ()(size_t a, size_t b) const {
return pred_(iter_[a], iter_[b]);
}
Predicate pred_;
Iter iter_;
};
// Initialize a permutation of size 'size'. [ 0, 1, 2, ... size-1 ]
// Note: it would be nice to use 'iota' here, but that call writes over
// existing elements - not append them. I don't want to initialize
// the elements of the permutation to zero, and then immediately
// overwrite them.
void init_permutation (Permutation &p, size_t size) {
p.reserve(size);
boost::algorithm::iota_n(
std::back_insert_iterator<Permutation>(p), size_t(0), size);
}
}
// ===== sort =====
/// \fn indirect_sort (RAIterator first, RAIterator last, Predicate pred)
/// \returns a permutation of the elements in the range [first, last)
/// such that when the permutation is applied to the sequence,
/// the result is ordered as if 'std::sort(first, last, pred)'
// was called on the sequence.
///
/// \param first The start of the input sequence
/// \param last The end of the input sequence
/// \param pred The predicate to compare elements with
///
template <typename RAIterator, typename Pred>
Permutation indirect_sort (RAIterator first, RAIterator last, Pred pred) {
Permutation ret;
detail::init_permutation(ret, std::distance(first, last));
std::sort(ret.begin(), ret.end(),
detail::indirect_predicate<Pred, RAIterator>(pred, first));
return ret;
}
/// \fn indirect_sort (RAIterator first, RAIterator last)
/// \returns a permutation of the elements in the range [first, last)
/// such that when the permutation is applied to the sequence,
/// the result is ordered as if 'std::sort(first, last)'
// was called on the sequence.
///
/// \param first The start of the input sequence
/// \param last The end of the input sequence
///
template <typename RAIterator>
Permutation indirect_sort (RAIterator first, RAIterator last) {
return indirect_sort(first, last,
std::less<typename std::iterator_traits<RAIterator>::value_type>());
}
// ===== stable_sort =====
/// \fn indirect_stable_sort (RAIterator first, RAIterator last, Predicate pred)
/// \returns a permutation of the elements in the range [first, last)
/// such that when the permutation is applied to the sequence,
/// the result is ordered as if 'std::stable_sort(first, last, pred)'
// was called on the sequence.
///
/// \param first The start of the input sequence
/// \param last The end of the input sequence
/// \param pred The predicate to compare elements with
///
template <typename RAIterator, typename Pred>
Permutation indirect_stable_sort (RAIterator first, RAIterator last, Pred pred) {
Permutation ret;
detail::init_permutation(ret, std::distance(first, last));
std::stable_sort(ret.begin(), ret.end(),
detail::indirect_predicate<Pred, RAIterator>(pred, first));
return ret;
}
/// \fn indirect_stable_sort (RAIterator first, RAIterator last)
/// \returns a permutation of the elements in the range [first, last)
/// such that when the permutation is applied to the sequence,
/// the result is ordered as if 'std::stable_sort(first, last)'
// was called on the sequence.
///
/// \param first The start of the input sequence
/// \param last The end of the input sequence
///
template <typename RAIterator>
Permutation indirect_stable_sort (RAIterator first, RAIterator last) {
return indirect_stable_sort(first, last,
std::less<typename std::iterator_traits<RAIterator>::value_type>());
}
// ===== partial_sort =====
/// \fn indirect_partial_sort (RAIterator first, RAIterator middle, RAIterator last, Predicate pred)
/// \returns a permutation of the elements in the range [first, last)
/// such that when the permutation is applied to the sequence,
/// the result is ordered as if 'std::partial_sort(first, middle, last, pred)'
// was called on the sequence.
///
/// \param first The start of the input sequence
/// \param middle The end of the range to be sorted
/// \param last The end of the input sequence
/// \param pred The predicate to compare elements with
///
template <typename RAIterator, typename Pred>
Permutation indirect_partial_sort (RAIterator first, RAIterator middle,
RAIterator last, Pred pred) {
Permutation ret;
detail::init_permutation(ret, std::distance(first, last));
std::partial_sort(ret.begin(), ret.begin() + std::distance(first, middle), ret.end(),
detail::indirect_predicate<Pred, RAIterator>(pred, first));
return ret;
}
/// \fn indirect_partial_sort (RAIterator first, RAIterator middle, RAIterator last)
/// \returns a permutation of the elements in the range [first, last)
/// such that when the permutation is applied to the sequence,
/// the result is ordered as if 'std::partial_sort(first, middle, last)'
// was called on the sequence.
///
/// \param first The start of the input sequence
/// \param middle The end of the range to be sorted
/// \param last The end of the input sequence
///
template <typename RAIterator>
Permutation indirect_partial_sort (RAIterator first, RAIterator middle, RAIterator last) {
return indirect_partial_sort(first, middle, last,
std::less<typename std::iterator_traits<RAIterator>::value_type>());
}
// ===== nth_element =====
/// \fn indirect_nth_element (RAIterator first, RAIterator nth, RAIterator last, Predicate p)
/// \returns a permutation of the elements in the range [first, last)
/// such that when the permutation is applied to the sequence,
/// the result is ordered as if 'std::nth_element(first, nth, last, p)'
// was called on the sequence.
///
/// \param first The start of the input sequence
/// \param nth The sort partition point in the input sequence
/// \param last The end of the input sequence
/// \param pred The predicate to compare elements with
///
template <typename RAIterator, typename Pred>
Permutation indirect_nth_element (RAIterator first, RAIterator nth,
RAIterator last, Pred pred) {
Permutation ret;
detail::init_permutation(ret, std::distance(first, last));
std::nth_element(ret.begin(), ret.begin() + std::distance(first, nth), ret.end(),
detail::indirect_predicate<Pred, RAIterator>(pred, first));
return ret;
}
/// \fn indirect_nth_element (RAIterator first, RAIterator nth, RAIterator last)
/// \returns a permutation of the elements in the range [first, last)
/// such that when the permutation is applied to the sequence,
/// the result is ordered as if 'std::nth_element(first, nth, last)'
// was called on the sequence.
///
/// \param first The start of the input sequence
/// \param nth The sort partition point in the input sequence
/// \param last The end of the input sequence
///
template <typename RAIterator>
Permutation indirect_nth_element (RAIterator first, RAIterator nth, RAIterator last) {
return indirect_nth_element(first, nth, last,
std::less<typename std::iterator_traits<RAIterator>::value_type>());
}
}}
#endif // BOOST_ALGORITHM_INDIRECT_SORT

View File

@ -113,7 +113,7 @@ bool is_palindrome(const R& range, Predicate p)
/// \note This function will return true for empty sequences and for palindromes.
/// For other sequences function will return false.
/// Complexity: O(N).
inline bool is_palindrome(const char* str)
bool is_palindrome(const char* str)
{
if(!str)
return true;

View File

@ -19,7 +19,7 @@
#include <boost/range/begin.hpp>
#include <boost/range/end.hpp>
#include <boost/core/enable_if.hpp>
#include <boost/utility/enable_if.hpp>
#include <boost/type_traits/is_same.hpp>
#include <boost/algorithm/searching/detail/bm_traits.hpp>

View File

@ -19,7 +19,7 @@
#include <boost/range/begin.hpp>
#include <boost/range/end.hpp>
#include <boost/core/enable_if.hpp>
#include <boost/utility/enable_if.hpp>
#include <boost/type_traits/is_same.hpp>
#include <boost/algorithm/searching/detail/bm_traits.hpp>

View File

@ -20,7 +20,7 @@
#include <boost/range/begin.hpp>
#include <boost/range/end.hpp>
#include <boost/core/enable_if.hpp>
#include <boost/utility/enable_if.hpp>
#include <boost/type_traits/is_same.hpp>
#include <boost/algorithm/searching/detail/debugging.hpp>

View File

@ -88,10 +88,6 @@ alias unit_test_framework
# Apply_permutation tests
[ run apply_permutation_test.cpp unit_test_framework : : : : apply_permutation_test ]
# Indirect_sort tests
[ run indirect_sort_test.cpp unit_test_framework : : : : indirect_sort_test ]
# Find tests
[ run find_not_test.cpp unit_test_framework : : : : find_not_test ]
[ run find_backward_test.cpp unit_test_framework : : : : find_backward_test ]

View File

@ -28,8 +28,8 @@
namespace ba = boost::algorithm;
// namespace ba = boost;
BOOST_CXX14_CONSTEXPR bool is_true ( int ) { return true; }
BOOST_CXX14_CONSTEXPR bool is_false ( int ) { return false; }
BOOST_CXX14_CONSTEXPR bool is_true ( int v ) { return true; }
BOOST_CXX14_CONSTEXPR bool is_false ( int v ) { return false; }
BOOST_CXX14_CONSTEXPR bool is_even ( int v ) { return v % 2 == 0; }
BOOST_CXX14_CONSTEXPR bool is_odd ( int v ) { return v % 2 == 1; }
BOOST_CXX14_CONSTEXPR bool is_zero ( int v ) { return v == 0; }

View File

@ -25,7 +25,7 @@ void test_short_input1 () {
std::string s;
try { ba::unhex ( std::string ( "A" ), std::back_inserter(s)); }
catch ( const std::exception & ) { return; }
catch ( const std::exception &ex ) { return; }
BOOST_TEST_MESSAGE ( "Failed to catch std::exception in test_short_input1" );
BOOST_CHECK ( false );
}
@ -34,7 +34,7 @@ void test_short_input2 () {
std::string s;
try { ba::unhex ( std::string ( "A" ), std::back_inserter(s)); }
catch ( const ba::hex_decode_error & ) { return; }
catch ( const ba::hex_decode_error &ex ) { return; }
BOOST_TEST_MESSAGE ( "Failed to catch ba::hex_decode_error in test_short_input2" );
BOOST_CHECK ( false );
}
@ -43,7 +43,7 @@ void test_short_input3 () {
std::string s;
try { ba::unhex ( std::string ( "A" ), std::back_inserter(s)); }
catch ( const ba::not_enough_input & ) { return; }
catch ( const ba::not_enough_input &ex ) { return; }
BOOST_TEST_MESSAGE ( "Failed to catch ba::not_enough_input in test_short_input3" );
BOOST_CHECK ( false );
}
@ -53,8 +53,8 @@ void test_short_input4 () {
std::string s;
try { ba::unhex ( std::string ( "A" ), std::back_inserter(s)); }
catch ( const ba::non_hex_input & ) { BOOST_CHECK ( false ); }
catch ( const ba::not_enough_input & ) { return; }
catch ( const ba::non_hex_input &ex ) { BOOST_CHECK ( false ); }
catch ( const ba::not_enough_input &ex ) { return; }
catch ( ... ) { BOOST_CHECK ( false ); }
BOOST_CHECK ( false );
}
@ -64,8 +64,8 @@ void test_short_input5 () {
std::string s;
try { ba::unhex ( "A", std::back_inserter(s)); }
catch ( const ba::non_hex_input & ) { BOOST_CHECK ( false ); }
catch ( const ba::not_enough_input & ) { return; }
catch ( const ba::non_hex_input &ex ) { BOOST_CHECK ( false ); }
catch ( const ba::not_enough_input &ex ) { return; }
catch ( ... ) { BOOST_CHECK ( false ); }
BOOST_CHECK ( false );
}
@ -125,8 +125,8 @@ void test_nonhex_input4 () {
std::string s;
try { ba::unhex ( "P1234FA1234", std::back_inserter(s)); }
catch ( const ba::not_enough_input & ) { BOOST_CHECK ( false ); }
catch ( const ba::non_hex_input & ) { return; }
catch ( const ba::not_enough_input &ex ) { BOOST_CHECK ( false ); }
catch ( const ba::non_hex_input &ex ) { return; }
catch ( ... ) { BOOST_CHECK ( false ); }
BOOST_CHECK ( false );
}

View File

@ -1,348 +0,0 @@
/*
Copyright (c) Marshall Clow 2023.
Distributed under the Boost Software License, Version 1.0. (See accompanying
file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
For more information, see http://www.boost.org
*/
#include <boost/config.hpp>
#include <boost/algorithm/indirect_sort.hpp>
#include <boost/algorithm/apply_permutation.hpp>
#include <boost/algorithm/cxx11/is_sorted.hpp>
#include <boost/algorithm/cxx11/all_of.hpp>
#define BOOST_TEST_MAIN
#include <boost/test/unit_test.hpp>
#include <iostream>
#include <string>
#include <vector>
#include <list>
using boost::algorithm::Permutation;
// A permutation of size N is a sequence of values in the range [0..N)
// such that no value appears more than once in the permutation.
bool is_a_permutation(Permutation p, size_t N) {
if (p.size() != N) return false;
// Sort the permutation, and ensure that each value appears exactly once.
std::sort(p.begin(), p.end());
for (size_t i = 0; i < N; ++i)
if (p[i] != i) return false;
return true;
}
template <typename Iter,
typename Comp = typename std::less<typename std::iterator_traits<Iter>::value_type> >
struct indirect_comp {
indirect_comp (Iter it, Comp c = Comp())
: iter_(it), comp_(c) {}
bool operator ()(size_t a, size_t b) const { return comp_(iter_[a], iter_[b]);}
Iter iter_;
Comp comp_;
};
//// =======================
//// ==== indirect_sort ====
//// =======================
template <typename Iter>
void test_one_sort(Iter first, Iter last) {
Permutation perm = boost::algorithm::indirect_sort(first, last);
BOOST_CHECK (is_a_permutation(perm, std::distance(first, last)));
BOOST_CHECK (boost::algorithm::is_sorted(perm.begin(), perm.end(), indirect_comp<Iter>(first)));
// Make a copy of the data, apply the permutation, and ensure that it is sorted.
typedef std::vector<typename std::iterator_traits<Iter>::value_type> Vector;
Vector v(first, last);
boost::algorithm::apply_permutation(v.begin(), v.end(), perm.begin(), perm.end());
BOOST_CHECK (boost::algorithm::is_sorted(v.begin(), v.end()));
}
template <typename Iter, typename Comp>
void test_one_sort(Iter first, Iter last, Comp comp) {
Permutation perm = boost::algorithm::indirect_sort(first, last, comp);
BOOST_CHECK (is_a_permutation(perm, std::distance(first, last)));
BOOST_CHECK (boost::algorithm::is_sorted(perm.begin(), perm.end(),
indirect_comp<Iter, Comp>(first, comp)));
// Make a copy of the data, apply the permutation, and ensure that it is sorted.
typedef std::vector<typename std::iterator_traits<Iter>::value_type> Vector;
Vector v(first, last);
boost::algorithm::apply_permutation(v.begin(), v.end(), perm.begin(), perm.end());
BOOST_CHECK (boost::algorithm::is_sorted(v.begin(), v.end(), comp));
}
BOOST_AUTO_TEST_CASE(test_sort) {
int num[] = { 1,3,5,7,9, 2, 4, 6, 8, 10 };
const int sz = sizeof (num)/sizeof(num[0]);
int *first = &num[0];
int const *cFirst = &num[0];
// Test subsets
for (size_t i = 0; i <= sz; ++i) {
test_one_sort(first, first + i);
test_one_sort(first, first + i, std::greater<int>());
// test with constant inputs
test_one_sort(cFirst, cFirst + i);
test_one_sort(cFirst, cFirst + i, std::greater<int>());
}
// make sure we work with iterators as well as pointers
std::vector<int> v(first, first + sz);
test_one_sort(v.begin(), v.end());
test_one_sort(v.begin(), v.end(), std::greater<int>());
}
//// ==============================
//// ==== indirect_stable_sort ====
//// ==============================
template <typename T1, typename T2>
struct MyPair {
MyPair () {}
MyPair (const T1 &t1, const T2 &t2)
: first(t1), second(t2) {}
T1 first;
T2 second;
};
template <typename T1, typename T2>
bool operator < (const MyPair<T1, T2>& lhs, const MyPair<T1, T2>& rhs) {
return lhs.first < rhs.first; // compare only the first elements
}
template <typename T1, typename T2>
bool MyGreater (const MyPair<T1, T2>& lhs, const MyPair<T1, T2>& rhs) {
return lhs.first > rhs.first; // compare only the first elements
}
template <typename Iter>
void test_one_stable_sort(Iter first, Iter last) {
Permutation perm = boost::algorithm::indirect_stable_sort(first, last);
BOOST_CHECK (is_a_permutation(perm, std::distance(first, last)));
BOOST_CHECK (boost::algorithm::is_sorted(perm.begin(), perm.end(), indirect_comp<Iter>(first)));
if (first != last) {
Iter iFirst = first;
Iter iSecond = first; ++iSecond;
while (iSecond != last) {
if (iFirst->first == iSecond->first)
BOOST_CHECK(iFirst->second < iSecond->second);
++iFirst;
++iSecond;
}
}
// Make a copy of the data, apply the permutation, and ensure that it is sorted.
typedef std::vector<typename std::iterator_traits<Iter>::value_type> Vector;
Vector v(first, last);
boost::algorithm::apply_permutation(v.begin(), v.end(), perm.begin(), perm.end());
BOOST_CHECK (boost::algorithm::is_sorted(v.begin(), v.end()));
}
template <typename Iter, typename Comp>
void test_one_stable_sort(Iter first, Iter last, Comp comp) {
Permutation perm = boost::algorithm::indirect_stable_sort(first, last, comp);
BOOST_CHECK (is_a_permutation(perm, std::distance(first, last)));
BOOST_CHECK (boost::algorithm::is_sorted(perm.begin(), perm.end(), indirect_comp<Iter, Comp>(first, comp)));
if (first != last) {
Iter iFirst = first;
Iter iSecond = first; ++iSecond;
while (iSecond != last) {
if (iFirst->first == iSecond->first)
BOOST_CHECK(iFirst->second < iSecond->second);
++iFirst;
++iSecond;
}
}
// Make a copy of the data, apply the permutation, and ensure that it is sorted.
typedef std::vector<typename std::iterator_traits<Iter>::value_type> Vector;
Vector v(first, last);
boost::algorithm::apply_permutation(v.begin(), v.end(), perm.begin(), perm.end());
BOOST_CHECK (boost::algorithm::is_sorted(v.begin(), v.end(), comp));
}
BOOST_AUTO_TEST_CASE(test_stable_sort) {
typedef MyPair<int, long> Pair;
const int sz = 10;
Pair vals[sz];
for (int i = 0; i < sz; ++i) {
vals[i].first = 100 - (i >> 1);
vals[i].second = i;
}
Pair *first = &vals[0];
Pair const *cFirst = &vals[0];
// Test subsets
for (size_t i = 0; i <= sz; ++i) {
test_one_stable_sort(first, first + i);
test_one_stable_sort(first, first + i, MyGreater<int, long>);
// test with constant inputs
test_one_sort(cFirst, cFirst + i);
test_one_sort(cFirst, cFirst + i, MyGreater<int, long>);
}
}
//// ===============================
//// ==== indirect_partial_sort ====
//// ===============================
template <typename Iter>
void test_one_partial_sort(Iter first, Iter middle, Iter last) {
const size_t middleIdx = std::distance(first, middle);
Permutation perm = boost::algorithm::indirect_partial_sort(first, middle, last);
BOOST_CHECK (is_a_permutation(perm, std::distance(first, last)));
BOOST_CHECK (boost::algorithm::is_sorted(perm.begin(), perm.begin() + middleIdx, indirect_comp<Iter>(first)));
// Make a copy of the data, apply the permutation, and ensure that it is sorted.
typedef std::vector<typename std::iterator_traits<Iter>::value_type> Vector;
Vector v(first, last);
boost::algorithm::apply_permutation(v.begin(), v.end(), perm.begin(), perm.end());
BOOST_CHECK (boost::algorithm::is_sorted(v.begin(), v.begin() + middleIdx));
// Make sure that [middle, end) are all "greater" than the sorted part
if (middleIdx > 0) {
typename Vector::iterator lastSorted = v.begin() + middleIdx - 1;
for (typename Vector::iterator it = v.begin () + middleIdx; it != v.end(); ++it)
BOOST_CHECK(*lastSorted < *it);
}
}
template <typename Iter, typename Comp>
void test_one_partial_sort(Iter first, Iter middle, Iter last, Comp comp) {
const size_t middleIdx = std::distance(first, middle);
Permutation perm = boost::algorithm::indirect_partial_sort(first, middle, last, comp);
BOOST_CHECK (is_a_permutation(perm, std::distance(first, last)));
BOOST_CHECK (boost::algorithm::is_sorted(perm.begin(), perm.begin() + middleIdx,
indirect_comp<Iter, Comp>(first, comp)));
// Make a copy of the data, apply the permutation, and ensure that it is sorted.
typedef std::vector<typename std::iterator_traits<Iter>::value_type> Vector;
Vector v(first, last);
boost::algorithm::apply_permutation(v.begin(), v.end(), perm.begin(), perm.end());
BOOST_CHECK (boost::algorithm::is_sorted(v.begin(), v.begin() + middleIdx, comp));
// Make sure that [middle, end) are all "greater" than the sorted part
if (middleIdx > 0) {
typename Vector::iterator lastSorted = v.begin() + middleIdx - 1;
for (typename Vector::iterator it = v.begin () + middleIdx; it != v.end(); ++it)
BOOST_CHECK(comp(*lastSorted, *it));
}
}
BOOST_AUTO_TEST_CASE(test_partial_sort) {
int num[] = { 1,3,5,7,9, 2, 4, 6, 8, 10 };
const int sz = sizeof (num)/sizeof(num[0]);
int *first = &num[0];
int const *cFirst = &num[0];
// Test subsets
for (size_t i = 0; i <= sz; ++i) {
for (size_t j = 0; j < i; ++j) {
test_one_partial_sort(first, first + j, first + i);
test_one_partial_sort(first, first + j, first + i, std::greater<int>());
// test with constant inputs
test_one_partial_sort(cFirst, cFirst + j, cFirst + i);
test_one_partial_sort(cFirst, cFirst + j, cFirst + i, std::greater<int>());
}
}
// make sure we work with iterators as well as pointers
std::vector<int> v(first, first + sz);
test_one_partial_sort(v.begin(), v.begin() + (sz / 2), v.end());
test_one_partial_sort(v.begin(), v.begin() + (sz / 2), v.end(), std::greater<int>());
}
//// ===================================
//// ==== indirect_nth_element_sort ====
//// ===================================
template <typename Iter>
void test_one_nth_element(Iter first, Iter nth, Iter last) {
const size_t nthIdx = std::distance(first, nth);
Permutation perm = boost::algorithm::indirect_nth_element(first, nth, last);
BOOST_CHECK (is_a_permutation(perm, std::distance(first, last)));
for (size_t i = 0; i < nthIdx; ++i)
BOOST_CHECK(!(first[perm[nthIdx]] < first[perm[i]])); // all items before the nth element are <= the nth element
for (size_t i = nthIdx; i < std::distance(first, last); ++i)
BOOST_CHECK(!(first[perm[i]] < first[perm[nthIdx]])); // all items before the nth element are >= the nth element
// Make a copy of the data, apply the permutation, and ensure that the result is correct.
typedef std::vector<typename std::iterator_traits<Iter>::value_type> Vector;
Vector v(first, last);
boost::algorithm::apply_permutation(v.begin(), v.end(), perm.begin(), perm.end());
for (size_t i = 0; i < nthIdx; ++i)
BOOST_CHECK(!(v[nthIdx] < v[i])); // all items before the nth element are <= the nth element
for (size_t i = nthIdx; i < v.size(); ++i)
BOOST_CHECK(!(v[i] < v[nthIdx])); // all items before the nth element are >= the nth element
}
template <typename Iter, typename Comp>
void test_one_nth_element(Iter first, Iter nth, Iter last, Comp comp) {
const size_t nthIdx = std::distance(first, nth);
Permutation perm = boost::algorithm::indirect_nth_element(first, nth, last, comp);
BOOST_CHECK (is_a_permutation(perm, std::distance(first, last)));
for (size_t i = 0; i < nthIdx; ++i)
BOOST_CHECK(!comp(first[perm[nthIdx]], first[perm[i]])); // all items before the nth element are <= the nth element
for (size_t i = nthIdx; i < std::distance(first, last); ++i)
BOOST_CHECK(!comp(first[perm[i]], first[perm[nthIdx]])); // all items before the nth element are >= the nth element
// Make a copy of the data, apply the permutation, and ensure that the result is correct.
typedef std::vector<typename std::iterator_traits<Iter>::value_type> Vector;
Vector v(first, last);
boost::algorithm::apply_permutation(v.begin(), v.end(), perm.begin(), perm.end());
for (size_t i = 0; i < nthIdx; ++i)
BOOST_CHECK(!comp(v[nthIdx], v[i])); // all items before the nth element are <= the nth element
for (size_t i = nthIdx; i < v.size(); ++i)
BOOST_CHECK(!comp(v[i], v[nthIdx])); // all items before the nth element are >= the nth element
}
BOOST_AUTO_TEST_CASE(test_nth_element) {
int num[] = { 1, 3, 5, 7, 9, 2, 4, 6, 8, 10, 1, 2, 3, 4, 5 };
const int sz = sizeof (num)/sizeof(num[0]);
int *first = &num[0];
int const *cFirst = &num[0];
// Test subsets
for (size_t i = 0; i <= sz; ++i) {
for (size_t j = 0; j < i; ++j) {
test_one_nth_element(first, first + j, first + i);
test_one_nth_element(first, first + j, first + i, std::greater<int>());
// test with constant inputs
test_one_nth_element(cFirst, cFirst + j, cFirst + i);
test_one_nth_element(cFirst, cFirst + j, cFirst + i, std::greater<int>());
}
}
// make sure we work with iterators as well as pointers
std::vector<int> v(first, first + sz);
test_one_nth_element(v.begin(), v.begin() + (sz / 2), v.end());
test_one_nth_element(v.begin(), v.begin() + (sz / 2), v.end(), std::greater<int>());
}

View File

@ -112,7 +112,7 @@ void test_sequence1 () {
std::vector<int> v, v1;
v.clear ();
for ( int i = 5; i < 15; ++i )
for ( std::size_t i = 5; i < 15; ++i )
v.push_back ( i );
v1 = v;
BOOST_CHECK ( ba::is_permutation ( v.begin (), v.end (), v.begin ())); // better be a permutation of itself!

View File

@ -32,7 +32,7 @@ namespace {
// Check using iterators
template<typename Container>
void check_one_iter ( const Container &haystack, const std::string &needle, std::ptrdiff_t expected ) {
void check_one_iter ( const Container &haystack, const std::string &needle, int expected ) {
typedef typename Container::const_iterator iter_type;
typedef typename std::pair<iter_type, iter_type> ret_type;
typedef std::string::const_iterator pattern_type;
@ -53,7 +53,7 @@ namespace {
// iter_type it1r = ret1r.first;
// iter_type it2 = ret2.first;
// iter_type it3 = ret3.first;
const std::ptrdiff_t dist = ret1.first == hEnd ? -1 : std::distance ( hBeg, ret1.first );
const int dist = ret1.first == hEnd ? -1 : std::distance ( hBeg, ret1.first );
std::cout << "(Iterators) Pattern is " << needle.length () << ", haysstack is " << haystack.length () << " chars long; " << std::endl;
try {
@ -97,7 +97,7 @@ namespace {
// Check using pointers
// We're assuming that the container implements contiguous storage here.
template<typename Container>
void check_one_pointer ( const Container &haystack, const std::string &needle, std::ptrdiff_t expected ) {
void check_one_pointer ( const Container &haystack, const std::string &needle, int expected ) {
typedef const typename Container::value_type *ptr_type;
typedef typename std::pair<ptr_type, ptr_type> ret_type;
@ -110,7 +110,7 @@ namespace {
ret_type ret1 = ba::boyer_moore_search (hBeg, hEnd, nBeg, nEnd);
ret_type ret2 = ba::boyer_moore_horspool_search (hBeg, hEnd, nBeg, nEnd);
ret_type ret3 = ba::knuth_morris_pratt_search (hBeg, hEnd, nBeg, nEnd);
const std::ptrdiff_t dist = ret1.first == hEnd ? -1 : std::distance ( hBeg, ret1.first );
const int dist = ret1.first == hEnd ? -1 : std::distance ( hBeg, ret1.first );
std::cout << "(Pointers) Pattern is " << needle.length () << ", haysstack is " << haystack.length () << " chars long; " << std::endl;
try {
@ -147,7 +147,7 @@ namespace {
// Check using objects
template<typename Container>
void check_one_object ( const Container &haystack, const std::string &needle, std::ptrdiff_t expected ) {
void check_one_object ( const Container &haystack, const std::string &needle, int expected ) {
typedef typename Container::const_iterator iter_type;
typedef typename std::pair<iter_type, iter_type> ret_type;
typedef std::string::const_iterator pattern_type;
@ -169,7 +169,7 @@ namespace {
ret_type retr1r = bm_r (haystack);
ret_type ret2 = bmh (hBeg, hEnd);
ret_type ret3 = kmp (hBeg, hEnd);
const std::ptrdiff_t dist = ret1.first == hEnd ? -1 : std::distance ( hBeg, ret1.first );
const int dist = ret1.first == hEnd ? -1 : std::distance ( hBeg, ret1.first );
std::cout << "(Objects) Pattern is " << needle.length () << ", haysstack is " << haystack.length () << " chars long; " << std::endl;
try {
@ -224,7 +224,7 @@ namespace {
template<typename Container>
void check_one ( const Container &haystack, const std::string &needle, std::ptrdiff_t expected ) {
void check_one ( const Container &haystack, const std::string &needle, int expected ) {
check_one_iter ( haystack, needle, expected );
check_one_pointer ( haystack, needle, expected );
check_one_object ( haystack, needle, expected );

View File

@ -85,7 +85,7 @@ namespace {
std::cout << std::endl;
}
void check_one ( const vec &haystack, const vec &needle, std::ptrdiff_t expected ) {
void check_one ( const vec &haystack, const vec &needle, int expected ) {
std::size_t i;
std::clock_t sTime;
unsigned long stdDiff;
@ -147,7 +147,7 @@ BOOST_AUTO_TEST_CASE( test_main )
std::cout << "---- Middle -----" << std::endl;
check_one ( c1, p1f, -2 ); // Don't know answer
std::cout << "------ End ------" << std::endl;
check_one ( c1, p1e, static_cast<std::ptrdiff_t>(c1.size() - p1e.size ()));
check_one ( c1, p1e, c1.size() - p1e.size ());
std::cout << "--- Not found ---" << std::endl;
check_one ( c1, p1n, -1 ); // Not found
}

View File

@ -85,7 +85,7 @@ namespace {
std::cout << std::endl;
}
void check_one ( const vec &haystack, const vec &needle, std::ptrdiff_t expected ) {
void check_one ( const vec &haystack, const vec &needle, int expected ) {
std::size_t i;
std::clock_t sTime;
unsigned long stdDiff;
@ -147,7 +147,7 @@ BOOST_AUTO_TEST_CASE( test_main )
std::cout << "---- Middle -----" << std::endl;
check_one ( c1, p1f, -2 ); // Don't know answer
std::cout << "------ End ------" << std::endl;
check_one ( c1, p1e, static_cast<std::ptrdiff_t>(c1.size() - p1e.size ()));
check_one ( c1, p1e, c1.size() - p1e.size ());
std::cout << "--- Not found ---" << std::endl;
check_one ( c1, p1n, -1 ); // Not found
}

View File

@ -62,7 +62,7 @@ namespace {
return retVal;
}
void check_one ( const vec &haystack, const vec &needle, std::ptrdiff_t expected ) {
void check_one ( const vec &haystack, const vec &needle, int expected ) {
std::pair<vec::const_iterator, vec::const_iterator> res;
std::pair<vec::const_iterator, vec::const_iterator> exp; // the expected result
@ -117,7 +117,7 @@ BOOST_AUTO_TEST_CASE( test_main )
std::cout << "---- Middle -----" << std::endl;
check_one ( c1, p1f, -2 ); // Don't know answer
std::cout << "------ End ------" << std::endl;
check_one ( c1, p1e, static_cast<std::ptrdiff_t>(c1.size() - p1e.size ()));
check_one ( c1, p1e, c1.size() - p1e.size ());
std::cout << "--- Not found ---" << std::endl;
check_one ( c1, p1n, -1 ); // Not found
}