Different fixes

This commit is contained in:
Alexander Zaitsev
2017-08-30 20:25:15 +03:00
parent 32016b3c79
commit 7df35ffd56
4 changed files with 50 additions and 35 deletions

View File

@ -12,8 +12,16 @@ Distributed under the Boost Software License, Version 1.0.
The header file 'apply_permutation.hpp' contains two algorithms, apply_permutation and apply_reverse_permutation. Also there are range-based versions.
The algorithms transform the item sequence according to index sequence order.
The routine `apply_permutation` takes a item sequence and a order sequence. It reshuffles item sequence according to order sequence. Every value in order sequence means where the item comes from.
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.
The routine `apply_permutation` takes a item sequence and a order sequence. It reshuffles item sequence according to order sequence. Every value in order sequence means where the item comes from. 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).
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://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.
@ -21,17 +29,17 @@ The routines come in 2 forms; the first one takes two iterators to define the it
[heading interface]
There are two versions of algorithms:
1) takes three iterators.
1) takes four iterators.
2) takes two ranges.
``
template<typename RandomAccessIterator1, typename RandomAccessIterator2>
void apply_permutation(RandomAccessIterator1 item_begin, RandomAccessIterator1 item_end,
RandomAccessIterator2 ind_begin);
RandomAccessIterator2 ind_begin, RandomAccessIterator2 ind_end);
template<typename Range1, typename Range2>
void apply_permutation(Range1& item_range, Range2& ind_range);
template<typename RandomAccessIterator1, typename RandomAccessIterator2>
void apply_reverse_permutation(RandomAccessIterator1 item_begin, RandomAccessIterator1 item_end,
RandomAccessIterator2 ind_begin);
RandomAccessIterator2 ind_begin, RandomAccessIterator2 ind_end);
template<typename Range1, typename Range2>
void apply_reverse_permutation(Range1& item_range, Range2& ind_range);
``
@ -64,6 +72,7 @@ apply_reverse_permutation(vec, order) --> vec:{5, 4, 2, 3, 1}
[heading Complexity]
All of the variants of `apply_permutation` and `apply_reverse_permutation` run in ['O(N)] (linear) time.
More
[heading Exception Safety]
@ -76,6 +85,8 @@ All of the variants of `apply_permutation` and `apply_reverse_permutation` take
* Order sequence must be zero-indexed.
* Order sequence gets permuted.
[endsect]
[/ File apply_permutation.qbk