update boost on linux
This commit is contained in:
@@ -261,6 +261,12 @@ BidirIt2 adl_move_swap_ranges_backward(BidirIt1 first1, BidirIt1 last1, BidirIt2
|
||||
return last2;
|
||||
}
|
||||
|
||||
template<class ForwardIt1, class ForwardIt2>
|
||||
void adl_move_iter_swap(ForwardIt1 a, ForwardIt2 b)
|
||||
{
|
||||
boost::adl_move_swap(*a, *b);
|
||||
}
|
||||
|
||||
} //namespace boost{
|
||||
|
||||
#endif //#ifndef BOOST_MOVE_ADL_MOVE_SWAP_HPP
|
||||
|
||||
@@ -18,6 +18,265 @@
|
||||
namespace boost {
|
||||
namespace movelib {
|
||||
|
||||
///@cond
|
||||
namespace detail_adaptive {
|
||||
|
||||
template<class RandIt, class Compare, class XBuf>
|
||||
inline void adaptive_merge_combine_blocks( RandIt first
|
||||
, typename iterator_traits<RandIt>::size_type len1
|
||||
, typename iterator_traits<RandIt>::size_type len2
|
||||
, typename iterator_traits<RandIt>::size_type collected
|
||||
, typename iterator_traits<RandIt>::size_type n_keys
|
||||
, typename iterator_traits<RandIt>::size_type l_block
|
||||
, bool use_internal_buf
|
||||
, bool xbuf_used
|
||||
, Compare comp
|
||||
, XBuf & xbuf
|
||||
)
|
||||
{
|
||||
typedef typename iterator_traits<RandIt>::size_type size_type;
|
||||
size_type const len = len1+len2;
|
||||
size_type const l_combine = len-collected;
|
||||
size_type const l_combine1 = len1-collected;
|
||||
|
||||
if(n_keys){
|
||||
RandIt const first_data = first+collected;
|
||||
RandIt const keys = first;
|
||||
BOOST_MOVE_ADAPTIVE_SORT_PRINT_L2(" A combine: ", len);
|
||||
if(xbuf_used){
|
||||
if(xbuf.size() < l_block){
|
||||
xbuf.initialize_until(l_block, *first);
|
||||
}
|
||||
BOOST_ASSERT(xbuf.size() >= l_block);
|
||||
size_type n_block_a, n_block_b, l_irreg1, l_irreg2;
|
||||
combine_params( keys, comp, l_combine
|
||||
, l_combine1, l_block, xbuf
|
||||
, n_block_a, n_block_b, l_irreg1, l_irreg2); //Outputs
|
||||
op_merge_blocks_with_buf
|
||||
(keys, comp, first_data, l_block, l_irreg1, n_block_a, n_block_b, l_irreg2, comp, move_op(), xbuf.data());
|
||||
BOOST_MOVE_ADAPTIVE_SORT_PRINT_L1(" A mrg xbf: ", len);
|
||||
}
|
||||
else{
|
||||
size_type n_block_a, n_block_b, l_irreg1, l_irreg2;
|
||||
combine_params( keys, comp, l_combine
|
||||
, l_combine1, l_block, xbuf
|
||||
, n_block_a, n_block_b, l_irreg1, l_irreg2); //Outputs
|
||||
if(use_internal_buf){
|
||||
op_merge_blocks_with_buf
|
||||
(keys, comp, first_data, l_block, l_irreg1, n_block_a, n_block_b, l_irreg2, comp, swap_op(), first_data-l_block);
|
||||
BOOST_MOVE_ADAPTIVE_SORT_PRINT_L2(" A mrg buf: ", len);
|
||||
}
|
||||
else{
|
||||
merge_blocks_bufferless
|
||||
(keys, comp, first_data, l_block, l_irreg1, n_block_a, n_block_b, l_irreg2, comp);
|
||||
BOOST_MOVE_ADAPTIVE_SORT_PRINT_L1(" A mrg nbf: ", len);
|
||||
}
|
||||
}
|
||||
}
|
||||
else{
|
||||
xbuf.shrink_to_fit(l_block);
|
||||
if(xbuf.size() < l_block){
|
||||
xbuf.initialize_until(l_block, *first);
|
||||
}
|
||||
size_type *const uint_keys = xbuf.template aligned_trailing<size_type>(l_block);
|
||||
size_type n_block_a, n_block_b, l_irreg1, l_irreg2;
|
||||
combine_params( uint_keys, less(), l_combine
|
||||
, l_combine1, l_block, xbuf
|
||||
, n_block_a, n_block_b, l_irreg1, l_irreg2, true); //Outputs
|
||||
BOOST_MOVE_ADAPTIVE_SORT_PRINT_L2(" A combine: ", len);
|
||||
BOOST_ASSERT(xbuf.size() >= l_block);
|
||||
op_merge_blocks_with_buf
|
||||
(uint_keys, less(), first, l_block, l_irreg1, n_block_a, n_block_b, l_irreg2, comp, move_op(), xbuf.data());
|
||||
xbuf.clear();
|
||||
BOOST_MOVE_ADAPTIVE_SORT_PRINT_L1(" A mrg buf: ", len);
|
||||
}
|
||||
}
|
||||
|
||||
template<class RandIt, class Compare, class XBuf>
|
||||
inline void adaptive_merge_final_merge( RandIt first
|
||||
, typename iterator_traits<RandIt>::size_type len1
|
||||
, typename iterator_traits<RandIt>::size_type len2
|
||||
, typename iterator_traits<RandIt>::size_type collected
|
||||
, typename iterator_traits<RandIt>::size_type l_intbuf
|
||||
, typename iterator_traits<RandIt>::size_type l_block
|
||||
, bool use_internal_buf
|
||||
, bool xbuf_used
|
||||
, Compare comp
|
||||
, XBuf & xbuf
|
||||
)
|
||||
{
|
||||
typedef typename iterator_traits<RandIt>::size_type size_type;
|
||||
(void)l_block;
|
||||
(void)use_internal_buf;
|
||||
size_type n_keys = collected-l_intbuf;
|
||||
size_type len = len1+len2;
|
||||
if (!xbuf_used || n_keys) {
|
||||
xbuf.clear();
|
||||
const size_type middle = xbuf_used && n_keys ? n_keys: collected;
|
||||
unstable_sort(first, first + middle, comp, xbuf);
|
||||
BOOST_MOVE_ADAPTIVE_SORT_PRINT_L2(" A k/b srt: ", len);
|
||||
stable_merge(first, first + middle, first + len, comp, xbuf);
|
||||
}
|
||||
BOOST_MOVE_ADAPTIVE_SORT_PRINT_L1(" A fin mrg: ", len);
|
||||
}
|
||||
|
||||
template<class SizeType>
|
||||
inline static SizeType adaptive_merge_n_keys_without_external_keys(SizeType l_block, SizeType len1, SizeType len2, SizeType l_intbuf)
|
||||
{
|
||||
typedef SizeType size_type;
|
||||
//This is the minimum number of keys to implement the ideal algorithm
|
||||
size_type n_keys = len1/l_block+len2/l_block;
|
||||
const size_type second_half_blocks = len2/l_block;
|
||||
const size_type first_half_aux = len1-l_intbuf;
|
||||
while(n_keys >= ((first_half_aux-n_keys)/l_block + second_half_blocks)){
|
||||
--n_keys;
|
||||
}
|
||||
++n_keys;
|
||||
return n_keys;
|
||||
}
|
||||
|
||||
template<class SizeType>
|
||||
inline static SizeType adaptive_merge_n_keys_with_external_keys(SizeType l_block, SizeType len1, SizeType len2, SizeType l_intbuf)
|
||||
{
|
||||
typedef SizeType size_type;
|
||||
//This is the minimum number of keys to implement the ideal algorithm
|
||||
size_type n_keys = (len1-l_intbuf)/l_block + len2/l_block;
|
||||
return n_keys;
|
||||
}
|
||||
|
||||
template<class SizeType, class Xbuf>
|
||||
inline SizeType adaptive_merge_n_keys_intbuf(SizeType &rl_block, SizeType len1, SizeType len2, Xbuf & xbuf, SizeType &l_intbuf_inout)
|
||||
{
|
||||
typedef SizeType size_type;
|
||||
size_type l_block = rl_block;
|
||||
size_type l_intbuf = xbuf.capacity() >= l_block ? 0u : l_block;
|
||||
|
||||
if (xbuf.capacity() > l_block){
|
||||
l_block = xbuf.capacity();
|
||||
}
|
||||
|
||||
//This is the minimum number of keys to implement the ideal algorithm
|
||||
size_type n_keys = adaptive_merge_n_keys_without_external_keys(l_block, len1, len2, l_intbuf);
|
||||
BOOST_ASSERT(n_keys >= ((len1-l_intbuf-n_keys)/l_block + len2/l_block));
|
||||
|
||||
if(xbuf.template supports_aligned_trailing<size_type>
|
||||
( l_block
|
||||
, adaptive_merge_n_keys_with_external_keys(l_block, len1, len2, l_intbuf)))
|
||||
{
|
||||
n_keys = 0u;
|
||||
}
|
||||
l_intbuf_inout = l_intbuf;
|
||||
rl_block = l_block;
|
||||
return n_keys;
|
||||
}
|
||||
|
||||
// Main explanation of the merge algorithm.
|
||||
//
|
||||
// csqrtlen = ceil(sqrt(len));
|
||||
//
|
||||
// * First, csqrtlen [to be used as buffer] + (len/csqrtlen - 1) [to be used as keys] => to_collect
|
||||
// unique elements are extracted from elements to be sorted and placed in the beginning of the range.
|
||||
//
|
||||
// * Step "combine_blocks": the leading (len1-to_collect) elements plus trailing len2 elements
|
||||
// are merged with a non-trivial ("smart") algorithm to form an ordered range trailing "len-to_collect" elements.
|
||||
//
|
||||
// Explanation of the "combine_blocks" step:
|
||||
//
|
||||
// * Trailing [first+to_collect, first+len1) elements are divided in groups of cqrtlen elements.
|
||||
// Remaining elements that can't form a group are grouped in front of those elements.
|
||||
// * Trailing [first+len1, first+len1+len2) elements are divided in groups of cqrtlen elements.
|
||||
// Remaining elements that can't form a group are grouped in the back of those elements.
|
||||
// * In parallel the following two steps are performed:
|
||||
// * Groups are selection-sorted by first or last element (depending whether they are going
|
||||
// to be merged to left or right) and keys are reordered accordingly as an imitation-buffer.
|
||||
// * Elements of each block pair are merged using the csqrtlen buffer taking into account
|
||||
// if they belong to the first half or second half (marked by the key).
|
||||
//
|
||||
// * In the final merge step leading "to_collect" elements are merged with rotations
|
||||
// with the rest of merged elements in the "combine_blocks" step.
|
||||
//
|
||||
// Corner cases:
|
||||
//
|
||||
// * If no "to_collect" elements can be extracted:
|
||||
//
|
||||
// * If more than a minimum number of elements is extracted
|
||||
// then reduces the number of elements used as buffer and keys in the
|
||||
// and "combine_blocks" steps. If "combine_blocks" has no enough keys due to this reduction
|
||||
// then uses a rotation based smart merge.
|
||||
//
|
||||
// * If the minimum number of keys can't be extracted, a rotation-based merge is performed.
|
||||
//
|
||||
// * If auxiliary memory is more or equal than min(len1, len2), a buffered merge is performed.
|
||||
//
|
||||
// * If the len1 or len2 are less than 2*csqrtlen then a rotation-based merge is performed.
|
||||
//
|
||||
// * If auxiliary memory is more than csqrtlen+n_keys*sizeof(std::size_t),
|
||||
// then no csqrtlen need to be extracted and "combine_blocks" will use integral
|
||||
// keys to combine blocks.
|
||||
template<class RandIt, class Compare, class XBuf>
|
||||
void adaptive_merge_impl
|
||||
( RandIt first
|
||||
, typename iterator_traits<RandIt>::size_type len1
|
||||
, typename iterator_traits<RandIt>::size_type len2
|
||||
, Compare comp
|
||||
, XBuf & xbuf
|
||||
)
|
||||
{
|
||||
typedef typename iterator_traits<RandIt>::size_type size_type;
|
||||
|
||||
if(xbuf.capacity() >= min_value<size_type>(len1, len2)){
|
||||
buffered_merge(first, first+len1, first+(len1+len2), comp, xbuf);
|
||||
}
|
||||
else{
|
||||
const size_type len = len1+len2;
|
||||
//Calculate ideal parameters and try to collect needed unique keys
|
||||
size_type l_block = size_type(ceil_sqrt(len));
|
||||
|
||||
//One range is not big enough to extract keys and the internal buffer so a
|
||||
//rotation-based based merge will do just fine
|
||||
if(len1 <= l_block*2 || len2 <= l_block*2){
|
||||
merge_bufferless(first, first+len1, first+len1+len2, comp);
|
||||
return;
|
||||
}
|
||||
|
||||
//Detail the number of keys and internal buffer. If xbuf has enough memory, no
|
||||
//internal buffer is needed so l_intbuf will remain 0.
|
||||
size_type l_intbuf = 0;
|
||||
size_type n_keys = adaptive_merge_n_keys_intbuf(l_block, len1, len2, xbuf, l_intbuf);
|
||||
size_type const to_collect = l_intbuf+n_keys;
|
||||
//Try to extract needed unique values from the first range
|
||||
size_type const collected = collect_unique(first, first+len1, to_collect, comp, xbuf);
|
||||
BOOST_MOVE_ADAPTIVE_SORT_PRINT_L1("\n A collect: ", len);
|
||||
|
||||
//Not the minimum number of keys is not available on the first range, so fallback to rotations
|
||||
if(collected != to_collect && collected < 4){
|
||||
merge_bufferless(first, first+collected, first+len1, comp);
|
||||
merge_bufferless(first, first + len1, first + len1 + len2, comp);
|
||||
return;
|
||||
}
|
||||
|
||||
//If not enough keys but more than minimum, adjust the internal buffer and key count
|
||||
bool use_internal_buf = collected == to_collect;
|
||||
if (!use_internal_buf){
|
||||
l_intbuf = 0u;
|
||||
n_keys = collected;
|
||||
l_block = lblock_for_combine(l_intbuf, n_keys, len, use_internal_buf);
|
||||
//If use_internal_buf is false, then then internal buffer will be zero and rotation-based combination will be used
|
||||
l_intbuf = use_internal_buf ? l_block : 0u;
|
||||
}
|
||||
|
||||
bool const xbuf_used = collected == to_collect && xbuf.capacity() >= l_block;
|
||||
//Merge trailing elements using smart merges
|
||||
adaptive_merge_combine_blocks(first, len1, len2, collected, n_keys, l_block, use_internal_buf, xbuf_used, comp, xbuf);
|
||||
//Merge buffer and keys with the rest of the values
|
||||
adaptive_merge_final_merge (first, len1, len2, collected, l_intbuf, l_block, use_internal_buf, xbuf_used, comp, xbuf);
|
||||
}
|
||||
}
|
||||
|
||||
} //namespace detail_adaptive {
|
||||
|
||||
///@endcond
|
||||
|
||||
//! <b>Effects</b>: Merges two consecutive sorted ranges [first, middle) and [middle, last)
|
||||
//! into one sorted range [first, last) according to the given comparison function comp.
|
||||
//! The algorithm is stable (if there are equivalent elements in the original two ranges,
|
||||
@@ -50,12 +309,38 @@ namespace movelib {
|
||||
template<class RandIt, class Compare>
|
||||
void adaptive_merge( RandIt first, RandIt middle, RandIt last, Compare comp
|
||||
, typename iterator_traits<RandIt>::value_type* uninitialized = 0
|
||||
, std::size_t uninitialized_len = 0)
|
||||
, typename iterator_traits<RandIt>::size_type uninitialized_len = 0)
|
||||
{
|
||||
typedef typename iterator_traits<RandIt>::size_type size_type;
|
||||
typedef typename iterator_traits<RandIt>::value_type value_type;
|
||||
|
||||
::boost::movelib::detail_adaptive::adaptive_xbuf<value_type> xbuf(uninitialized, uninitialized_len);
|
||||
if (first == middle || middle == last){
|
||||
return;
|
||||
}
|
||||
|
||||
//Reduce ranges to merge if possible
|
||||
do {
|
||||
if (comp(*middle, *first)){
|
||||
break;
|
||||
}
|
||||
++first;
|
||||
if (first == middle)
|
||||
return;
|
||||
} while(1);
|
||||
|
||||
RandIt first_high(middle);
|
||||
--first_high;
|
||||
do {
|
||||
--last;
|
||||
if (comp(*last, *first_high)){
|
||||
++last;
|
||||
break;
|
||||
}
|
||||
if (last == middle)
|
||||
return;
|
||||
} while(1);
|
||||
|
||||
::boost::movelib::adaptive_xbuf<value_type, value_type*, size_type> xbuf(uninitialized, size_type(uninitialized_len));
|
||||
::boost::movelib::detail_adaptive::adaptive_merge_impl(first, size_type(middle - first), size_type(last - middle), comp, xbuf);
|
||||
}
|
||||
|
||||
|
||||
@@ -18,6 +18,567 @@
|
||||
namespace boost {
|
||||
namespace movelib {
|
||||
|
||||
///@cond
|
||||
namespace detail_adaptive {
|
||||
|
||||
template<class RandIt>
|
||||
void move_data_backward( RandIt cur_pos
|
||||
, typename iterator_traits<RandIt>::size_type const l_data
|
||||
, RandIt new_pos
|
||||
, bool const xbuf_used)
|
||||
{
|
||||
//Move buffer to the total combination right
|
||||
if(xbuf_used){
|
||||
boost::move_backward(cur_pos, cur_pos+l_data, new_pos+l_data);
|
||||
}
|
||||
else{
|
||||
boost::adl_move_swap_ranges_backward(cur_pos, cur_pos+l_data, new_pos+l_data);
|
||||
//Rotate does less moves but it seems slower due to cache issues
|
||||
//rotate_gcd(first-l_block, first+len-l_block, first+len);
|
||||
}
|
||||
}
|
||||
|
||||
template<class RandIt>
|
||||
void move_data_forward( RandIt cur_pos
|
||||
, typename iterator_traits<RandIt>::size_type const l_data
|
||||
, RandIt new_pos
|
||||
, bool const xbuf_used)
|
||||
{
|
||||
//Move buffer to the total combination right
|
||||
if(xbuf_used){
|
||||
boost::move(cur_pos, cur_pos+l_data, new_pos);
|
||||
}
|
||||
else{
|
||||
boost::adl_move_swap_ranges(cur_pos, cur_pos+l_data, new_pos);
|
||||
//Rotate does less moves but it seems slower due to cache issues
|
||||
//rotate_gcd(first-l_block, first+len-l_block, first+len);
|
||||
}
|
||||
}
|
||||
|
||||
// build blocks of length 2*l_build_buf. l_build_buf is power of two
|
||||
// input: [0, l_build_buf) elements are buffer, rest unsorted elements
|
||||
// output: [0, l_build_buf) elements are buffer, blocks 2*l_build_buf and last subblock sorted
|
||||
//
|
||||
// First elements are merged from right to left until elements start
|
||||
// at first. All old elements [first, first + l_build_buf) are placed at the end
|
||||
// [first+len-l_build_buf, first+len). To achieve this:
|
||||
// - If we have external memory to merge, we save elements from the buffer
|
||||
// so that a non-swapping merge is used. Buffer elements are restored
|
||||
// at the end of the buffer from the external memory.
|
||||
//
|
||||
// - When the external memory is not available or it is insufficient
|
||||
// for a merge operation, left swap merging is used.
|
||||
//
|
||||
// Once elements are merged left to right in blocks of l_build_buf, then a single left
|
||||
// to right merge step is performed to achieve merged blocks of size 2K.
|
||||
// If external memory is available, usual merge is used, swap merging otherwise.
|
||||
//
|
||||
// As a last step, if auxiliary memory is available in-place merge is performed.
|
||||
// until all is merged or auxiliary memory is not large enough.
|
||||
template<class RandIt, class Compare, class XBuf>
|
||||
typename iterator_traits<RandIt>::size_type
|
||||
adaptive_sort_build_blocks
|
||||
( RandIt const first
|
||||
, typename iterator_traits<RandIt>::size_type const len
|
||||
, typename iterator_traits<RandIt>::size_type const l_base
|
||||
, typename iterator_traits<RandIt>::size_type const l_build_buf
|
||||
, XBuf & xbuf
|
||||
, Compare comp)
|
||||
{
|
||||
typedef typename iterator_traits<RandIt>::size_type size_type;
|
||||
BOOST_ASSERT(l_build_buf <= len);
|
||||
BOOST_ASSERT(0 == ((l_build_buf / l_base)&(l_build_buf/l_base-1)));
|
||||
|
||||
//Place the start pointer after the buffer
|
||||
RandIt first_block = first + l_build_buf;
|
||||
size_type const elements_in_blocks = len - l_build_buf;
|
||||
|
||||
//////////////////////////////////
|
||||
// Start of merge to left step
|
||||
//////////////////////////////////
|
||||
size_type l_merged = 0u;
|
||||
|
||||
BOOST_ASSERT(l_build_buf);
|
||||
//If there is no enough buffer for the insertion sort step, just avoid the external buffer
|
||||
size_type kbuf = min_value<size_type>(l_build_buf, size_type(xbuf.capacity()));
|
||||
kbuf = kbuf < l_base ? 0 : kbuf;
|
||||
|
||||
if(kbuf){
|
||||
//Backup internal buffer values in external buffer so they can be overwritten
|
||||
xbuf.move_assign(first+l_build_buf-kbuf, kbuf);
|
||||
l_merged = op_insertion_sort_step_left(first_block, elements_in_blocks, l_base, comp, move_op());
|
||||
|
||||
//Now combine them using the buffer. Elements from buffer can be
|
||||
//overwritten since they've been saved to xbuf
|
||||
l_merged = op_merge_left_step_multiple
|
||||
( first_block - l_merged, elements_in_blocks, l_merged, l_build_buf, kbuf - l_merged, comp, move_op());
|
||||
|
||||
//Restore internal buffer from external buffer unless kbuf was l_build_buf,
|
||||
//in that case restoration will happen later
|
||||
if(kbuf != l_build_buf){
|
||||
boost::move(xbuf.data()+kbuf-l_merged, xbuf.data() + kbuf, first_block-l_merged+elements_in_blocks);
|
||||
}
|
||||
}
|
||||
else{
|
||||
l_merged = insertion_sort_step(first_block, elements_in_blocks, l_base, comp);
|
||||
rotate_gcd(first_block - l_merged, first_block, first_block+elements_in_blocks);
|
||||
}
|
||||
|
||||
//Now combine elements using the buffer. Elements from buffer can't be
|
||||
//overwritten since xbuf was not big enough, so merge swapping elements.
|
||||
l_merged = op_merge_left_step_multiple
|
||||
(first_block - l_merged, elements_in_blocks, l_merged, l_build_buf, l_build_buf - l_merged, comp, swap_op());
|
||||
|
||||
BOOST_ASSERT(l_merged == l_build_buf);
|
||||
|
||||
//////////////////////////////////
|
||||
// Start of merge to right step
|
||||
//////////////////////////////////
|
||||
|
||||
//If kbuf is l_build_buf then we can merge right without swapping
|
||||
//Saved data is still in xbuf
|
||||
if(kbuf && kbuf == l_build_buf){
|
||||
op_merge_right_step_once(first, elements_in_blocks, l_build_buf, comp, move_op());
|
||||
//Restore internal buffer from external buffer if kbuf was l_build_buf.
|
||||
//as this operation was previously delayed.
|
||||
boost::move(xbuf.data(), xbuf.data() + kbuf, first);
|
||||
}
|
||||
else{
|
||||
op_merge_right_step_once(first, elements_in_blocks, l_build_buf, comp, swap_op());
|
||||
}
|
||||
xbuf.clear();
|
||||
//2*l_build_buf or total already merged
|
||||
return min_value<size_type>(elements_in_blocks, 2*l_build_buf);
|
||||
}
|
||||
|
||||
template<class RandItKeys, class KeyCompare, class RandIt, class Compare, class XBuf>
|
||||
void adaptive_sort_combine_blocks
|
||||
( RandItKeys const keys
|
||||
, KeyCompare key_comp
|
||||
, RandIt const first
|
||||
, typename iterator_traits<RandIt>::size_type const len
|
||||
, typename iterator_traits<RandIt>::size_type const l_prev_merged
|
||||
, typename iterator_traits<RandIt>::size_type const l_block
|
||||
, bool const use_buf
|
||||
, bool const xbuf_used
|
||||
, XBuf & xbuf
|
||||
, Compare comp
|
||||
, bool merge_left)
|
||||
{
|
||||
(void)xbuf;
|
||||
typedef typename iterator_traits<RandIt>::size_type size_type;
|
||||
|
||||
size_type const l_reg_combined = 2*l_prev_merged;
|
||||
size_type l_irreg_combined = 0;
|
||||
size_type const l_total_combined = calculate_total_combined(len, l_prev_merged, &l_irreg_combined);
|
||||
size_type const n_reg_combined = len/l_reg_combined;
|
||||
RandIt combined_first = first;
|
||||
|
||||
(void)l_total_combined;
|
||||
BOOST_ASSERT(l_total_combined <= len);
|
||||
|
||||
size_type const max_i = n_reg_combined + (l_irreg_combined != 0);
|
||||
|
||||
if(merge_left || !use_buf) {
|
||||
for( size_type combined_i = 0; combined_i != max_i; ++combined_i, combined_first += l_reg_combined) {
|
||||
//Now merge blocks
|
||||
bool const is_last = combined_i==n_reg_combined;
|
||||
size_type const l_cur_combined = is_last ? l_irreg_combined : l_reg_combined;
|
||||
|
||||
range_xbuf<RandIt, size_type, move_op> rbuf( (use_buf && xbuf_used) ? (combined_first-l_block) : combined_first, combined_first);
|
||||
size_type n_block_a, n_block_b, l_irreg1, l_irreg2;
|
||||
combine_params( keys, key_comp, l_cur_combined
|
||||
, l_prev_merged, l_block, rbuf
|
||||
, n_block_a, n_block_b, l_irreg1, l_irreg2); //Outputs
|
||||
BOOST_MOVE_ADAPTIVE_SORT_PRINT_L2(" A combpar: ", len + l_block);
|
||||
BOOST_MOVE_ADAPTIVE_SORT_INVARIANT(boost::movelib::is_sorted(combined_first, combined_first + n_block_a*l_block+l_irreg1, comp));
|
||||
BOOST_MOVE_ADAPTIVE_SORT_INVARIANT(boost::movelib::is_sorted(combined_first + n_block_a*l_block+l_irreg1, combined_first + n_block_a*l_block+l_irreg1+n_block_b*l_block+l_irreg2, comp));
|
||||
if(!use_buf){
|
||||
merge_blocks_bufferless
|
||||
(keys, key_comp, combined_first, l_block, 0u, n_block_a, n_block_b, l_irreg2, comp);
|
||||
}
|
||||
else{
|
||||
merge_blocks_left
|
||||
(keys, key_comp, combined_first, l_block, 0u, n_block_a, n_block_b, l_irreg2, comp, xbuf_used);
|
||||
}
|
||||
BOOST_MOVE_ADAPTIVE_SORT_PRINT_L2(" After merge_blocks_L: ", len + l_block);
|
||||
}
|
||||
}
|
||||
else{
|
||||
combined_first += l_reg_combined*(max_i-1);
|
||||
for( size_type combined_i = max_i; combined_i--; combined_first -= l_reg_combined) {
|
||||
bool const is_last = combined_i==n_reg_combined;
|
||||
size_type const l_cur_combined = is_last ? l_irreg_combined : l_reg_combined;
|
||||
|
||||
RandIt const combined_last(combined_first+l_cur_combined);
|
||||
range_xbuf<RandIt, size_type, move_op> rbuf(combined_last, xbuf_used ? (combined_last+l_block) : combined_last);
|
||||
size_type n_block_a, n_block_b, l_irreg1, l_irreg2;
|
||||
combine_params( keys, key_comp, l_cur_combined
|
||||
, l_prev_merged, l_block, rbuf
|
||||
, n_block_a, n_block_b, l_irreg1, l_irreg2); //Outputs
|
||||
BOOST_MOVE_ADAPTIVE_SORT_PRINT_L2(" A combpar: ", len + l_block);
|
||||
BOOST_MOVE_ADAPTIVE_SORT_INVARIANT(boost::movelib::is_sorted(combined_first, combined_first + n_block_a*l_block+l_irreg1, comp));
|
||||
BOOST_MOVE_ADAPTIVE_SORT_INVARIANT(boost::movelib::is_sorted(combined_first + n_block_a*l_block+l_irreg1, combined_first + n_block_a*l_block+l_irreg1+n_block_b*l_block+l_irreg2, comp));
|
||||
merge_blocks_right
|
||||
(keys, key_comp, combined_first, l_block, n_block_a, n_block_b, l_irreg2, comp, xbuf_used);
|
||||
BOOST_MOVE_ADAPTIVE_SORT_PRINT_L2(" After merge_blocks_R: ", len + l_block);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//Returns true if buffer is placed in
|
||||
//[buffer+len-l_intbuf, buffer+len). Otherwise, buffer is
|
||||
//[buffer,buffer+l_intbuf)
|
||||
template<class RandIt, class Compare, class XBuf>
|
||||
bool adaptive_sort_combine_all_blocks
|
||||
( RandIt keys
|
||||
, typename iterator_traits<RandIt>::size_type &n_keys
|
||||
, RandIt const buffer
|
||||
, typename iterator_traits<RandIt>::size_type const l_buf_plus_data
|
||||
, typename iterator_traits<RandIt>::size_type l_merged
|
||||
, typename iterator_traits<RandIt>::size_type &l_intbuf
|
||||
, XBuf & xbuf
|
||||
, Compare comp)
|
||||
{
|
||||
typedef typename iterator_traits<RandIt>::size_type size_type;
|
||||
RandIt const first = buffer + l_intbuf;
|
||||
size_type const l_data = l_buf_plus_data - l_intbuf;
|
||||
size_type const l_unique = l_intbuf+n_keys;
|
||||
//Backup data to external buffer once if possible
|
||||
bool const common_xbuf = l_data > l_merged && l_intbuf && l_intbuf <= xbuf.capacity();
|
||||
if(common_xbuf){
|
||||
xbuf.move_assign(buffer, l_intbuf);
|
||||
}
|
||||
|
||||
bool prev_merge_left = true;
|
||||
size_type l_prev_total_combined = l_merged, l_prev_block = 0;
|
||||
bool prev_use_internal_buf = true;
|
||||
|
||||
for( size_type n = 0; l_data > l_merged
|
||||
; l_merged*=2
|
||||
, ++n){
|
||||
//If l_intbuf is non-zero, use that internal buffer.
|
||||
// Implies l_block == l_intbuf && use_internal_buf == true
|
||||
//If l_intbuf is zero, see if half keys can be reused as a reduced emergency buffer,
|
||||
// Implies l_block == n_keys/2 && use_internal_buf == true
|
||||
//Otherwise, just give up and and use all keys to merge using rotations (use_internal_buf = false)
|
||||
bool use_internal_buf = false;
|
||||
size_type const l_block = lblock_for_combine(l_intbuf, n_keys, size_type(2*l_merged), use_internal_buf);
|
||||
BOOST_ASSERT(!l_intbuf || (l_block == l_intbuf));
|
||||
BOOST_ASSERT(n == 0 || (!use_internal_buf || prev_use_internal_buf) );
|
||||
BOOST_ASSERT(n == 0 || (!use_internal_buf || l_prev_block == l_block) );
|
||||
|
||||
bool const is_merge_left = (n&1) == 0;
|
||||
size_type const l_total_combined = calculate_total_combined(l_data, l_merged);
|
||||
if(n && prev_use_internal_buf && prev_merge_left){
|
||||
if(is_merge_left || !use_internal_buf){
|
||||
move_data_backward(first-l_prev_block, l_prev_total_combined, first, common_xbuf);
|
||||
}
|
||||
else{
|
||||
//Put the buffer just after l_total_combined
|
||||
RandIt const buf_end = first+l_prev_total_combined;
|
||||
RandIt const buf_beg = buf_end-l_block;
|
||||
if(l_prev_total_combined > l_total_combined){
|
||||
size_type const l_diff = l_prev_total_combined - l_total_combined;
|
||||
move_data_backward(buf_beg-l_diff, l_diff, buf_end-l_diff, common_xbuf);
|
||||
}
|
||||
else if(l_prev_total_combined < l_total_combined){
|
||||
size_type const l_diff = l_total_combined - l_prev_total_combined;
|
||||
move_data_forward(buf_end, l_diff, buf_beg, common_xbuf);
|
||||
}
|
||||
}
|
||||
BOOST_MOVE_ADAPTIVE_SORT_PRINT_L2(" After move_data : ", l_data + l_intbuf);
|
||||
}
|
||||
|
||||
//Combine to form l_merged*2 segments
|
||||
if(n_keys){
|
||||
size_type upper_n_keys_this_iter = 2*l_merged/l_block;
|
||||
if(upper_n_keys_this_iter > 256){
|
||||
adaptive_sort_combine_blocks
|
||||
( keys, comp, !use_internal_buf || is_merge_left ? first : first-l_block
|
||||
, l_data, l_merged, l_block, use_internal_buf, common_xbuf, xbuf, comp, is_merge_left);
|
||||
}
|
||||
else{
|
||||
unsigned char uint_keys[256];
|
||||
adaptive_sort_combine_blocks
|
||||
( uint_keys, less(), !use_internal_buf || is_merge_left ? first : first-l_block
|
||||
, l_data, l_merged, l_block, use_internal_buf, common_xbuf, xbuf, comp, is_merge_left);
|
||||
}
|
||||
}
|
||||
else{
|
||||
size_type *const uint_keys = xbuf.template aligned_trailing<size_type>();
|
||||
adaptive_sort_combine_blocks
|
||||
( uint_keys, less(), !use_internal_buf || is_merge_left ? first : first-l_block
|
||||
, l_data, l_merged, l_block, use_internal_buf, common_xbuf, xbuf, comp, is_merge_left);
|
||||
}
|
||||
|
||||
BOOST_MOVE_ADAPTIVE_SORT_PRINT_L1(is_merge_left ? " After comb blocks L: " : " After comb blocks R: ", l_data + l_intbuf);
|
||||
prev_merge_left = is_merge_left;
|
||||
l_prev_total_combined = l_total_combined;
|
||||
l_prev_block = l_block;
|
||||
prev_use_internal_buf = use_internal_buf;
|
||||
}
|
||||
BOOST_ASSERT(l_prev_total_combined == l_data);
|
||||
bool const buffer_right = prev_use_internal_buf && prev_merge_left;
|
||||
|
||||
l_intbuf = prev_use_internal_buf ? l_prev_block : 0u;
|
||||
n_keys = l_unique - l_intbuf;
|
||||
//Restore data from to external common buffer if used
|
||||
if(common_xbuf){
|
||||
if(buffer_right){
|
||||
boost::move(xbuf.data(), xbuf.data() + l_intbuf, buffer+l_data);
|
||||
}
|
||||
else{
|
||||
boost::move(xbuf.data(), xbuf.data() + l_intbuf, buffer);
|
||||
}
|
||||
}
|
||||
return buffer_right;
|
||||
}
|
||||
|
||||
|
||||
template<class RandIt, class Compare, class XBuf>
|
||||
void adaptive_sort_final_merge( bool buffer_right
|
||||
, RandIt const first
|
||||
, typename iterator_traits<RandIt>::size_type const l_intbuf
|
||||
, typename iterator_traits<RandIt>::size_type const n_keys
|
||||
, typename iterator_traits<RandIt>::size_type const len
|
||||
, XBuf & xbuf
|
||||
, Compare comp)
|
||||
{
|
||||
//BOOST_ASSERT(n_keys || xbuf.size() == l_intbuf);
|
||||
xbuf.clear();
|
||||
|
||||
typedef typename iterator_traits<RandIt>::size_type size_type;
|
||||
size_type const n_key_plus_buf = l_intbuf+n_keys;
|
||||
if(buffer_right){
|
||||
//Use stable sort as some buffer elements might not be unique (see non_unique_buf)
|
||||
stable_sort(first+len-l_intbuf, first+len, comp, xbuf);
|
||||
stable_merge(first+n_keys, first+len-l_intbuf, first+len, antistable<Compare>(comp), xbuf);
|
||||
unstable_sort(first, first+n_keys, comp, xbuf);
|
||||
stable_merge(first, first+n_keys, first+len, comp, xbuf);
|
||||
}
|
||||
else{
|
||||
//Use stable sort as some buffer elements might not be unique (see non_unique_buf)
|
||||
stable_sort(first, first+n_key_plus_buf, comp, xbuf);
|
||||
if(xbuf.capacity() >= n_key_plus_buf){
|
||||
buffered_merge(first, first+n_key_plus_buf, first+len, comp, xbuf);
|
||||
}
|
||||
else if(xbuf.capacity() >= min_value<size_type>(l_intbuf, n_keys)){
|
||||
stable_merge(first+n_keys, first+n_key_plus_buf, first+len, comp, xbuf);
|
||||
stable_merge(first, first+n_keys, first+len, comp, xbuf);
|
||||
}
|
||||
else{
|
||||
stable_merge(first, first+n_key_plus_buf, first+len, comp, xbuf);
|
||||
}
|
||||
}
|
||||
BOOST_MOVE_ADAPTIVE_SORT_PRINT_L1(" After final_merge : ", len);
|
||||
}
|
||||
|
||||
template<class RandIt, class Compare, class Unsigned, class XBuf>
|
||||
bool adaptive_sort_build_params
|
||||
(RandIt first, Unsigned const len, Compare comp
|
||||
, Unsigned &n_keys, Unsigned &l_intbuf, Unsigned &l_base, Unsigned &l_build_buf
|
||||
, XBuf & xbuf
|
||||
)
|
||||
{
|
||||
typedef Unsigned size_type;
|
||||
|
||||
//Calculate ideal parameters and try to collect needed unique keys
|
||||
l_base = 0u;
|
||||
|
||||
//Try to find a value near sqrt(len) that is 2^N*l_base where
|
||||
//l_base <= AdaptiveSortInsertionSortThreshold. This property is important
|
||||
//as build_blocks merges to the left iteratively duplicating the
|
||||
//merged size and all the buffer must be used just before the final
|
||||
//merge to right step. This guarantees "build_blocks" produces
|
||||
//segments of size l_build_buf*2, maximizing the classic merge phase.
|
||||
l_intbuf = size_type(ceil_sqrt_multiple(len, &l_base));
|
||||
|
||||
//The internal buffer can be expanded if there is enough external memory
|
||||
while(xbuf.capacity() >= l_intbuf*2){
|
||||
l_intbuf *= 2;
|
||||
}
|
||||
|
||||
//This is the minimum number of keys to implement the ideal algorithm
|
||||
//
|
||||
//l_intbuf is used as buffer plus the key count
|
||||
size_type n_min_ideal_keys = l_intbuf-1;
|
||||
while(n_min_ideal_keys >= (len-l_intbuf-n_min_ideal_keys)/l_intbuf){
|
||||
--n_min_ideal_keys;
|
||||
}
|
||||
n_min_ideal_keys += 1;
|
||||
BOOST_ASSERT(n_min_ideal_keys <= l_intbuf);
|
||||
|
||||
if(xbuf.template supports_aligned_trailing<size_type>(l_intbuf, (len-l_intbuf-1)/l_intbuf+1)){
|
||||
n_keys = 0u;
|
||||
l_build_buf = l_intbuf;
|
||||
}
|
||||
else{
|
||||
//Try to achieve a l_build_buf of length l_intbuf*2, so that we can merge with that
|
||||
//l_intbuf*2 buffer in "build_blocks" and use half of them as buffer and the other half
|
||||
//as keys in combine_all_blocks. In that case n_keys >= n_min_ideal_keys but by a small margin.
|
||||
//
|
||||
//If available memory is 2*sqrt(l), then only sqrt(l) unique keys are needed,
|
||||
//(to be used for keys in combine_all_blocks) as the whole l_build_buf
|
||||
//will be backuped in the buffer during build_blocks.
|
||||
bool const non_unique_buf = xbuf.capacity() >= l_intbuf;
|
||||
size_type const to_collect = non_unique_buf ? n_min_ideal_keys : l_intbuf*2;
|
||||
size_type collected = collect_unique(first, first+len, to_collect, comp, xbuf);
|
||||
|
||||
//If available memory is 2*sqrt(l), then for "build_params"
|
||||
//the situation is the same as if 2*l_intbuf were collected.
|
||||
if(non_unique_buf && collected == n_min_ideal_keys){
|
||||
l_build_buf = l_intbuf;
|
||||
n_keys = n_min_ideal_keys;
|
||||
}
|
||||
else if(collected == 2*l_intbuf){
|
||||
//l_intbuf*2 elements found. Use all of them in the build phase
|
||||
l_build_buf = l_intbuf*2;
|
||||
n_keys = l_intbuf;
|
||||
}
|
||||
else if(collected == (n_min_ideal_keys+l_intbuf)){
|
||||
l_build_buf = l_intbuf;
|
||||
n_keys = n_min_ideal_keys;
|
||||
}
|
||||
//If collected keys are not enough, try to fix n_keys and l_intbuf. If no fix
|
||||
//is possible (due to very low unique keys), then go to a slow sort based on rotations.
|
||||
else{
|
||||
BOOST_ASSERT(collected < (n_min_ideal_keys+l_intbuf));
|
||||
if(collected < 4){ //No combination possible with less that 4 keys
|
||||
return false;
|
||||
}
|
||||
n_keys = l_intbuf;
|
||||
while(n_keys&(n_keys-1)){
|
||||
n_keys &= n_keys-1; // make it power or 2
|
||||
}
|
||||
while(n_keys > collected){
|
||||
n_keys/=2;
|
||||
}
|
||||
//AdaptiveSortInsertionSortThreshold is always power of two so the minimum is power of two
|
||||
l_base = min_value<Unsigned>(n_keys, AdaptiveSortInsertionSortThreshold);
|
||||
l_intbuf = 0;
|
||||
l_build_buf = n_keys;
|
||||
}
|
||||
BOOST_ASSERT((n_keys+l_intbuf) >= l_build_buf);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// Main explanation of the sort algorithm.
|
||||
//
|
||||
// csqrtlen = ceil(sqrt(len));
|
||||
//
|
||||
// * First, 2*csqrtlen unique elements elements are extracted from elements to be
|
||||
// sorted and placed in the beginning of the range.
|
||||
//
|
||||
// * Step "build_blocks": In this nearly-classic merge step, 2*csqrtlen unique elements
|
||||
// will be used as auxiliary memory, so trailing len-2*csqrtlen elements are
|
||||
// are grouped in blocks of sorted 4*csqrtlen elements. At the end of the step
|
||||
// 2*csqrtlen unique elements are again the leading elements of the whole range.
|
||||
//
|
||||
// * Step "combine_blocks": pairs of previously formed blocks are merged with a different
|
||||
// ("smart") algorithm to form blocks of 8*csqrtlen elements. This step is slower than the
|
||||
// "build_blocks" step and repeated iteratively (forming blocks of 16*csqrtlen, 32*csqrtlen
|
||||
// elements, etc) of until all trailing (len-2*csqrtlen) elements are merged.
|
||||
//
|
||||
// In "combine_blocks" len/csqrtlen elements used are as "keys" (markers) to
|
||||
// know if elements belong to the first or second block to be merged and another
|
||||
// leading csqrtlen elements are used as buffer. Explanation of the "combine_blocks" step:
|
||||
//
|
||||
// Iteratively until all trailing (len-2*csqrtlen) elements are merged:
|
||||
// Iteratively for each pair of previously merged block:
|
||||
// * Blocks are divided groups of csqrtlen elements and
|
||||
// 2*merged_block/csqrtlen keys are sorted to be used as markers
|
||||
// * Groups are selection-sorted by first or last element (depending whether they are going
|
||||
// to be merged to left or right) and keys are reordered accordingly as an imitation-buffer.
|
||||
// * Elements of each block pair are merged using the csqrtlen buffer taking into account
|
||||
// if they belong to the first half or second half (marked by the key).
|
||||
//
|
||||
// * In the final merge step leading elements (2*csqrtlen) are sorted and merged with
|
||||
// rotations with the rest of sorted elements in the "combine_blocks" step.
|
||||
//
|
||||
// Corner cases:
|
||||
//
|
||||
// * If no 2*csqrtlen elements can be extracted:
|
||||
//
|
||||
// * If csqrtlen+len/csqrtlen are extracted, then only csqrtlen elements are used
|
||||
// as buffer in the "build_blocks" step forming blocks of 2*csqrtlen elements. This
|
||||
// means that an additional "combine_blocks" step will be needed to merge all elements.
|
||||
//
|
||||
// * If no csqrtlen+len/csqrtlen elements can be extracted, but still more than a minimum,
|
||||
// then reduces the number of elements used as buffer and keys in the "build_blocks"
|
||||
// and "combine_blocks" steps. If "combine_blocks" has no enough keys due to this reduction
|
||||
// then uses a rotation based smart merge.
|
||||
//
|
||||
// * If the minimum number of keys can't be extracted, a rotation-based sorting is performed.
|
||||
//
|
||||
// * If auxiliary memory is more or equal than ceil(len/2), half-copying mergesort is used.
|
||||
//
|
||||
// * If auxiliary memory is more than csqrtlen+n_keys*sizeof(std::size_t),
|
||||
// then only csqrtlen elements need to be extracted and "combine_blocks" will use integral
|
||||
// keys to combine blocks.
|
||||
//
|
||||
// * If auxiliary memory is available, the "build_blocks" will be extended to build bigger blocks
|
||||
// using classic merge and "combine_blocks" will use bigger blocks when merging.
|
||||
template<class RandIt, class Compare, class XBuf>
|
||||
void adaptive_sort_impl
|
||||
( RandIt first
|
||||
, typename iterator_traits<RandIt>::size_type const len
|
||||
, Compare comp
|
||||
, XBuf & xbuf
|
||||
)
|
||||
{
|
||||
typedef typename iterator_traits<RandIt>::size_type size_type;
|
||||
|
||||
//Small sorts go directly to insertion sort
|
||||
if(len <= size_type(AdaptiveSortInsertionSortThreshold)){
|
||||
insertion_sort(first, first + len, comp);
|
||||
}
|
||||
else if((len-len/2) <= xbuf.capacity()){
|
||||
merge_sort(first, first+len, comp, xbuf.data());
|
||||
}
|
||||
else{
|
||||
//Make sure it is at least four
|
||||
BOOST_STATIC_ASSERT(AdaptiveSortInsertionSortThreshold >= 4);
|
||||
|
||||
size_type l_base = 0;
|
||||
size_type l_intbuf = 0;
|
||||
size_type n_keys = 0;
|
||||
size_type l_build_buf = 0;
|
||||
|
||||
//Calculate and extract needed unique elements. If a minimum is not achieved
|
||||
//fallback to a slow stable sort
|
||||
if(!adaptive_sort_build_params(first, len, comp, n_keys, l_intbuf, l_base, l_build_buf, xbuf)){
|
||||
stable_sort(first, first+len, comp, xbuf);
|
||||
}
|
||||
else{
|
||||
BOOST_ASSERT(l_build_buf);
|
||||
//Otherwise, continue the adaptive_sort
|
||||
BOOST_MOVE_ADAPTIVE_SORT_PRINT_L1("\n After collect_unique: ", len);
|
||||
size_type const n_key_plus_buf = l_intbuf+n_keys;
|
||||
//l_build_buf is always power of two if l_intbuf is zero
|
||||
BOOST_ASSERT(l_intbuf || (0 == (l_build_buf & (l_build_buf-1))));
|
||||
|
||||
//Classic merge sort until internal buffer and xbuf are exhausted
|
||||
size_type const l_merged = adaptive_sort_build_blocks
|
||||
(first+n_key_plus_buf-l_build_buf, len-n_key_plus_buf+l_build_buf, l_base, l_build_buf, xbuf, comp);
|
||||
BOOST_MOVE_ADAPTIVE_SORT_PRINT_L1(" After build_blocks: ", len);
|
||||
|
||||
//Non-trivial merge
|
||||
bool const buffer_right = adaptive_sort_combine_all_blocks
|
||||
(first, n_keys, first+n_keys, len-n_keys, l_merged, l_intbuf, xbuf, comp);
|
||||
|
||||
//Sort keys and buffer and merge the whole sequence
|
||||
adaptive_sort_final_merge(buffer_right, first, l_intbuf, n_keys, len, xbuf, comp);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} //namespace detail_adaptive {
|
||||
|
||||
///@endcond
|
||||
|
||||
//! <b>Effects</b>: Sorts the elements in the range [first, last) in ascending order according
|
||||
//! to comparison functor "comp". The sort is stable (order of equal elements
|
||||
//! is guaranteed to be preserved). Performance is improved if additional raw storage is
|
||||
@@ -43,18 +604,25 @@ namespace movelib {
|
||||
//! ceil(sqrt(std::distance(first, last)))*2.
|
||||
//!
|
||||
//! <b>Caution</b>: Experimental implementation, not production-ready.
|
||||
template<class RandIt, class Compare>
|
||||
template<class RandIt, class RandRawIt, class Compare>
|
||||
void adaptive_sort( RandIt first, RandIt last, Compare comp
|
||||
, typename iterator_traits<RandIt>::value_type* uninitialized = 0
|
||||
, std::size_t uninitialized_len = 0)
|
||||
, RandRawIt uninitialized
|
||||
, typename iterator_traits<RandIt>::size_type uninitialized_len)
|
||||
{
|
||||
typedef typename iterator_traits<RandIt>::size_type size_type;
|
||||
typedef typename iterator_traits<RandIt>::value_type value_type;
|
||||
|
||||
::boost::movelib::detail_adaptive::adaptive_xbuf<value_type> xbuf(uninitialized, uninitialized_len);
|
||||
::boost::movelib::adaptive_xbuf<value_type, RandRawIt, size_type> xbuf(uninitialized, uninitialized_len);
|
||||
::boost::movelib::detail_adaptive::adaptive_sort_impl(first, size_type(last - first), comp, xbuf);
|
||||
}
|
||||
|
||||
template<class RandIt, class Compare>
|
||||
void adaptive_sort( RandIt first, RandIt last, Compare comp)
|
||||
{
|
||||
typedef typename iterator_traits<RandIt>::value_type value_type;
|
||||
adaptive_sort(first, last, comp, (value_type*)0, 0u);
|
||||
}
|
||||
|
||||
} //namespace movelib {
|
||||
} //namespace boost {
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -35,19 +35,19 @@ struct four_way_t{};
|
||||
struct move_op
|
||||
{
|
||||
template <class SourceIt, class DestinationIt>
|
||||
void operator()(SourceIt source, DestinationIt dest)
|
||||
BOOST_MOVE_FORCEINLINE void operator()(SourceIt source, DestinationIt dest)
|
||||
{ *dest = ::boost::move(*source); }
|
||||
|
||||
template <class SourceIt, class DestinationIt>
|
||||
DestinationIt operator()(forward_t, SourceIt first, SourceIt last, DestinationIt dest_begin)
|
||||
BOOST_MOVE_FORCEINLINE DestinationIt operator()(forward_t, SourceIt first, SourceIt last, DestinationIt dest_begin)
|
||||
{ return ::boost::move(first, last, dest_begin); }
|
||||
|
||||
template <class SourceIt, class DestinationIt>
|
||||
DestinationIt operator()(backward_t, SourceIt first, SourceIt last, DestinationIt dest_last)
|
||||
BOOST_MOVE_FORCEINLINE DestinationIt operator()(backward_t, SourceIt first, SourceIt last, DestinationIt dest_last)
|
||||
{ return ::boost::move_backward(first, last, dest_last); }
|
||||
|
||||
template <class SourceIt, class DestinationIt1, class DestinationIt2>
|
||||
void operator()(three_way_t, SourceIt srcit, DestinationIt1 dest1it, DestinationIt2 dest2it)
|
||||
BOOST_MOVE_FORCEINLINE void operator()(three_way_t, SourceIt srcit, DestinationIt1 dest1it, DestinationIt2 dest2it)
|
||||
{
|
||||
*dest2it = boost::move(*dest1it);
|
||||
*dest1it = boost::move(*srcit);
|
||||
@@ -64,7 +64,7 @@ struct move_op
|
||||
}
|
||||
|
||||
template <class SourceIt, class DestinationIt1, class DestinationIt2, class DestinationIt3>
|
||||
void operator()(four_way_t, SourceIt srcit, DestinationIt1 dest1it, DestinationIt2 dest2it, DestinationIt3 dest3it)
|
||||
BOOST_MOVE_FORCEINLINE void operator()(four_way_t, SourceIt srcit, DestinationIt1 dest1it, DestinationIt2 dest2it, DestinationIt3 dest3it)
|
||||
{
|
||||
*dest3it = boost::move(*dest2it);
|
||||
*dest2it = boost::move(*dest1it);
|
||||
@@ -75,19 +75,19 @@ struct move_op
|
||||
struct swap_op
|
||||
{
|
||||
template <class SourceIt, class DestinationIt>
|
||||
void operator()(SourceIt source, DestinationIt dest)
|
||||
BOOST_MOVE_FORCEINLINE void operator()(SourceIt source, DestinationIt dest)
|
||||
{ boost::adl_move_swap(*dest, *source); }
|
||||
|
||||
template <class SourceIt, class DestinationIt>
|
||||
DestinationIt operator()(forward_t, SourceIt first, SourceIt last, DestinationIt dest_begin)
|
||||
BOOST_MOVE_FORCEINLINE DestinationIt operator()(forward_t, SourceIt first, SourceIt last, DestinationIt dest_begin)
|
||||
{ return boost::adl_move_swap_ranges(first, last, dest_begin); }
|
||||
|
||||
template <class SourceIt, class DestinationIt>
|
||||
DestinationIt operator()(backward_t, SourceIt first, SourceIt last, DestinationIt dest_begin)
|
||||
BOOST_MOVE_FORCEINLINE DestinationIt operator()(backward_t, SourceIt first, SourceIt last, DestinationIt dest_begin)
|
||||
{ return boost::adl_move_swap_ranges_backward(first, last, dest_begin); }
|
||||
|
||||
template <class SourceIt, class DestinationIt1, class DestinationIt2>
|
||||
void operator()(three_way_t, SourceIt srcit, DestinationIt1 dest1it, DestinationIt2 dest2it)
|
||||
BOOST_MOVE_FORCEINLINE void operator()(three_way_t, SourceIt srcit, DestinationIt1 dest1it, DestinationIt2 dest2it)
|
||||
{
|
||||
typename ::boost::movelib::iterator_traits<SourceIt>::value_type tmp(boost::move(*dest2it));
|
||||
*dest2it = boost::move(*dest1it);
|
||||
@@ -105,7 +105,7 @@ struct swap_op
|
||||
}
|
||||
|
||||
template <class SourceIt, class DestinationIt1, class DestinationIt2, class DestinationIt3>
|
||||
void operator()(four_way_t, SourceIt srcit, DestinationIt1 dest1it, DestinationIt2 dest2it, DestinationIt3 dest3it)
|
||||
BOOST_MOVE_FORCEINLINE void operator()(four_way_t, SourceIt srcit, DestinationIt1 dest1it, DestinationIt2 dest2it, DestinationIt3 dest3it)
|
||||
{
|
||||
typename ::boost::movelib::iterator_traits<SourceIt>::value_type tmp(boost::move(*dest3it));
|
||||
*dest3it = boost::move(*dest2it);
|
||||
|
||||
111
linx64/include/boost/move/algo/detail/heap_sort.hpp
Normal file
111
linx64/include/boost/move/algo/detail/heap_sort.hpp
Normal file
@@ -0,0 +1,111 @@
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// (C) Copyright Ion Gaztanaga 2017-2018.
|
||||
// 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)
|
||||
//
|
||||
// See http://www.boost.org/libs/move for documentation.
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//! \file
|
||||
|
||||
#ifndef BOOST_MOVE_DETAIL_HEAP_SORT_HPP
|
||||
#define BOOST_MOVE_DETAIL_HEAP_SORT_HPP
|
||||
|
||||
#ifndef BOOST_CONFIG_HPP
|
||||
# include <boost/config.hpp>
|
||||
#endif
|
||||
#
|
||||
#if defined(BOOST_HAS_PRAGMA_ONCE)
|
||||
# pragma once
|
||||
#endif
|
||||
|
||||
#include <boost/move/detail/config_begin.hpp>
|
||||
#include <boost/move/detail/workaround.hpp>
|
||||
#include <boost/move/detail/iterator_traits.hpp>
|
||||
#include <boost/move/algo/detail/is_sorted.hpp>
|
||||
#include <boost/move/utility_core.hpp>
|
||||
|
||||
namespace boost { namespace movelib{
|
||||
|
||||
template <class RandomAccessIterator, class Compare>
|
||||
class heap_sort_helper
|
||||
{
|
||||
typedef typename boost::movelib::iterator_traits<RandomAccessIterator>::size_type size_type;
|
||||
typedef typename boost::movelib::iterator_traits<RandomAccessIterator>::value_type value_type;
|
||||
|
||||
static void adjust_heap(RandomAccessIterator first, size_type hole_index, size_type const len, value_type &value, Compare comp)
|
||||
{
|
||||
size_type const top_index = hole_index;
|
||||
size_type second_child = 2 * (hole_index + 1);
|
||||
|
||||
while (second_child < len) {
|
||||
if (comp(*(first + second_child), *(first + (second_child - 1))))
|
||||
second_child--;
|
||||
*(first + hole_index) = boost::move(*(first + second_child));
|
||||
hole_index = second_child;
|
||||
second_child = 2 * (second_child + 1);
|
||||
}
|
||||
if (second_child == len) {
|
||||
*(first + hole_index) = boost::move(*(first + (second_child - 1)));
|
||||
hole_index = second_child - 1;
|
||||
}
|
||||
|
||||
{ //push_heap-like ending
|
||||
size_type parent = (hole_index - 1) / 2;
|
||||
while (hole_index > top_index && comp(*(first + parent), value)) {
|
||||
*(first + hole_index) = boost::move(*(first + parent));
|
||||
hole_index = parent;
|
||||
parent = (hole_index - 1) / 2;
|
||||
}
|
||||
*(first + hole_index) = boost::move(value);
|
||||
}
|
||||
}
|
||||
|
||||
static void make_heap(RandomAccessIterator first, RandomAccessIterator last, Compare comp)
|
||||
{
|
||||
size_type const len = size_type(last - first);
|
||||
if (len > 1) {
|
||||
size_type parent = len/2u - 1u;
|
||||
|
||||
do {
|
||||
value_type v(boost::move(*(first + parent)));
|
||||
adjust_heap(first, parent, len, v, comp);
|
||||
}while (parent--);
|
||||
}
|
||||
}
|
||||
|
||||
static void sort_heap(RandomAccessIterator first, RandomAccessIterator last, Compare comp)
|
||||
{
|
||||
size_type len = size_type(last - first);
|
||||
while (len > 1) {
|
||||
//move biggest to the safe zone
|
||||
--last;
|
||||
value_type v(boost::move(*last));
|
||||
*last = boost::move(*first);
|
||||
adjust_heap(first, size_type(0), --len, v, comp);
|
||||
}
|
||||
}
|
||||
|
||||
public:
|
||||
static void sort(RandomAccessIterator first, RandomAccessIterator last, Compare comp)
|
||||
{
|
||||
make_heap(first, last, comp);
|
||||
sort_heap(first, last, comp);
|
||||
BOOST_ASSERT(boost::movelib::is_sorted(first, last, comp));
|
||||
}
|
||||
};
|
||||
|
||||
template <class RandomAccessIterator, class Compare>
|
||||
BOOST_MOVE_FORCEINLINE void heap_sort(RandomAccessIterator first, RandomAccessIterator last, Compare comp)
|
||||
{
|
||||
heap_sort_helper<RandomAccessIterator, Compare>::sort(first, last, comp);
|
||||
}
|
||||
|
||||
}} //namespace boost { namespace movelib{
|
||||
|
||||
#include <boost/move/detail/config_end.hpp>
|
||||
|
||||
#endif //#ifndef BOOST_MOVE_DETAIL_HEAP_SORT_HPP
|
||||
@@ -31,6 +31,7 @@
|
||||
#include <boost/move/detail/destruct_n.hpp>
|
||||
#include <boost/move/algo/detail/basic_op.hpp>
|
||||
#include <boost/move/detail/placement_new.hpp>
|
||||
#include <boost/move/detail/iterator_to_raw_pointer.hpp>
|
||||
|
||||
namespace boost { namespace movelib{
|
||||
|
||||
@@ -91,30 +92,30 @@ void insertion_sort(BirdirectionalIterator first, BirdirectionalIterator last, C
|
||||
}
|
||||
}
|
||||
|
||||
template <class Compare, class BirdirectionalIterator>
|
||||
template <class Compare, class BirdirectionalIterator, class BirdirectionalRawIterator>
|
||||
void insertion_sort_uninitialized_copy
|
||||
(BirdirectionalIterator first1, BirdirectionalIterator const last1
|
||||
, typename iterator_traits<BirdirectionalIterator>::value_type* const first2
|
||||
, BirdirectionalRawIterator const first2
|
||||
, Compare comp)
|
||||
{
|
||||
typedef typename iterator_traits<BirdirectionalIterator>::value_type value_type;
|
||||
if (first1 != last1){
|
||||
value_type* last2 = first2;
|
||||
::new(last2, boost_move_new_t()) value_type(move(*first1));
|
||||
destruct_n<value_type> d(first2);
|
||||
BirdirectionalRawIterator last2 = first2;
|
||||
::new((iterator_to_raw_pointer)(last2), boost_move_new_t()) value_type(::boost::move(*first1));
|
||||
destruct_n<value_type, BirdirectionalRawIterator> d(first2);
|
||||
d.incr();
|
||||
for (++last2; ++first1 != last1; ++last2){
|
||||
value_type* j2 = last2;
|
||||
value_type* k2 = j2;
|
||||
BirdirectionalRawIterator j2 = last2;
|
||||
BirdirectionalRawIterator k2 = j2;
|
||||
if (comp(*first1, *--k2)){
|
||||
::new(j2, boost_move_new_t()) value_type(move(*k2));
|
||||
::new((iterator_to_raw_pointer)(j2), boost_move_new_t()) value_type(::boost::move(*k2));
|
||||
d.incr();
|
||||
for (--j2; k2 != first2 && comp(*first1, *--k2); --j2)
|
||||
*j2 = move(*k2);
|
||||
*j2 = move(*first1);
|
||||
*j2 = ::boost::move(*k2);
|
||||
*j2 = ::boost::move(*first1);
|
||||
}
|
||||
else{
|
||||
::new(j2, boost_move_new_t()) value_type(move(*first1));
|
||||
::new((iterator_to_raw_pointer)(j2), boost_move_new_t()) value_type(::boost::move(*first1));
|
||||
d.incr();
|
||||
}
|
||||
}
|
||||
|
||||
55
linx64/include/boost/move/algo/detail/is_sorted.hpp
Normal file
55
linx64/include/boost/move/algo/detail/is_sorted.hpp
Normal file
@@ -0,0 +1,55 @@
|
||||
#ifndef BOOST_MOVE_DETAIL_IS_SORTED_HPP
|
||||
#define BOOST_MOVE_DETAIL_IS_SORTED_HPP
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// (C) Copyright Ion Gaztanaga 2017-2018. 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)
|
||||
//
|
||||
// See http://www.boost.org/libs/container for documentation.
|
||||
//
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef BOOST_CONFIG_HPP
|
||||
# include <boost/config.hpp>
|
||||
#endif
|
||||
|
||||
#if defined(BOOST_HAS_PRAGMA_ONCE)
|
||||
# pragma once
|
||||
#endif
|
||||
|
||||
namespace boost {
|
||||
namespace movelib {
|
||||
|
||||
template<class ForwardIt, class Pred>
|
||||
bool is_sorted(ForwardIt const first, ForwardIt last, Pred pred)
|
||||
{
|
||||
if (first != last) {
|
||||
ForwardIt next = first, cur(first);
|
||||
while (++next != last) {
|
||||
if (pred(*next, *cur))
|
||||
return false;
|
||||
cur = next;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
template<class ForwardIt, class Pred>
|
||||
bool is_sorted_and_unique(ForwardIt first, ForwardIt last, Pred pred)
|
||||
{
|
||||
if (first != last) {
|
||||
ForwardIt next = first;
|
||||
while (++next != last) {
|
||||
if (!pred(*first, *next))
|
||||
return false;
|
||||
first = next;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
} //namespace movelib {
|
||||
} //namespace boost {
|
||||
|
||||
#endif //BOOST_MOVE_DETAIL_IS_SORTED_HPP
|
||||
@@ -16,11 +16,266 @@
|
||||
#include <boost/move/algo/detail/basic_op.hpp>
|
||||
#include <boost/move/detail/iterator_traits.hpp>
|
||||
#include <boost/move/detail/destruct_n.hpp>
|
||||
#include <boost/move/algo/predicate.hpp>
|
||||
#include <boost/move/detail/iterator_to_raw_pointer.hpp>
|
||||
#include <boost/assert.hpp>
|
||||
#include <cstddef>
|
||||
|
||||
namespace boost {
|
||||
namespace movelib {
|
||||
|
||||
template<class T, class RandRawIt = T*, class SizeType = typename iterator_traits<RandRawIt>::size_type>
|
||||
class adaptive_xbuf
|
||||
{
|
||||
adaptive_xbuf(const adaptive_xbuf &);
|
||||
adaptive_xbuf & operator=(const adaptive_xbuf &);
|
||||
|
||||
#if !defined(UINTPTR_MAX)
|
||||
typedef std::size_t uintptr_t;
|
||||
#endif
|
||||
|
||||
public:
|
||||
typedef RandRawIt iterator;
|
||||
typedef SizeType size_type;
|
||||
|
||||
adaptive_xbuf()
|
||||
: m_ptr(), m_size(0), m_capacity(0)
|
||||
{}
|
||||
|
||||
adaptive_xbuf(RandRawIt raw_memory, size_type capacity)
|
||||
: m_ptr(raw_memory), m_size(0), m_capacity(capacity)
|
||||
{}
|
||||
|
||||
template<class RandIt>
|
||||
void move_assign(RandIt first, size_type n)
|
||||
{
|
||||
if(n <= m_size){
|
||||
boost::move(first, first+n, m_ptr);
|
||||
size_type size = m_size;
|
||||
while(size-- != n){
|
||||
m_ptr[size].~T();
|
||||
}
|
||||
m_size = n;
|
||||
}
|
||||
else{
|
||||
RandRawIt result = boost::move(first, first+m_size, m_ptr);
|
||||
boost::uninitialized_move(first+m_size, first+n, result);
|
||||
m_size = n;
|
||||
}
|
||||
}
|
||||
|
||||
template<class RandIt>
|
||||
void push_back(RandIt first, size_type n)
|
||||
{
|
||||
BOOST_ASSERT(m_capacity - m_size >= n);
|
||||
boost::uninitialized_move(first, first+n, m_ptr+m_size);
|
||||
m_size += n;
|
||||
}
|
||||
|
||||
template<class RandIt>
|
||||
iterator add(RandIt it)
|
||||
{
|
||||
BOOST_ASSERT(m_size < m_capacity);
|
||||
RandRawIt p_ret = m_ptr + m_size;
|
||||
::new(&*p_ret) T(::boost::move(*it));
|
||||
++m_size;
|
||||
return p_ret;
|
||||
}
|
||||
|
||||
template<class RandIt>
|
||||
void insert(iterator pos, RandIt it)
|
||||
{
|
||||
if(pos == (m_ptr + m_size)){
|
||||
this->add(it);
|
||||
}
|
||||
else{
|
||||
this->add(m_ptr+m_size-1);
|
||||
//m_size updated
|
||||
boost::move_backward(pos, m_ptr+m_size-2, m_ptr+m_size-1);
|
||||
*pos = boost::move(*it);
|
||||
}
|
||||
}
|
||||
|
||||
void set_size(size_type size)
|
||||
{
|
||||
m_size = size;
|
||||
}
|
||||
|
||||
void shrink_to_fit(size_type const size)
|
||||
{
|
||||
if(m_size > size){
|
||||
for(size_type szt_i = size; szt_i != m_size; ++szt_i){
|
||||
m_ptr[szt_i].~T();
|
||||
}
|
||||
m_size = size;
|
||||
}
|
||||
}
|
||||
|
||||
void initialize_until(size_type const size, T &t)
|
||||
{
|
||||
BOOST_ASSERT(m_size < m_capacity);
|
||||
if(m_size < size){
|
||||
BOOST_TRY
|
||||
{
|
||||
::new((void*)&m_ptr[m_size]) T(::boost::move(t));
|
||||
++m_size;
|
||||
for(; m_size != size; ++m_size){
|
||||
::new((void*)&m_ptr[m_size]) T(::boost::move(m_ptr[m_size-1]));
|
||||
}
|
||||
t = ::boost::move(m_ptr[m_size-1]);
|
||||
}
|
||||
BOOST_CATCH(...)
|
||||
{
|
||||
while(m_size)
|
||||
{
|
||||
--m_size;
|
||||
m_ptr[m_size].~T();
|
||||
}
|
||||
}
|
||||
BOOST_CATCH_END
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
template<class RIt>
|
||||
static bool is_raw_ptr(RIt)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool is_raw_ptr(T*)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public:
|
||||
template<class U>
|
||||
bool supports_aligned_trailing(size_type size, size_type trail_count) const
|
||||
{
|
||||
if(this->is_raw_ptr(this->data()) && m_capacity){
|
||||
uintptr_t u_addr_sz = uintptr_t(&*(this->data()+size));
|
||||
uintptr_t u_addr_cp = uintptr_t(&*(this->data()+this->capacity()));
|
||||
u_addr_sz = ((u_addr_sz + sizeof(U)-1)/sizeof(U))*sizeof(U);
|
||||
return (u_addr_cp >= u_addr_sz) && ((u_addr_cp - u_addr_sz)/sizeof(U) >= trail_count);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
template<class U>
|
||||
U *aligned_trailing() const
|
||||
{
|
||||
return this->aligned_trailing<U>(this->size());
|
||||
}
|
||||
|
||||
template<class U>
|
||||
U *aligned_trailing(size_type pos) const
|
||||
{
|
||||
uintptr_t u_addr = uintptr_t(&*(this->data()+pos));
|
||||
u_addr = ((u_addr + sizeof(U)-1)/sizeof(U))*sizeof(U);
|
||||
return (U*)u_addr;
|
||||
}
|
||||
|
||||
~adaptive_xbuf()
|
||||
{
|
||||
this->clear();
|
||||
}
|
||||
|
||||
size_type capacity() const
|
||||
{ return m_capacity; }
|
||||
|
||||
iterator data() const
|
||||
{ return m_ptr; }
|
||||
|
||||
iterator begin() const
|
||||
{ return m_ptr; }
|
||||
|
||||
iterator end() const
|
||||
{ return m_ptr+m_size; }
|
||||
|
||||
size_type size() const
|
||||
{ return m_size; }
|
||||
|
||||
bool empty() const
|
||||
{ return !m_size; }
|
||||
|
||||
void clear()
|
||||
{
|
||||
this->shrink_to_fit(0u);
|
||||
}
|
||||
|
||||
private:
|
||||
RandRawIt m_ptr;
|
||||
size_type m_size;
|
||||
size_type m_capacity;
|
||||
};
|
||||
|
||||
template<class Iterator, class SizeType, class Op>
|
||||
class range_xbuf
|
||||
{
|
||||
range_xbuf(const range_xbuf &);
|
||||
range_xbuf & operator=(const range_xbuf &);
|
||||
|
||||
public:
|
||||
typedef SizeType size_type;
|
||||
typedef Iterator iterator;
|
||||
|
||||
range_xbuf(Iterator first, Iterator last)
|
||||
: m_first(first), m_last(first), m_cap(last)
|
||||
{}
|
||||
|
||||
template<class RandIt>
|
||||
void move_assign(RandIt first, size_type n)
|
||||
{
|
||||
BOOST_ASSERT(size_type(n) <= size_type(m_cap-m_first));
|
||||
m_last = Op()(forward_t(), first, first+n, m_first);
|
||||
}
|
||||
|
||||
~range_xbuf()
|
||||
{}
|
||||
|
||||
size_type capacity() const
|
||||
{ return m_cap-m_first; }
|
||||
|
||||
Iterator data() const
|
||||
{ return m_first; }
|
||||
|
||||
Iterator end() const
|
||||
{ return m_last; }
|
||||
|
||||
size_type size() const
|
||||
{ return m_last-m_first; }
|
||||
|
||||
bool empty() const
|
||||
{ return m_first == m_last; }
|
||||
|
||||
void clear()
|
||||
{
|
||||
m_last = m_first;
|
||||
}
|
||||
|
||||
template<class RandIt>
|
||||
iterator add(RandIt it)
|
||||
{
|
||||
Iterator pos(m_last);
|
||||
*pos = boost::move(*it);
|
||||
++m_last;
|
||||
return pos;
|
||||
}
|
||||
|
||||
void set_size(size_type size)
|
||||
{
|
||||
m_last = m_first;
|
||||
m_last += size;
|
||||
}
|
||||
|
||||
private:
|
||||
Iterator const m_first;
|
||||
Iterator m_last;
|
||||
Iterator const m_cap;
|
||||
};
|
||||
|
||||
|
||||
|
||||
// @cond
|
||||
|
||||
/*
|
||||
@@ -181,9 +436,6 @@ void op_merge_left( RandIt buf_first
|
||||
//and all elements from the second half are less)
|
||||
op(forward_t(), first1, last1, buf_first);
|
||||
}
|
||||
else{
|
||||
buf_first = buf_first;
|
||||
}
|
||||
}
|
||||
|
||||
// [buf_first, first1) -> buffer
|
||||
@@ -257,99 +509,43 @@ void swap_merge_right
|
||||
op_merge_right(first1, last1, last2, buf_last, comp, swap_op());
|
||||
}
|
||||
|
||||
template <class BidirIt, class Distance, class Compare>
|
||||
void merge_bufferless_ONlogN_recursive
|
||||
(BidirIt first, BidirIt middle, BidirIt last, Distance len1, Distance len2, Compare comp)
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// BUFFERED MERGE
|
||||
//
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
template<class RandIt, class Compare, class Op, class Buf>
|
||||
void op_buffered_merge
|
||||
( RandIt first, RandIt const middle, RandIt last
|
||||
, Compare comp, Op op
|
||||
, Buf &xbuf)
|
||||
{
|
||||
typedef typename iterator_traits<BidirIt>::size_type size_type;
|
||||
while(1) {
|
||||
//#define MERGE_BUFFERLESS_RECURSIVE_OPT
|
||||
#ifndef MERGE_BUFFERLESS_RECURSIVE_OPT
|
||||
if (len2 == 0) {
|
||||
return;
|
||||
if(first != middle && middle != last && comp(*middle, middle[-1])){
|
||||
typedef typename iterator_traits<RandIt>::size_type size_type;
|
||||
size_type const len1 = size_type(middle-first);
|
||||
size_type const len2 = size_type(last-middle);
|
||||
if(len1 <= len2){
|
||||
first = boost::movelib::upper_bound(first, middle, *middle, comp);
|
||||
xbuf.move_assign(first, size_type(middle-first));
|
||||
op_merge_with_right_placed
|
||||
(xbuf.data(), xbuf.end(), first, middle, last, comp, op);
|
||||
}
|
||||
|
||||
if (!len1) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ((len1 | len2) == 1) {
|
||||
if (comp(*middle, *first))
|
||||
adl_move_swap(*first, *middle);
|
||||
return;
|
||||
}
|
||||
#else
|
||||
if (len2 == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!len1) {
|
||||
return;
|
||||
}
|
||||
BidirIt middle_prev = middle; --middle_prev;
|
||||
if(!comp(*middle, *middle_prev))
|
||||
return;
|
||||
|
||||
while(true) {
|
||||
if (comp(*middle, *first))
|
||||
break;
|
||||
++first;
|
||||
if(--len1 == 1)
|
||||
break;
|
||||
}
|
||||
|
||||
if (len1 == 1 && len2 == 1) {
|
||||
//comp(*middle, *first) == true already tested in the loop
|
||||
adl_move_swap(*first, *middle);
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
BidirIt first_cut = first;
|
||||
BidirIt second_cut = middle;
|
||||
Distance len11 = 0;
|
||||
Distance len22 = 0;
|
||||
if (len1 > len2) {
|
||||
len11 = len1 / 2;
|
||||
first_cut += len11;
|
||||
second_cut = lower_bound(middle, last, *first_cut, comp);
|
||||
len22 = size_type(second_cut - middle);
|
||||
}
|
||||
else {
|
||||
len22 = len2 / 2;
|
||||
second_cut += len22;
|
||||
first_cut = upper_bound(first, middle, *second_cut, comp);
|
||||
len11 = size_type(first_cut - first);
|
||||
}
|
||||
BidirIt new_middle = rotate_gcd(first_cut, middle, second_cut);
|
||||
|
||||
//Avoid one recursive call doing a manual tail call elimination on the biggest range
|
||||
const Distance len_internal = len11+len22;
|
||||
if( len_internal < (len1 + len2 - len_internal) ) {
|
||||
merge_bufferless_ONlogN_recursive(first, first_cut, new_middle, len11, len22, comp);
|
||||
//merge_bufferless_recursive(new_middle, second_cut, last, len1 - len11, len2 - len22, comp);
|
||||
first = new_middle;
|
||||
middle = second_cut;
|
||||
len1 -= len11;
|
||||
len2 -= len22;
|
||||
}
|
||||
else {
|
||||
//merge_bufferless_recursive(first, first_cut, new_middle, len11, len22, comp);
|
||||
merge_bufferless_ONlogN_recursive(new_middle, second_cut, last, len1 - len11, len2 - len22, comp);
|
||||
middle = first_cut;
|
||||
last = new_middle;
|
||||
len1 = len11;
|
||||
len2 = len22;
|
||||
else{
|
||||
last = boost::movelib::lower_bound(middle, last, middle[-1], comp);
|
||||
xbuf.move_assign(middle, size_type(last-middle));
|
||||
op_merge_with_left_placed
|
||||
(first, middle, last, xbuf.data(), xbuf.end(), comp, op);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//Complexity: NlogN
|
||||
template<class BidirIt, class Compare>
|
||||
void merge_bufferless_ONlogN(BidirIt first, BidirIt middle, BidirIt last, Compare comp)
|
||||
template<class RandIt, class Compare, class XBuf>
|
||||
void buffered_merge
|
||||
( RandIt first, RandIt const middle, RandIt last
|
||||
, Compare comp
|
||||
, XBuf &xbuf)
|
||||
{
|
||||
merge_bufferless_ONlogN_recursive
|
||||
(first, middle, last, middle - first, last - middle, comp);
|
||||
op_buffered_merge(first, middle, last, comp, move_op(), xbuf);
|
||||
}
|
||||
|
||||
//Complexity: min(len1,len2)^2 + max(len1,len2)
|
||||
@@ -359,7 +555,7 @@ void merge_bufferless_ON2(RandIt first, RandIt middle, RandIt last, Compare comp
|
||||
if((middle - first) < (last - middle)){
|
||||
while(first != middle){
|
||||
RandIt const old_last1 = middle;
|
||||
middle = lower_bound(middle, last, *first, comp);
|
||||
middle = boost::movelib::lower_bound(middle, last, *first, comp);
|
||||
first = rotate_gcd(first, old_last1, middle);
|
||||
if(middle == last){
|
||||
break;
|
||||
@@ -371,7 +567,7 @@ void merge_bufferless_ON2(RandIt first, RandIt middle, RandIt last, Compare comp
|
||||
}
|
||||
else{
|
||||
while(middle != last){
|
||||
RandIt p = upper_bound(first, middle, last[-1], comp);
|
||||
RandIt p = boost::movelib::upper_bound(first, middle, last[-1], comp);
|
||||
last = rotate_gcd(p, middle, last);
|
||||
middle = p;
|
||||
if(middle == first){
|
||||
@@ -385,10 +581,86 @@ void merge_bufferless_ON2(RandIt first, RandIt middle, RandIt last, Compare comp
|
||||
}
|
||||
}
|
||||
|
||||
static const std::size_t MergeBufferlessONLogNRotationThreshold = 16u;
|
||||
|
||||
template <class RandIt, class Compare>
|
||||
void merge_bufferless_ONlogN_recursive
|
||||
( RandIt first, RandIt middle, RandIt last
|
||||
, typename iterator_traits<RandIt>::size_type len1
|
||||
, typename iterator_traits<RandIt>::size_type len2
|
||||
, Compare comp)
|
||||
{
|
||||
typedef typename iterator_traits<RandIt>::size_type size_type;
|
||||
|
||||
while(1) {
|
||||
//trivial cases
|
||||
if (!len2) {
|
||||
return;
|
||||
}
|
||||
else if (!len1) {
|
||||
return;
|
||||
}
|
||||
else if (size_type(len1 | len2) == 1u) {
|
||||
if (comp(*middle, *first))
|
||||
adl_move_swap(*first, *middle);
|
||||
return;
|
||||
}
|
||||
else if(size_type(len1+len2) < MergeBufferlessONLogNRotationThreshold){
|
||||
merge_bufferless_ON2(first, middle, last, comp);
|
||||
return;
|
||||
}
|
||||
|
||||
RandIt first_cut = first;
|
||||
RandIt second_cut = middle;
|
||||
size_type len11 = 0;
|
||||
size_type len22 = 0;
|
||||
if (len1 > len2) {
|
||||
len11 = len1 / 2;
|
||||
first_cut += len11;
|
||||
second_cut = boost::movelib::lower_bound(middle, last, *first_cut, comp);
|
||||
len22 = size_type(second_cut - middle);
|
||||
}
|
||||
else {
|
||||
len22 = len2 / 2;
|
||||
second_cut += len22;
|
||||
first_cut = boost::movelib::upper_bound(first, middle, *second_cut, comp);
|
||||
len11 = size_type(first_cut - first);
|
||||
}
|
||||
RandIt new_middle = rotate_gcd(first_cut, middle, second_cut);
|
||||
|
||||
//Avoid one recursive call doing a manual tail call elimination on the biggest range
|
||||
const size_type len_internal = len11+len22;
|
||||
if( len_internal < (len1 + len2 - len_internal) ) {
|
||||
merge_bufferless_ONlogN_recursive(first, first_cut, new_middle, len11, len22, comp);
|
||||
first = new_middle;
|
||||
middle = second_cut;
|
||||
len1 -= len11;
|
||||
len2 -= len22;
|
||||
}
|
||||
else {
|
||||
merge_bufferless_ONlogN_recursive(new_middle, second_cut, last, len1 - len11, len2 - len22, comp);
|
||||
middle = first_cut;
|
||||
last = new_middle;
|
||||
len1 = len11;
|
||||
len2 = len22;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//Complexity: NlogN
|
||||
template<class RandIt, class Compare>
|
||||
void merge_bufferless_ONlogN(RandIt first, RandIt middle, RandIt last, Compare comp)
|
||||
{
|
||||
typedef typename iterator_traits<RandIt>::size_type size_type;
|
||||
merge_bufferless_ONlogN_recursive
|
||||
(first, middle, last, size_type(middle - first), size_type(last - middle), comp);
|
||||
}
|
||||
|
||||
template<class RandIt, class Compare>
|
||||
void merge_bufferless(RandIt first, RandIt middle, RandIt last, Compare comp)
|
||||
{
|
||||
//#define BOOST_ADAPTIVE_MERGE_NLOGN_MERGE
|
||||
#define BOOST_ADAPTIVE_MERGE_NLOGN_MERGE
|
||||
#ifdef BOOST_ADAPTIVE_MERGE_NLOGN_MERGE
|
||||
merge_bufferless_ONlogN(first, middle, last, comp);
|
||||
#else
|
||||
@@ -396,65 +668,6 @@ void merge_bufferless(RandIt first, RandIt middle, RandIt last, Compare comp)
|
||||
#endif //BOOST_ADAPTIVE_MERGE_NLOGN_MERGE
|
||||
}
|
||||
|
||||
template<class Comp>
|
||||
struct antistable
|
||||
{
|
||||
explicit antistable(Comp &comp)
|
||||
: m_comp(comp)
|
||||
{}
|
||||
|
||||
template<class U, class V>
|
||||
bool operator()(const U &u, const V & v)
|
||||
{ return !m_comp(v, u); }
|
||||
|
||||
private:
|
||||
antistable & operator=(const antistable &);
|
||||
Comp &m_comp;
|
||||
};
|
||||
|
||||
template <class Comp>
|
||||
class negate
|
||||
{
|
||||
public:
|
||||
negate()
|
||||
{}
|
||||
|
||||
explicit negate(Comp comp)
|
||||
: m_comp(comp)
|
||||
{}
|
||||
|
||||
template <class T1, class T2>
|
||||
bool operator()(const T1& l, const T2& r)
|
||||
{
|
||||
return !m_comp(l, r);
|
||||
}
|
||||
|
||||
private:
|
||||
Comp m_comp;
|
||||
};
|
||||
|
||||
|
||||
template <class Comp>
|
||||
class inverse
|
||||
{
|
||||
public:
|
||||
inverse()
|
||||
{}
|
||||
|
||||
explicit inverse(Comp comp)
|
||||
: m_comp(comp)
|
||||
{}
|
||||
|
||||
template <class T1, class T2>
|
||||
bool operator()(const T1& l, const T2& r)
|
||||
{
|
||||
return m_comp(r, l);
|
||||
}
|
||||
|
||||
private:
|
||||
Comp m_comp;
|
||||
};
|
||||
|
||||
// [r_first, r_last) are already in the right part of the destination range.
|
||||
template <class Compare, class InputIterator, class InputOutIterator, class Op>
|
||||
void op_merge_with_right_placed
|
||||
@@ -525,7 +738,7 @@ void op_merge_with_left_placed
|
||||
|
||||
// @endcond
|
||||
|
||||
// [irst, last) are already in the right part of the destination range.
|
||||
// [first, last) are already in the right part of the destination range.
|
||||
template <class Compare, class BidirIterator, class BidirOutIterator>
|
||||
void merge_with_left_placed
|
||||
( BidirOutIterator const first, BidirOutIterator last, BidirOutIterator dest_last
|
||||
@@ -557,12 +770,12 @@ void uninitialized_merge_with_right_placed
|
||||
typedef typename iterator_traits<InputOutIterator>::value_type value_type;
|
||||
InputOutIterator const original_r_first = r_first;
|
||||
|
||||
destruct_n<value_type> d(&*dest_first);
|
||||
destruct_n<value_type, InputOutIterator> d(dest_first);
|
||||
|
||||
while ( first != last && dest_first != original_r_first ) {
|
||||
if (r_first == r_last) {
|
||||
for(; dest_first != original_r_first; ++dest_first, ++first){
|
||||
::new(&*dest_first) value_type(::boost::move(*first));
|
||||
::new((iterator_to_raw_pointer)(dest_first)) value_type(::boost::move(*first));
|
||||
d.incr();
|
||||
}
|
||||
d.release();
|
||||
@@ -572,12 +785,12 @@ void uninitialized_merge_with_right_placed
|
||||
return;
|
||||
}
|
||||
else if (comp(*r_first, *first)) {
|
||||
::new(&*dest_first) value_type(::boost::move(*r_first));
|
||||
::new((iterator_to_raw_pointer)(dest_first)) value_type(::boost::move(*r_first));
|
||||
d.incr();
|
||||
++r_first;
|
||||
}
|
||||
else {
|
||||
::new(&*dest_first) value_type(::boost::move(*first));
|
||||
::new((iterator_to_raw_pointer)(dest_first)) value_type(::boost::move(*first));
|
||||
d.incr();
|
||||
++first;
|
||||
}
|
||||
@@ -631,6 +844,136 @@ void uninitialized_merge_with_left_placed
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
/// This is a helper function for the merge routines.
|
||||
template<typename BidirectionalIterator1, typename BidirectionalIterator2>
|
||||
BidirectionalIterator1
|
||||
rotate_adaptive(BidirectionalIterator1 first,
|
||||
BidirectionalIterator1 middle,
|
||||
BidirectionalIterator1 last,
|
||||
typename iterator_traits<BidirectionalIterator1>::size_type len1,
|
||||
typename iterator_traits<BidirectionalIterator1>::size_type len2,
|
||||
BidirectionalIterator2 buffer,
|
||||
typename iterator_traits<BidirectionalIterator1>::size_type buffer_size)
|
||||
{
|
||||
if (len1 > len2 && len2 <= buffer_size)
|
||||
{
|
||||
if(len2) //Protect against self-move ranges
|
||||
{
|
||||
BidirectionalIterator2 buffer_end = boost::move(middle, last, buffer);
|
||||
boost::move_backward(first, middle, last);
|
||||
return boost::move(buffer, buffer_end, first);
|
||||
}
|
||||
else
|
||||
return first;
|
||||
}
|
||||
else if (len1 <= buffer_size)
|
||||
{
|
||||
if(len1) //Protect against self-move ranges
|
||||
{
|
||||
BidirectionalIterator2 buffer_end = boost::move(first, middle, buffer);
|
||||
BidirectionalIterator1 ret = boost::move(middle, last, first);
|
||||
boost::move(buffer, buffer_end, ret);
|
||||
return ret;
|
||||
}
|
||||
else
|
||||
return last;
|
||||
}
|
||||
else
|
||||
return rotate_gcd(first, middle, last);
|
||||
}
|
||||
|
||||
template<typename BidirectionalIterator,
|
||||
typename Pointer, typename Compare>
|
||||
void merge_adaptive_ONlogN_recursive
|
||||
(BidirectionalIterator first,
|
||||
BidirectionalIterator middle,
|
||||
BidirectionalIterator last,
|
||||
typename iterator_traits<BidirectionalIterator>::size_type len1,
|
||||
typename iterator_traits<BidirectionalIterator>::size_type len2,
|
||||
Pointer buffer,
|
||||
typename iterator_traits<BidirectionalIterator>::size_type buffer_size,
|
||||
Compare comp)
|
||||
{
|
||||
typedef typename iterator_traits<BidirectionalIterator>::size_type size_type;
|
||||
//trivial cases
|
||||
if (!len2 || !len1) {
|
||||
return;
|
||||
}
|
||||
else if (len1 <= buffer_size || len2 <= buffer_size)
|
||||
{
|
||||
range_xbuf<Pointer, size_type, move_op> rxbuf(buffer, buffer + buffer_size);
|
||||
buffered_merge(first, middle, last, comp, rxbuf);
|
||||
}
|
||||
else if (size_type(len1 + len2) == 2u) {
|
||||
if (comp(*middle, *first))
|
||||
adl_move_swap(*first, *middle);
|
||||
return;
|
||||
}
|
||||
else if (size_type(len1 + len2) < MergeBufferlessONLogNRotationThreshold) {
|
||||
merge_bufferless_ON2(first, middle, last, comp);
|
||||
return;
|
||||
}
|
||||
BidirectionalIterator first_cut = first;
|
||||
BidirectionalIterator second_cut = middle;
|
||||
size_type len11 = 0;
|
||||
size_type len22 = 0;
|
||||
if (len1 > len2) //(len1 < len2)
|
||||
{
|
||||
len11 = len1 / 2;
|
||||
first_cut += len11;
|
||||
second_cut = boost::movelib::lower_bound(middle, last, *first_cut, comp);
|
||||
len22 = second_cut - middle;
|
||||
}
|
||||
else
|
||||
{
|
||||
len22 = len2 / 2;
|
||||
second_cut += len22;
|
||||
first_cut = boost::movelib::upper_bound(first, middle, *second_cut, comp);
|
||||
len11 = first_cut - first;
|
||||
}
|
||||
|
||||
BidirectionalIterator new_middle
|
||||
= rotate_adaptive(first_cut, middle, second_cut,
|
||||
size_type(len1 - len11), len22, buffer,
|
||||
buffer_size);
|
||||
merge_adaptive_ONlogN_recursive(first, first_cut, new_middle, len11,
|
||||
len22, buffer, buffer_size, comp);
|
||||
merge_adaptive_ONlogN_recursive(new_middle, second_cut, last,
|
||||
len1 - len11, len2 - len22, buffer, buffer_size, comp);
|
||||
}
|
||||
|
||||
|
||||
template<typename BidirectionalIterator, typename Compare, typename RandRawIt>
|
||||
void merge_adaptive_ONlogN(BidirectionalIterator first,
|
||||
BidirectionalIterator middle,
|
||||
BidirectionalIterator last,
|
||||
Compare comp,
|
||||
RandRawIt uninitialized,
|
||||
typename iterator_traits<BidirectionalIterator>::size_type uninitialized_len)
|
||||
{
|
||||
typedef typename iterator_traits<BidirectionalIterator>::value_type value_type;
|
||||
typedef typename iterator_traits<BidirectionalIterator>::size_type size_type;
|
||||
|
||||
if (first == middle || middle == last)
|
||||
return;
|
||||
|
||||
if(uninitialized_len)
|
||||
{
|
||||
const size_type len1 = size_type(middle - first);
|
||||
const size_type len2 = size_type(last - middle);
|
||||
|
||||
::boost::movelib::adaptive_xbuf<value_type, RandRawIt> xbuf(uninitialized, uninitialized_len);
|
||||
xbuf.initialize_until(uninitialized_len, *first);
|
||||
merge_adaptive_ONlogN_recursive(first, middle, last, len1, len2, xbuf.begin(), uninitialized_len, comp);
|
||||
}
|
||||
else
|
||||
{
|
||||
merge_bufferless(first, middle, last, comp);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
} //namespace movelib {
|
||||
} //namespace boost {
|
||||
|
||||
|
||||
@@ -79,9 +79,9 @@ void merge_sort_copy( RandIt first, RandIt last
|
||||
}
|
||||
}
|
||||
|
||||
template<class RandIt, class Compare>
|
||||
template<class RandIt, class RandItRaw, class Compare>
|
||||
void merge_sort_uninitialized_copy( RandIt first, RandIt last
|
||||
, typename iterator_traits<RandIt>::value_type* uninitialized
|
||||
, RandItRaw uninitialized
|
||||
, Compare comp)
|
||||
{
|
||||
typedef typename iterator_traits<RandIt>::size_type size_type;
|
||||
@@ -94,7 +94,7 @@ void merge_sort_uninitialized_copy( RandIt first, RandIt last
|
||||
else{
|
||||
size_type const half = count/2;
|
||||
merge_sort_uninitialized_copy(first + half, last, uninitialized + half, comp);
|
||||
destruct_n<value_type> d(uninitialized+half);
|
||||
destruct_n<value_type, RandItRaw> d(uninitialized+half);
|
||||
d.incr(count-half);
|
||||
merge_sort_copy(first, first + half, first + half, comp);
|
||||
uninitialized_merge_with_right_placed
|
||||
@@ -105,9 +105,9 @@ void merge_sort_uninitialized_copy( RandIt first, RandIt last
|
||||
}
|
||||
}
|
||||
|
||||
template<class RandIt, class Compare>
|
||||
template<class RandIt, class RandItRaw, class Compare>
|
||||
void merge_sort( RandIt first, RandIt last, Compare comp
|
||||
, typename iterator_traits<RandIt>::value_type* uninitialized)
|
||||
, RandItRaw uninitialized)
|
||||
{
|
||||
typedef typename iterator_traits<RandIt>::size_type size_type;
|
||||
typedef typename iterator_traits<RandIt>::value_type value_type;
|
||||
@@ -123,7 +123,7 @@ void merge_sort( RandIt first, RandIt last, Compare comp
|
||||
RandIt const rest_it = first + rest;
|
||||
|
||||
merge_sort_uninitialized_copy(half_it, last, uninitialized, comp);
|
||||
destruct_n<value_type> d(uninitialized);
|
||||
destruct_n<value_type, RandItRaw> d(uninitialized);
|
||||
d.incr(rest);
|
||||
merge_sort_copy(first, half_it, rest_it, comp);
|
||||
merge_with_right_placed
|
||||
@@ -132,6 +132,74 @@ void merge_sort( RandIt first, RandIt last, Compare comp
|
||||
}
|
||||
}
|
||||
|
||||
///@cond
|
||||
|
||||
template<class RandIt, class RandItRaw, class Compare>
|
||||
void merge_sort_with_constructed_buffer( RandIt first, RandIt last, Compare comp, RandItRaw buffer)
|
||||
{
|
||||
typedef typename iterator_traits<RandIt>::size_type size_type;
|
||||
|
||||
size_type const count = size_type(last - first);
|
||||
if(count <= MergeSortInsertionSortThreshold){
|
||||
insertion_sort(first, last, comp);
|
||||
}
|
||||
else{
|
||||
size_type const half = count/2;
|
||||
size_type const rest = count - half;
|
||||
RandIt const half_it = first + half;
|
||||
RandIt const rest_it = first + rest;
|
||||
|
||||
merge_sort_copy(half_it, last, buffer, comp);
|
||||
merge_sort_copy(first, half_it, rest_it, comp);
|
||||
merge_with_right_placed
|
||||
(buffer, buffer + rest
|
||||
, first, rest_it, last, antistable<Compare>(comp));
|
||||
}
|
||||
}
|
||||
|
||||
template<typename RandIt, typename Pointer,
|
||||
typename Distance, typename Compare>
|
||||
void stable_sort_ONlogN_recursive(RandIt first, RandIt last, Pointer buffer, Distance buffer_size, Compare comp)
|
||||
{
|
||||
typedef typename iterator_traits<RandIt>::size_type size_type;
|
||||
if (size_type(last - first) <= size_type(MergeSortInsertionSortThreshold)) {
|
||||
insertion_sort(first, last, comp);
|
||||
}
|
||||
else {
|
||||
const size_type len = (last - first) / 2;
|
||||
const RandIt middle = first + len;
|
||||
if (len > ((buffer_size+1)/2)){
|
||||
stable_sort_ONlogN_recursive(first, middle, buffer, buffer_size, comp);
|
||||
stable_sort_ONlogN_recursive(middle, last, buffer, buffer_size, comp);
|
||||
}
|
||||
else{
|
||||
merge_sort_with_constructed_buffer(first, middle, comp, buffer);
|
||||
merge_sort_with_constructed_buffer(middle, last, comp, buffer);
|
||||
}
|
||||
merge_adaptive_ONlogN_recursive(first, middle, last,
|
||||
size_type(middle - first),
|
||||
size_type(last - middle),
|
||||
buffer, buffer_size,
|
||||
comp);
|
||||
}
|
||||
}
|
||||
|
||||
template<typename BidirectionalIterator, typename Compare, typename RandRawIt>
|
||||
void stable_sort_adaptive_ONlogN2(BidirectionalIterator first,
|
||||
BidirectionalIterator last,
|
||||
Compare comp,
|
||||
RandRawIt uninitialized,
|
||||
std::size_t uninitialized_len)
|
||||
{
|
||||
typedef typename iterator_traits<BidirectionalIterator>::value_type value_type;
|
||||
|
||||
::boost::movelib::adaptive_xbuf<value_type, RandRawIt> xbuf(uninitialized, uninitialized_len);
|
||||
xbuf.initialize_until(uninitialized_len, *first);
|
||||
stable_sort_ONlogN_recursive(first, last, uninitialized, uninitialized_len, comp);
|
||||
}
|
||||
|
||||
///@endcond
|
||||
|
||||
}} //namespace boost { namespace movelib{
|
||||
|
||||
#include <boost/move/detail/config_end.hpp>
|
||||
|
||||
334
linx64/include/boost/move/algo/detail/pdqsort.hpp
Normal file
334
linx64/include/boost/move/algo/detail/pdqsort.hpp
Normal file
@@ -0,0 +1,334 @@
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// (C) Copyright Orson Peters 2017.
|
||||
// (C) Copyright Ion Gaztanaga 2017-2018.
|
||||
// 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)
|
||||
//
|
||||
// See http://www.boost.org/libs/move for documentation.
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// This implementation of Pattern-defeating quicksort (pdqsort) was written
|
||||
// by Orson Peters, and discussed in the Boost mailing list:
|
||||
// http://boost.2283326.n4.nabble.com/sort-pdqsort-td4691031.html
|
||||
//
|
||||
// This implementation is the adaptation by Ion Gaztanaga of code originally in GitHub
|
||||
// with permission from the author to relicense it under the Boost Software License
|
||||
// (see the Boost mailing list for details).
|
||||
//
|
||||
// The original copyright statement is pasted here for completeness:
|
||||
//
|
||||
// pdqsort.h - Pattern-defeating quicksort.
|
||||
// Copyright (c) 2015 Orson Peters
|
||||
// This software is provided 'as-is', without any express or implied warranty. In no event will the
|
||||
// authors be held liable for any damages arising from the use of this software.
|
||||
// Permission is granted to anyone to use this software for any purpose, including commercial
|
||||
// applications, and to alter it and redistribute it freely, subject to the following restrictions:
|
||||
// 1. The origin of this software must not be misrepresented; you must not claim that you wrote the
|
||||
// original software. If you use this software in a product, an acknowledgment in the product
|
||||
// documentation would be appreciated but is not required.
|
||||
// 2. Altered source versions must be plainly marked as such, and must not be misrepresented as
|
||||
// being the original software.
|
||||
// 3. This notice may not be removed or altered from any source distribution.
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef BOOST_MOVE_ALGO_PDQSORT_HPP
|
||||
#define BOOST_MOVE_ALGO_PDQSORT_HPP
|
||||
|
||||
#ifndef BOOST_CONFIG_HPP
|
||||
# include <boost/config.hpp>
|
||||
#endif
|
||||
#
|
||||
#if defined(BOOST_HAS_PRAGMA_ONCE)
|
||||
# pragma once
|
||||
#endif
|
||||
|
||||
#include <boost/move/detail/config_begin.hpp>
|
||||
#include <boost/move/detail/workaround.hpp>
|
||||
#include <boost/move/utility_core.hpp>
|
||||
#include <boost/move/algo/detail/insertion_sort.hpp>
|
||||
#include <boost/move/algo/detail/heap_sort.hpp>
|
||||
#include <boost/move/detail/iterator_traits.hpp>
|
||||
|
||||
#include <boost/move/adl_move_swap.hpp>
|
||||
#include <cstddef>
|
||||
|
||||
namespace boost {
|
||||
namespace movelib {
|
||||
|
||||
namespace pdqsort_detail {
|
||||
|
||||
//A simple pair implementation to avoid including <utility>
|
||||
template<class T1, class T2>
|
||||
struct pair
|
||||
{
|
||||
pair()
|
||||
{}
|
||||
|
||||
pair(const T1 &t1, const T2 &t2)
|
||||
: first(t1), second(t2)
|
||||
{}
|
||||
|
||||
T1 first;
|
||||
T2 second;
|
||||
};
|
||||
|
||||
enum {
|
||||
// Partitions below this size are sorted using insertion sort.
|
||||
insertion_sort_threshold = 24,
|
||||
|
||||
// Partitions above this size use Tukey's ninther to select the pivot.
|
||||
ninther_threshold = 128,
|
||||
|
||||
// When we detect an already sorted partition, attempt an insertion sort that allows this
|
||||
// amount of element moves before giving up.
|
||||
partial_insertion_sort_limit = 8,
|
||||
|
||||
// Must be multiple of 8 due to loop unrolling, and < 256 to fit in unsigned char.
|
||||
block_size = 64,
|
||||
|
||||
// Cacheline size, assumes power of two.
|
||||
cacheline_size = 64
|
||||
|
||||
};
|
||||
|
||||
// Returns floor(log2(n)), assumes n > 0.
|
||||
template<class Unsigned>
|
||||
Unsigned log2(Unsigned n) {
|
||||
Unsigned log = 0;
|
||||
while (n >>= 1) ++log;
|
||||
return log;
|
||||
}
|
||||
|
||||
// Attempts to use insertion sort on [begin, end). Will return false if more than
|
||||
// partial_insertion_sort_limit elements were moved, and abort sorting. Otherwise it will
|
||||
// successfully sort and return true.
|
||||
template<class Iter, class Compare>
|
||||
inline bool partial_insertion_sort(Iter begin, Iter end, Compare comp) {
|
||||
typedef typename boost::movelib::iterator_traits<Iter>::value_type T;
|
||||
typedef typename boost::movelib::iterator_traits<Iter>::size_type size_type;
|
||||
if (begin == end) return true;
|
||||
|
||||
size_type limit = 0;
|
||||
for (Iter cur = begin + 1; cur != end; ++cur) {
|
||||
if (limit > partial_insertion_sort_limit) return false;
|
||||
|
||||
Iter sift = cur;
|
||||
Iter sift_1 = cur - 1;
|
||||
|
||||
// Compare first so we can avoid 2 moves for an element already positioned correctly.
|
||||
if (comp(*sift, *sift_1)) {
|
||||
T tmp = boost::move(*sift);
|
||||
|
||||
do { *sift-- = boost::move(*sift_1); }
|
||||
while (sift != begin && comp(tmp, *--sift_1));
|
||||
|
||||
*sift = boost::move(tmp);
|
||||
limit += size_type(cur - sift);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
template<class Iter, class Compare>
|
||||
inline void sort2(Iter a, Iter b, Compare comp) {
|
||||
if (comp(*b, *a)) boost::adl_move_iter_swap(a, b);
|
||||
}
|
||||
|
||||
// Sorts the elements *a, *b and *c using comparison function comp.
|
||||
template<class Iter, class Compare>
|
||||
inline void sort3(Iter a, Iter b, Iter c, Compare comp) {
|
||||
sort2(a, b, comp);
|
||||
sort2(b, c, comp);
|
||||
sort2(a, b, comp);
|
||||
}
|
||||
|
||||
// Partitions [begin, end) around pivot *begin using comparison function comp. Elements equal
|
||||
// to the pivot are put in the right-hand partition. Returns the position of the pivot after
|
||||
// partitioning and whether the passed sequence already was correctly partitioned. Assumes the
|
||||
// pivot is a median of at least 3 elements and that [begin, end) is at least
|
||||
// insertion_sort_threshold long.
|
||||
template<class Iter, class Compare>
|
||||
pdqsort_detail::pair<Iter, bool> partition_right(Iter begin, Iter end, Compare comp) {
|
||||
typedef typename boost::movelib::iterator_traits<Iter>::value_type T;
|
||||
|
||||
// Move pivot into local for speed.
|
||||
T pivot(boost::move(*begin));
|
||||
|
||||
Iter first = begin;
|
||||
Iter last = end;
|
||||
|
||||
// Find the first element greater than or equal than the pivot (the median of 3 guarantees
|
||||
// this exists).
|
||||
while (comp(*++first, pivot));
|
||||
|
||||
// Find the first element strictly smaller than the pivot. We have to guard this search if
|
||||
// there was no element before *first.
|
||||
if (first - 1 == begin) while (first < last && !comp(*--last, pivot));
|
||||
else while ( !comp(*--last, pivot));
|
||||
|
||||
// If the first pair of elements that should be swapped to partition are the same element,
|
||||
// the passed in sequence already was correctly partitioned.
|
||||
bool already_partitioned = first >= last;
|
||||
|
||||
// Keep swapping pairs of elements that are on the wrong side of the pivot. Previously
|
||||
// swapped pairs guard the searches, which is why the first iteration is special-cased
|
||||
// above.
|
||||
while (first < last) {
|
||||
boost::adl_move_iter_swap(first, last);
|
||||
while (comp(*++first, pivot));
|
||||
while (!comp(*--last, pivot));
|
||||
}
|
||||
|
||||
// Put the pivot in the right place.
|
||||
Iter pivot_pos = first - 1;
|
||||
*begin = boost::move(*pivot_pos);
|
||||
*pivot_pos = boost::move(pivot);
|
||||
|
||||
return pdqsort_detail::pair<Iter, bool>(pivot_pos, already_partitioned);
|
||||
}
|
||||
|
||||
// Similar function to the one above, except elements equal to the pivot are put to the left of
|
||||
// the pivot and it doesn't check or return if the passed sequence already was partitioned.
|
||||
// Since this is rarely used (the many equal case), and in that case pdqsort already has O(n)
|
||||
// performance, no block quicksort is applied here for simplicity.
|
||||
template<class Iter, class Compare>
|
||||
inline Iter partition_left(Iter begin, Iter end, Compare comp) {
|
||||
typedef typename boost::movelib::iterator_traits<Iter>::value_type T;
|
||||
|
||||
T pivot(boost::move(*begin));
|
||||
Iter first = begin;
|
||||
Iter last = end;
|
||||
|
||||
while (comp(pivot, *--last));
|
||||
|
||||
if (last + 1 == end) while (first < last && !comp(pivot, *++first));
|
||||
else while ( !comp(pivot, *++first));
|
||||
|
||||
while (first < last) {
|
||||
boost::adl_move_iter_swap(first, last);
|
||||
while (comp(pivot, *--last));
|
||||
while (!comp(pivot, *++first));
|
||||
}
|
||||
|
||||
Iter pivot_pos = last;
|
||||
*begin = boost::move(*pivot_pos);
|
||||
*pivot_pos = boost::move(pivot);
|
||||
|
||||
return pivot_pos;
|
||||
}
|
||||
|
||||
|
||||
template<class Iter, class Compare>
|
||||
void pdqsort_loop( Iter begin, Iter end, Compare comp
|
||||
, typename boost::movelib::iterator_traits<Iter>::size_type bad_allowed
|
||||
, bool leftmost = true)
|
||||
{
|
||||
typedef typename boost::movelib::iterator_traits<Iter>::size_type size_type;
|
||||
|
||||
// Use a while loop for tail recursion elimination.
|
||||
while (true) {
|
||||
size_type size = size_type(end - begin);
|
||||
|
||||
// Insertion sort is faster for small arrays.
|
||||
if (size < insertion_sort_threshold) {
|
||||
insertion_sort(begin, end, comp);
|
||||
return;
|
||||
}
|
||||
|
||||
// Choose pivot as median of 3 or pseudomedian of 9.
|
||||
size_type s2 = size / 2;
|
||||
if (size > ninther_threshold) {
|
||||
sort3(begin, begin + s2, end - 1, comp);
|
||||
sort3(begin + 1, begin + (s2 - 1), end - 2, comp);
|
||||
sort3(begin + 2, begin + (s2 + 1), end - 3, comp);
|
||||
sort3(begin + (s2 - 1), begin + s2, begin + (s2 + 1), comp);
|
||||
boost::adl_move_iter_swap(begin, begin + s2);
|
||||
} else sort3(begin + s2, begin, end - 1, comp);
|
||||
|
||||
// If *(begin - 1) is the end of the right partition of a previous partition operation
|
||||
// there is no element in [begin, end) that is smaller than *(begin - 1). Then if our
|
||||
// pivot compares equal to *(begin - 1) we change strategy, putting equal elements in
|
||||
// the left partition, greater elements in the right partition. We do not have to
|
||||
// recurse on the left partition, since it's sorted (all equal).
|
||||
if (!leftmost && !comp(*(begin - 1), *begin)) {
|
||||
begin = partition_left(begin, end, comp) + 1;
|
||||
continue;
|
||||
}
|
||||
|
||||
// Partition and get results.
|
||||
pdqsort_detail::pair<Iter, bool> part_result = partition_right(begin, end, comp);
|
||||
Iter pivot_pos = part_result.first;
|
||||
bool already_partitioned = part_result.second;
|
||||
|
||||
// Check for a highly unbalanced partition.
|
||||
size_type l_size = size_type(pivot_pos - begin);
|
||||
size_type r_size = size_type(end - (pivot_pos + 1));
|
||||
bool highly_unbalanced = l_size < size / 8 || r_size < size / 8;
|
||||
|
||||
// If we got a highly unbalanced partition we shuffle elements to break many patterns.
|
||||
if (highly_unbalanced) {
|
||||
// If we had too many bad partitions, switch to heapsort to guarantee O(n log n).
|
||||
if (--bad_allowed == 0) {
|
||||
boost::movelib::heap_sort(begin, end, comp);
|
||||
return;
|
||||
}
|
||||
|
||||
if (l_size >= insertion_sort_threshold) {
|
||||
boost::adl_move_iter_swap(begin, begin + l_size / 4);
|
||||
boost::adl_move_iter_swap(pivot_pos - 1, pivot_pos - l_size / 4);
|
||||
|
||||
if (l_size > ninther_threshold) {
|
||||
boost::adl_move_iter_swap(begin + 1, begin + (l_size / 4 + 1));
|
||||
boost::adl_move_iter_swap(begin + 2, begin + (l_size / 4 + 2));
|
||||
boost::adl_move_iter_swap(pivot_pos - 2, pivot_pos - (l_size / 4 + 1));
|
||||
boost::adl_move_iter_swap(pivot_pos - 3, pivot_pos - (l_size / 4 + 2));
|
||||
}
|
||||
}
|
||||
|
||||
if (r_size >= insertion_sort_threshold) {
|
||||
boost::adl_move_iter_swap(pivot_pos + 1, pivot_pos + (1 + r_size / 4));
|
||||
boost::adl_move_iter_swap(end - 1, end - r_size / 4);
|
||||
|
||||
if (r_size > ninther_threshold) {
|
||||
boost::adl_move_iter_swap(pivot_pos + 2, pivot_pos + (2 + r_size / 4));
|
||||
boost::adl_move_iter_swap(pivot_pos + 3, pivot_pos + (3 + r_size / 4));
|
||||
boost::adl_move_iter_swap(end - 2, end - (1 + r_size / 4));
|
||||
boost::adl_move_iter_swap(end - 3, end - (2 + r_size / 4));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// If we were decently balanced and we tried to sort an already partitioned
|
||||
// sequence try to use insertion sort.
|
||||
if (already_partitioned && partial_insertion_sort(begin, pivot_pos, comp)
|
||||
&& partial_insertion_sort(pivot_pos + 1, end, comp)) return;
|
||||
}
|
||||
|
||||
// Sort the left partition first using recursion and do tail recursion elimination for
|
||||
// the right-hand partition.
|
||||
pdqsort_loop<Iter, Compare>(begin, pivot_pos, comp, bad_allowed, leftmost);
|
||||
begin = pivot_pos + 1;
|
||||
leftmost = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
template<class Iter, class Compare>
|
||||
void pdqsort(Iter begin, Iter end, Compare comp)
|
||||
{
|
||||
if (begin == end) return;
|
||||
typedef typename boost::movelib::iterator_traits<Iter>::size_type size_type;
|
||||
pdqsort_detail::pdqsort_loop<Iter, Compare>(begin, end, comp, pdqsort_detail::log2(size_type(end - begin)));
|
||||
}
|
||||
|
||||
} //namespace movelib {
|
||||
} //namespace boost {
|
||||
|
||||
#include <boost/move/detail/config_end.hpp>
|
||||
|
||||
#endif //BOOST_MOVE_ALGO_PDQSORT_HPP
|
||||
207
linx64/include/boost/move/algo/detail/set_difference.hpp
Normal file
207
linx64/include/boost/move/algo/detail/set_difference.hpp
Normal file
@@ -0,0 +1,207 @@
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// (C) Copyright Ion Gaztanaga 2017-2017.
|
||||
// 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)
|
||||
//
|
||||
// See http://www.boost.org/libs/move for documentation.
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
#ifndef BOOST_MOVE_SET_DIFFERENCE_HPP
|
||||
#define BOOST_MOVE_SET_DIFFERENCE_HPP
|
||||
|
||||
#include <boost/move/algo/move.hpp>
|
||||
#include <boost/move/iterator.hpp>
|
||||
#include <boost/move/utility_core.hpp>
|
||||
|
||||
namespace boost {
|
||||
|
||||
namespace move_detail{
|
||||
|
||||
template<class InputIt, class OutputIt>
|
||||
OutputIt copy(InputIt first, InputIt last, OutputIt result)
|
||||
{
|
||||
while (first != last) {
|
||||
*result++ = *first;
|
||||
++result;
|
||||
++first;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
} //namespace move_detail{
|
||||
|
||||
namespace movelib {
|
||||
|
||||
//Moves the elements from the sorted range [first1, last1) which are not found in the sorted
|
||||
//range [first2, last2) to the range beginning at result.
|
||||
//The resulting range is also sorted. Equivalent elements are treated individually,
|
||||
//that is, if some element is found m times in [first1, last1) and n times in [first2, last2),
|
||||
//it will be moved to result exactly max(m-n, 0) times.
|
||||
//The resulting range cannot overlap with either of the input ranges.
|
||||
template<class InputIt1, class InputIt2,
|
||||
class OutputIt, class Compare>
|
||||
OutputIt set_difference
|
||||
(InputIt1 first1, InputIt1 last1, InputIt2 first2, InputIt2 last2, OutputIt result, Compare comp)
|
||||
{
|
||||
while (first1 != last1) {
|
||||
if (first2 == last2)
|
||||
return boost::move_detail::copy(first1, last1, result);
|
||||
|
||||
if (comp(*first1, *first2)) {
|
||||
*result = *first1;
|
||||
++result;
|
||||
++first1;
|
||||
}
|
||||
else {
|
||||
if (!comp(*first2, *first1)) {
|
||||
++first1;
|
||||
}
|
||||
++first2;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
//Moves the elements from the sorted range [first1, last1) which are not found in the sorted
|
||||
//range [first2, last2) to the range beginning at first1 (in place operation in range1).
|
||||
//The resulting range is also sorted. Equivalent elements are treated individually,
|
||||
//that is, if some element is found m times in [first1, last1) and n times in [first2, last2),
|
||||
//it will be moved to result exactly max(m-n, 0) times.
|
||||
template<class InputOutputIt1, class InputIt2, class Compare>
|
||||
InputOutputIt1 inplace_set_difference
|
||||
(InputOutputIt1 first1, InputOutputIt1 last1, InputIt2 first2, InputIt2 last2, Compare comp )
|
||||
{
|
||||
while (first1 != last1) {
|
||||
//Skip copying from range 1 if no element has to be skipped
|
||||
if (first2 == last2){
|
||||
return last1;
|
||||
}
|
||||
else if (comp(*first1, *first2)){
|
||||
++first1;
|
||||
}
|
||||
else{
|
||||
if (!comp(*first2, *first1)) {
|
||||
InputOutputIt1 result = first1;
|
||||
//An element from range 1 must be skipped, no longer an inplace operation
|
||||
return boost::movelib::set_difference
|
||||
( boost::make_move_iterator(++first1)
|
||||
, boost::make_move_iterator(last1)
|
||||
, ++first2, last2, result, comp);
|
||||
}
|
||||
++first2;
|
||||
}
|
||||
}
|
||||
return first1;
|
||||
}
|
||||
|
||||
//Moves the elements from the sorted range [first1, last1) which are not found in the sorted
|
||||
//range [first2, last2) to the range beginning at first1.
|
||||
//The resulting range is also sorted. Equivalent elements from range 1 are moved past to end
|
||||
//of the result,
|
||||
//that is, if some element is found m times in [first1, last1) and n times in [first2, last2),
|
||||
//it will be moved to result exactly max(m-n, 0) times.
|
||||
//The resulting range cannot overlap with either of the input ranges.
|
||||
template<class ForwardIt1, class InputIt2,
|
||||
class OutputIt, class Compare>
|
||||
OutputIt set_unique_difference
|
||||
(ForwardIt1 first1, ForwardIt1 last1, InputIt2 first2, InputIt2 last2, OutputIt result, Compare comp)
|
||||
{
|
||||
while (first1 != last1) {
|
||||
if (first2 == last2){
|
||||
//unique_copy-like sequence with forward iterators but don't write i
|
||||
//to result before comparing as moving *i could alter the value in i.
|
||||
ForwardIt1 i = first1;
|
||||
while (++first1 != last1) {
|
||||
if (comp(*i, *first1)) {
|
||||
*result = *i;
|
||||
++result;
|
||||
i = first1;
|
||||
}
|
||||
}
|
||||
*result = *i;
|
||||
++result;
|
||||
break;
|
||||
}
|
||||
|
||||
if (comp(*first1, *first2)) {
|
||||
//Skip equivalent elements in range1 but don't write i
|
||||
//to result before comparing as moving *i could alter the value in i.
|
||||
ForwardIt1 i = first1;
|
||||
while (++first1 != last1) {
|
||||
if (comp(*i, *first1)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
*result = *i;
|
||||
++result;
|
||||
}
|
||||
else {
|
||||
if (comp(*first2, *first1)) {
|
||||
++first2;
|
||||
}
|
||||
else{
|
||||
++first1;
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
//Moves the elements from the sorted range [first1, last1) which are not found in the sorted
|
||||
//range [first2, last2) to the range beginning at first1 (in place operation in range1).
|
||||
//The resulting range is also sorted. Equivalent elements are treated individually,
|
||||
//that is, if some element is found m times in [first1, last1) and n times in [first2, last2),
|
||||
//it will be moved to result exactly max(m-n, 0) times.
|
||||
template<class ForwardOutputIt1, class ForwardIt2, class Compare>
|
||||
ForwardOutputIt1 inplace_set_unique_difference
|
||||
(ForwardOutputIt1 first1, ForwardOutputIt1 last1, ForwardIt2 first2, ForwardIt2 last2, Compare comp )
|
||||
{
|
||||
while (first1 != last1) {
|
||||
//Skip copying from range 1 if no element has to be skipped
|
||||
if (first2 == last2){
|
||||
//unique-like algorithm for the remaining range 1
|
||||
ForwardOutputIt1 result = first1;
|
||||
while (++first1 != last1) {
|
||||
if (comp(*result, *first1) && ++result != first1) {
|
||||
*result = boost::move(*first1);
|
||||
}
|
||||
}
|
||||
return ++result;
|
||||
}
|
||||
else if (comp(*first2, *first1)) {
|
||||
++first2;
|
||||
}
|
||||
else if (comp(*first1, *first2)){
|
||||
//skip any adjacent equivalent elementin range 1
|
||||
ForwardOutputIt1 result = first1;
|
||||
if (++first1 != last1 && !comp(*result, *first1)) {
|
||||
//Some elements from range 1 must be skipped, no longer an inplace operation
|
||||
while (++first1 != last1 && !comp(*result, *first1)){}
|
||||
return boost::movelib::set_unique_difference
|
||||
( boost::make_move_iterator(first1)
|
||||
, boost::make_move_iterator(last1)
|
||||
, first2, last2, ++result, comp);
|
||||
}
|
||||
}
|
||||
else{
|
||||
ForwardOutputIt1 result = first1;
|
||||
//Some elements from range 1 must be skipped, no longer an inplace operation
|
||||
while (++first1 != last1 && !comp(*result, *first1)){}
|
||||
//An element from range 1 must be skipped, no longer an inplace operation
|
||||
return boost::movelib::set_unique_difference
|
||||
( boost::make_move_iterator(first1)
|
||||
, boost::make_move_iterator(last1)
|
||||
, first2, last2, result, comp);
|
||||
}
|
||||
}
|
||||
return first1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
} //namespace movelib {
|
||||
} //namespace boost {
|
||||
|
||||
#endif //#define BOOST_MOVE_SET_DIFFERENCE_HPP
|
||||
@@ -26,7 +26,8 @@
|
||||
|
||||
#include <boost/move/utility_core.hpp>
|
||||
#include <boost/move/detail/iterator_traits.hpp>
|
||||
#include <boost/detail/no_exceptions_support.hpp>
|
||||
#include <boost/move/detail/iterator_to_raw_pointer.hpp>
|
||||
#include <boost/core/no_exceptions_support.hpp>
|
||||
|
||||
namespace boost {
|
||||
|
||||
@@ -126,7 +127,7 @@ F uninitialized_move(I f, I l, F r
|
||||
}
|
||||
BOOST_CATCH(...){
|
||||
for (; back != r; ++back){
|
||||
back->~input_value_type();
|
||||
boost::movelib::iterator_to_raw_pointer(back)->~input_value_type();
|
||||
}
|
||||
BOOST_RETHROW;
|
||||
}
|
||||
|
||||
101
linx64/include/boost/move/algo/predicate.hpp
Normal file
101
linx64/include/boost/move/algo/predicate.hpp
Normal file
@@ -0,0 +1,101 @@
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// (C) Copyright Ion Gaztanaga 2015-2016.
|
||||
// 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)
|
||||
//
|
||||
// See http://www.boost.org/libs/move for documentation.
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
#ifndef BOOST_MOVE_ALGO_PREDICATE_HPP
|
||||
#define BOOST_MOVE_ALGO_PREDICATE_HPP
|
||||
|
||||
#include <boost/move/algo/move.hpp>
|
||||
#include <boost/move/adl_move_swap.hpp>
|
||||
#include <boost/move/algo/detail/basic_op.hpp>
|
||||
#include <boost/move/detail/iterator_traits.hpp>
|
||||
#include <boost/move/detail/destruct_n.hpp>
|
||||
#include <boost/assert.hpp>
|
||||
|
||||
namespace boost {
|
||||
namespace movelib {
|
||||
|
||||
template<class Comp>
|
||||
struct antistable
|
||||
{
|
||||
explicit antistable(Comp &comp)
|
||||
: m_comp(comp)
|
||||
{}
|
||||
|
||||
antistable(const antistable & other)
|
||||
: m_comp(other.m_comp)
|
||||
{}
|
||||
|
||||
template<class U, class V>
|
||||
bool operator()(const U &u, const V & v)
|
||||
{ return !m_comp(v, u); }
|
||||
|
||||
const Comp &get() const
|
||||
{ return m_comp; }
|
||||
|
||||
private:
|
||||
antistable & operator=(const antistable &);
|
||||
Comp &m_comp;
|
||||
};
|
||||
|
||||
template<class Comp>
|
||||
Comp unantistable(Comp comp)
|
||||
{ return comp; }
|
||||
|
||||
template<class Comp>
|
||||
Comp unantistable(antistable<Comp> comp)
|
||||
{ return comp.get(); }
|
||||
|
||||
template <class Comp>
|
||||
class negate
|
||||
{
|
||||
public:
|
||||
negate()
|
||||
{}
|
||||
|
||||
explicit negate(Comp comp)
|
||||
: m_comp(comp)
|
||||
{}
|
||||
|
||||
template <class T1, class T2>
|
||||
bool operator()(const T1& l, const T2& r)
|
||||
{
|
||||
return !m_comp(l, r);
|
||||
}
|
||||
|
||||
private:
|
||||
Comp m_comp;
|
||||
};
|
||||
|
||||
|
||||
template <class Comp>
|
||||
class inverse
|
||||
{
|
||||
public:
|
||||
inverse()
|
||||
{}
|
||||
|
||||
explicit inverse(Comp comp)
|
||||
: m_comp(comp)
|
||||
{}
|
||||
|
||||
template <class T1, class T2>
|
||||
bool operator()(const T1& l, const T2& r)
|
||||
{
|
||||
return m_comp(r, l);
|
||||
}
|
||||
|
||||
private:
|
||||
Comp m_comp;
|
||||
};
|
||||
|
||||
} //namespace movelib {
|
||||
} //namespace boost {
|
||||
|
||||
#endif //#define BOOST_MOVE_ALGO_PREDICATE_HPP
|
||||
55
linx64/include/boost/move/algo/unique.hpp
Normal file
55
linx64/include/boost/move/algo/unique.hpp
Normal file
@@ -0,0 +1,55 @@
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// (C) Copyright Ion Gaztanaga 2017-2017.
|
||||
// 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)
|
||||
//
|
||||
// See http://www.boost.org/libs/move for documentation.
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef BOOST_MOVE_ALGO_UNIQUE_HPP
|
||||
#define BOOST_MOVE_ALGO_UNIQUE_HPP
|
||||
|
||||
#include <boost/move/detail/config_begin.hpp>
|
||||
#include <boost/move/utility_core.hpp>
|
||||
|
||||
namespace boost {
|
||||
namespace movelib {
|
||||
|
||||
//! <b>Requires</b>: The comparison function shall be an equivalence relation. The type of *first shall satisfy
|
||||
//! the MoveAssignable requirements
|
||||
//!
|
||||
//! <b>Effects</b>: For a nonempty range, eliminates all but the first element from every consecutive group
|
||||
//! of equivalent elements referred to by the iterator i in the range [first + 1, last) for which the
|
||||
//! following conditions hold: pred(*(i - 1), *i) != false.
|
||||
//!
|
||||
//! <b>Returns</b>: The end of the resulting range.
|
||||
//!
|
||||
//! <b>Complexity</b>: For nonempty ranges, exactly (last - first) - 1 applications of the corresponding predicate.
|
||||
template<class ForwardIterator, class BinaryPredicate>
|
||||
ForwardIterator unique(ForwardIterator first, ForwardIterator last, BinaryPredicate pred)
|
||||
{
|
||||
if (first != last) {
|
||||
ForwardIterator next(first);
|
||||
++next;
|
||||
for (; next != last; ++next, ++first) {
|
||||
if (pred(*first, *next)) { //Find first equal element
|
||||
while (++next != last)
|
||||
if (!pred(*first, *next))
|
||||
*++first = ::boost::move(*next);
|
||||
break;
|
||||
}
|
||||
}
|
||||
++first;
|
||||
}
|
||||
return first;
|
||||
}
|
||||
|
||||
} //namespace movelib {
|
||||
} //namespace boost {
|
||||
|
||||
#include <boost/move/detail/config_end.hpp>
|
||||
|
||||
#endif //#define BOOST_MOVE_ALGO_UNIQUE_HPP
|
||||
@@ -27,7 +27,7 @@
|
||||
#include <boost/move/utility_core.hpp>
|
||||
#include <boost/move/iterator.hpp>
|
||||
#include <boost/move/algo/move.hpp>
|
||||
#include <boost/detail/no_exceptions_support.hpp>
|
||||
#include <boost/core/no_exceptions_support.hpp>
|
||||
|
||||
#include <algorithm> //copy, copy_backward
|
||||
#include <memory> //uninitialized_copy
|
||||
|
||||
@@ -57,21 +57,13 @@
|
||||
|
||||
#include <boost/move/detail/type_traits.hpp>
|
||||
|
||||
#if defined(BOOST_MOVE_ADDRESS_SANITIZER_ON)
|
||||
#define BOOST_MOVE_TO_RV_CAST(RV_TYPE, ARG) reinterpret_cast<RV_TYPE>(ARG)
|
||||
#else
|
||||
#define BOOST_MOVE_TO_RV_CAST(RV_TYPE, ARG) static_cast<RV_TYPE>(ARG)
|
||||
#endif
|
||||
#define BOOST_MOVE_TO_RV_CAST(RV_TYPE, ARG) reinterpret_cast<RV_TYPE>(ARG)
|
||||
|
||||
//Move emulation rv breaks standard aliasing rules so add workarounds for some compilers
|
||||
#if defined(__GNUC__) && (__GNUC__ >= 4) && \
|
||||
(\
|
||||
defined(BOOST_GCC) || \
|
||||
(defined(BOOST_INTEL) && (BOOST_INTEL_CXX_VERSION >= 1300)) \
|
||||
)
|
||||
#define BOOST_MOVE_ATTRIBUTE_MAY_ALIAS __attribute__((__may_alias__))
|
||||
#if defined(BOOST_GCC) && (BOOST_GCC >= 40400) && (BOOST_GCC < 40500)
|
||||
#define BOOST_RV_ATTRIBUTE_MAY_ALIAS BOOST_MAY_ALIAS
|
||||
#else
|
||||
#define BOOST_MOVE_ATTRIBUTE_MAY_ALIAS
|
||||
#define BOOST_RV_ATTRIBUTE_MAY_ALIAS
|
||||
#endif
|
||||
|
||||
namespace boost {
|
||||
@@ -82,7 +74,7 @@
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
template <class T>
|
||||
class rv
|
||||
class BOOST_RV_ATTRIBUTE_MAY_ALIAS rv
|
||||
: public ::boost::move_detail::if_c
|
||||
< ::boost::move_detail::is_class<T>::value
|
||||
, T
|
||||
@@ -93,7 +85,7 @@
|
||||
~rv() throw();
|
||||
rv(rv const&);
|
||||
void operator=(rv const&);
|
||||
} BOOST_MOVE_ATTRIBUTE_MAY_ALIAS;
|
||||
};
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
@@ -27,11 +27,11 @@
|
||||
namespace boost {
|
||||
namespace movelib{
|
||||
|
||||
template<class T>
|
||||
template<class T, class RandItUninit>
|
||||
class destruct_n
|
||||
{
|
||||
public:
|
||||
explicit destruct_n(T *raw)
|
||||
explicit destruct_n(RandItUninit raw)
|
||||
: m_ptr(raw), m_size()
|
||||
{}
|
||||
|
||||
@@ -48,7 +48,6 @@ class destruct_n
|
||||
void release()
|
||||
{
|
||||
m_size = 0u;
|
||||
m_ptr = 0;
|
||||
}
|
||||
|
||||
~destruct_n()
|
||||
@@ -58,7 +57,7 @@ class destruct_n
|
||||
}
|
||||
}
|
||||
private:
|
||||
T *m_ptr;
|
||||
RandItUninit m_ptr;
|
||||
std::size_t m_size;
|
||||
};
|
||||
|
||||
|
||||
@@ -458,6 +458,31 @@ namespace move_detail {
|
||||
#define BOOST_MOVE_CLASSDFLTQ8 BOOST_MOVE_CLASSDFLTQ7, class Q7 = void
|
||||
#define BOOST_MOVE_CLASSDFLTQ9 BOOST_MOVE_CLASSDFLTQ8, class Q8 = void
|
||||
|
||||
//BOOST_MOVE_LAST_TARGN
|
||||
#define BOOST_MOVE_LAST_TARG0 void
|
||||
#define BOOST_MOVE_LAST_TARG1 P0
|
||||
#define BOOST_MOVE_LAST_TARG2 P1
|
||||
#define BOOST_MOVE_LAST_TARG3 P2
|
||||
#define BOOST_MOVE_LAST_TARG4 P3
|
||||
#define BOOST_MOVE_LAST_TARG5 P4
|
||||
#define BOOST_MOVE_LAST_TARG6 P5
|
||||
#define BOOST_MOVE_LAST_TARG7 P6
|
||||
#define BOOST_MOVE_LAST_TARG8 P7
|
||||
#define BOOST_MOVE_LAST_TARG9 P8
|
||||
|
||||
//BOOST_MOVE_LAST_TARGQN
|
||||
#define BOOST_MOVE_LAST_TARGQ0 void
|
||||
#define BOOST_MOVE_LAST_TARGQ1 Q0
|
||||
#define BOOST_MOVE_LAST_TARGQ2 Q1
|
||||
#define BOOST_MOVE_LAST_TARGQ3 Q2
|
||||
#define BOOST_MOVE_LAST_TARGQ4 Q3
|
||||
#define BOOST_MOVE_LAST_TARGQ5 Q4
|
||||
#define BOOST_MOVE_LAST_TARGQ6 Q5
|
||||
#define BOOST_MOVE_LAST_TARGQ7 Q6
|
||||
#define BOOST_MOVE_LAST_TARGQ8 Q7
|
||||
#define BOOST_MOVE_LAST_TARGQ9 Q8
|
||||
|
||||
|
||||
//BOOST_MOVE_TARGN
|
||||
#define BOOST_MOVE_TARG0
|
||||
#define BOOST_MOVE_TARG1 P0
|
||||
|
||||
59
linx64/include/boost/move/detail/iterator_to_raw_pointer.hpp
Normal file
59
linx64/include/boost/move/detail/iterator_to_raw_pointer.hpp
Normal file
@@ -0,0 +1,59 @@
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// (C) Copyright Ion Gaztanaga 2014-2015. 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)
|
||||
//
|
||||
// See http://www.boost.org/libs/container for documentation.
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
#ifndef BOOST_MOVE_DETAIL_ITERATOR_TO_RAW_POINTER_HPP
|
||||
#define BOOST_MOVE_DETAIL_ITERATOR_TO_RAW_POINTER_HPP
|
||||
|
||||
#ifndef BOOST_CONFIG_HPP
|
||||
# include <boost/config.hpp>
|
||||
#endif
|
||||
|
||||
#if defined(BOOST_HAS_PRAGMA_ONCE)
|
||||
# pragma once
|
||||
#endif
|
||||
|
||||
#include <boost/move/detail/iterator_traits.hpp>
|
||||
#include <boost/move/detail/to_raw_pointer.hpp>
|
||||
#include <boost/move/detail/pointer_element.hpp>
|
||||
|
||||
namespace boost {
|
||||
namespace movelib {
|
||||
namespace detail {
|
||||
|
||||
template <class T>
|
||||
inline T* iterator_to_pointer(T* i)
|
||||
{ return i; }
|
||||
|
||||
template <class Iterator>
|
||||
inline typename boost::movelib::iterator_traits<Iterator>::pointer
|
||||
iterator_to_pointer(const Iterator &i)
|
||||
{ return i.operator->(); }
|
||||
|
||||
template <class Iterator>
|
||||
struct iterator_to_element_ptr
|
||||
{
|
||||
typedef typename boost::movelib::iterator_traits<Iterator>::pointer pointer;
|
||||
typedef typename boost::movelib::pointer_element<pointer>::type element_type;
|
||||
typedef element_type* type;
|
||||
};
|
||||
|
||||
} //namespace detail {
|
||||
|
||||
template <class Iterator>
|
||||
inline typename boost::movelib::detail::iterator_to_element_ptr<Iterator>::type
|
||||
iterator_to_raw_pointer(const Iterator &i)
|
||||
{
|
||||
return ::boost::movelib::to_raw_pointer
|
||||
( ::boost::movelib::detail::iterator_to_pointer(i) );
|
||||
}
|
||||
|
||||
} //namespace movelib {
|
||||
} //namespace boost {
|
||||
|
||||
#endif //#ifndef BOOST_MOVE_DETAIL_ITERATOR_TO_RAW_POINTER_HPP
|
||||
@@ -67,6 +67,8 @@ typedef bool_<false> false_;
|
||||
// nat
|
||||
//////////////////////////////////////
|
||||
struct nat{};
|
||||
struct nat2{};
|
||||
struct nat3{};
|
||||
|
||||
//////////////////////////////////////
|
||||
// yes_type/no_type
|
||||
|
||||
@@ -27,6 +27,9 @@
|
||||
namespace boost {
|
||||
namespace move_detail {
|
||||
|
||||
template<typename T>
|
||||
struct voider { typedef void type; };
|
||||
|
||||
//////////////////////////////////////
|
||||
// if_c
|
||||
//////////////////////////////////////
|
||||
@@ -52,7 +55,9 @@ struct if_ : if_c<0 != T1::value, T2, T3>
|
||||
//////////////////////////////////////
|
||||
// enable_if_c
|
||||
//////////////////////////////////////
|
||||
template <bool B, class T = void>
|
||||
struct enable_if_nat{};
|
||||
|
||||
template <bool B, class T = enable_if_nat>
|
||||
struct enable_if_c
|
||||
{
|
||||
typedef T type;
|
||||
@@ -64,13 +69,13 @@ struct enable_if_c<false, T> {};
|
||||
//////////////////////////////////////
|
||||
// enable_if
|
||||
//////////////////////////////////////
|
||||
template <class Cond, class T = void>
|
||||
template <class Cond, class T = enable_if_nat>
|
||||
struct enable_if : enable_if_c<Cond::value, T> {};
|
||||
|
||||
//////////////////////////////////////
|
||||
// disable_if_c
|
||||
//////////////////////////////////////
|
||||
template <bool B, class T = void>
|
||||
template <bool B, class T = enable_if_nat>
|
||||
struct disable_if_c
|
||||
: enable_if_c<!B, T>
|
||||
{};
|
||||
@@ -78,7 +83,7 @@ struct disable_if_c
|
||||
//////////////////////////////////////
|
||||
// disable_if
|
||||
//////////////////////////////////////
|
||||
template <class Cond, class T = void>
|
||||
template <class Cond, class T = enable_if_nat>
|
||||
struct disable_if : enable_if_c<!Cond::value, T> {};
|
||||
|
||||
//////////////////////////////////////
|
||||
@@ -117,13 +122,13 @@ struct is_same<T, T>
|
||||
//////////////////////////////////////
|
||||
// enable_if_same
|
||||
//////////////////////////////////////
|
||||
template <class T, class U, class R = void>
|
||||
template <class T, class U, class R = enable_if_nat>
|
||||
struct enable_if_same : enable_if<is_same<T, U>, R> {};
|
||||
|
||||
//////////////////////////////////////
|
||||
// disable_if_same
|
||||
//////////////////////////////////////
|
||||
template <class T, class U, class R = void>
|
||||
template <class T, class U, class R = enable_if_nat>
|
||||
struct disable_if_same : disable_if<is_same<T, U>, R> {};
|
||||
|
||||
} //namespace move_detail {
|
||||
|
||||
168
linx64/include/boost/move/detail/pointer_element.hpp
Normal file
168
linx64/include/boost/move/detail/pointer_element.hpp
Normal file
@@ -0,0 +1,168 @@
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// (C) Copyright Ion Gaztanaga 2014-2017. 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)
|
||||
//
|
||||
// See http://www.boost.org/libs/move for documentation.
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef BOOST_MOVE_DETAIL_POINTER_ELEMENT_HPP
|
||||
#define BOOST_MOVE_DETAIL_POINTER_ELEMENT_HPP
|
||||
|
||||
#ifndef BOOST_CONFIG_HPP
|
||||
# include <boost/config.hpp>
|
||||
#endif
|
||||
|
||||
#if defined(BOOST_HAS_PRAGMA_ONCE)
|
||||
# pragma once
|
||||
#endif
|
||||
|
||||
#ifndef BOOST_MOVE_DETAIL_WORKAROUND_HPP
|
||||
#include <boost/move/detail/workaround.hpp>
|
||||
#endif //BOOST_MOVE_DETAIL_WORKAROUND_HPP
|
||||
|
||||
namespace boost {
|
||||
namespace movelib {
|
||||
namespace detail{
|
||||
|
||||
//////////////////////
|
||||
//struct first_param
|
||||
//////////////////////
|
||||
|
||||
template <typename T> struct first_param
|
||||
{ typedef void type; };
|
||||
|
||||
#if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
|
||||
|
||||
template <template <typename, typename...> class TemplateClass, typename T, typename... Args>
|
||||
struct first_param< TemplateClass<T, Args...> >
|
||||
{
|
||||
typedef T type;
|
||||
};
|
||||
|
||||
#else //C++03 compilers
|
||||
|
||||
template < template //0arg
|
||||
<class
|
||||
> class TemplateClass, class T
|
||||
>
|
||||
struct first_param
|
||||
< TemplateClass<T> >
|
||||
{ typedef T type; };
|
||||
|
||||
template < template //1arg
|
||||
<class,class
|
||||
> class TemplateClass, class T
|
||||
, class P0>
|
||||
struct first_param
|
||||
< TemplateClass<T, P0> >
|
||||
{ typedef T type; };
|
||||
|
||||
template < template //2arg
|
||||
<class,class,class
|
||||
> class TemplateClass, class T
|
||||
, class P0, class P1>
|
||||
struct first_param
|
||||
< TemplateClass<T, P0, P1> >
|
||||
{ typedef T type; };
|
||||
|
||||
template < template //3arg
|
||||
<class,class,class,class
|
||||
> class TemplateClass, class T
|
||||
, class P0, class P1, class P2>
|
||||
struct first_param
|
||||
< TemplateClass<T, P0, P1, P2> >
|
||||
{ typedef T type; };
|
||||
|
||||
template < template //4arg
|
||||
<class,class,class,class,class
|
||||
> class TemplateClass, class T
|
||||
, class P0, class P1, class P2, class P3>
|
||||
struct first_param
|
||||
< TemplateClass<T, P0, P1, P2, P3> >
|
||||
{ typedef T type; };
|
||||
|
||||
template < template //5arg
|
||||
<class,class,class,class,class,class
|
||||
> class TemplateClass, class T
|
||||
, class P0, class P1, class P2, class P3, class P4>
|
||||
struct first_param
|
||||
< TemplateClass<T, P0, P1, P2, P3, P4> >
|
||||
{ typedef T type; };
|
||||
|
||||
template < template //6arg
|
||||
<class,class,class,class,class,class,class
|
||||
> class TemplateClass, class T
|
||||
, class P0, class P1, class P2, class P3, class P4, class P5>
|
||||
struct first_param
|
||||
< TemplateClass<T, P0, P1, P2, P3, P4, P5> >
|
||||
{ typedef T type; };
|
||||
|
||||
template < template //7arg
|
||||
<class,class,class,class,class,class,class,class
|
||||
> class TemplateClass, class T
|
||||
, class P0, class P1, class P2, class P3, class P4, class P5, class P6>
|
||||
struct first_param
|
||||
< TemplateClass<T, P0, P1, P2, P3, P4, P5, P6> >
|
||||
{ typedef T type; };
|
||||
|
||||
template < template //8arg
|
||||
<class,class,class,class,class,class,class,class,class
|
||||
> class TemplateClass, class T
|
||||
, class P0, class P1, class P2, class P3, class P4, class P5, class P6, class P7>
|
||||
struct first_param
|
||||
< TemplateClass<T, P0, P1, P2, P3, P4, P5, P6, P7> >
|
||||
{ typedef T type; };
|
||||
|
||||
template < template //9arg
|
||||
<class,class,class,class,class,class,class,class,class,class
|
||||
> class TemplateClass, class T
|
||||
, class P0, class P1, class P2, class P3, class P4, class P5, class P6, class P7, class P8>
|
||||
struct first_param
|
||||
< TemplateClass<T, P0, P1, P2, P3, P4, P5, P6, P7, P8> >
|
||||
{ typedef T type; };
|
||||
|
||||
#endif //!defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
|
||||
|
||||
template <typename T>
|
||||
struct has_internal_pointer_element
|
||||
{
|
||||
template <typename X>
|
||||
static char test(int, typename X::element_type*);
|
||||
|
||||
template <typename X>
|
||||
static int test(...);
|
||||
|
||||
static const bool value = (1 == sizeof(test<T>(0, 0)));
|
||||
};
|
||||
|
||||
template<class Ptr, bool = has_internal_pointer_element<Ptr>::value>
|
||||
struct pointer_element_impl
|
||||
{
|
||||
typedef typename Ptr::element_type type;
|
||||
};
|
||||
|
||||
template<class Ptr>
|
||||
struct pointer_element_impl<Ptr, false>
|
||||
{
|
||||
typedef typename boost::movelib::detail::first_param<Ptr>::type type;
|
||||
};
|
||||
|
||||
} //namespace detail{
|
||||
|
||||
template <typename Ptr>
|
||||
struct pointer_element
|
||||
{
|
||||
typedef typename ::boost::movelib::detail::pointer_element_impl<Ptr>::type type;
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
struct pointer_element<T*>
|
||||
{ typedef T type; };
|
||||
|
||||
} //namespace movelib {
|
||||
} //namespace boost {
|
||||
|
||||
#endif // defined(BOOST_MOVE_DETAIL_POINTER_ELEMENT_HPP)
|
||||
45
linx64/include/boost/move/detail/to_raw_pointer.hpp
Normal file
45
linx64/include/boost/move/detail/to_raw_pointer.hpp
Normal file
@@ -0,0 +1,45 @@
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// (C) Copyright Ion Gaztanaga 2017-2017
|
||||
//
|
||||
// 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)
|
||||
//
|
||||
// See http://www.boost.org/libs/move for documentation.
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef BOOST_MOVE_DETAIL_TO_RAW_POINTER_HPP
|
||||
#define BOOST_MOVE_DETAIL_TO_RAW_POINTER_HPP
|
||||
|
||||
#ifndef BOOST_CONFIG_HPP
|
||||
# include <boost/config.hpp>
|
||||
#endif
|
||||
|
||||
#if defined(BOOST_HAS_PRAGMA_ONCE)
|
||||
# pragma once
|
||||
#endif
|
||||
|
||||
#include <boost/move/detail/config_begin.hpp>
|
||||
#include <boost/move/detail/workaround.hpp>
|
||||
#include <boost/move/detail/pointer_element.hpp>
|
||||
|
||||
namespace boost {
|
||||
namespace movelib {
|
||||
|
||||
template <class T>
|
||||
BOOST_MOVE_FORCEINLINE T* to_raw_pointer(T* p)
|
||||
{ return p; }
|
||||
|
||||
template <class Pointer>
|
||||
BOOST_MOVE_FORCEINLINE typename boost::movelib::pointer_element<Pointer>::type*
|
||||
to_raw_pointer(const Pointer &p)
|
||||
{ return ::boost::movelib::to_raw_pointer(p.operator->()); }
|
||||
|
||||
} //namespace movelib
|
||||
} //namespace boost
|
||||
|
||||
#include <boost/move/detail/config_end.hpp>
|
||||
|
||||
#endif //BOOST_MOVE_DETAIL_TO_RAW_POINTER_HPP
|
||||
@@ -967,14 +967,13 @@ typedef union max_align max_align_t;
|
||||
#if !defined(BOOST_NO_ALIGNMENT)
|
||||
|
||||
template<std::size_t Len, std::size_t Align>
|
||||
struct aligned_storage_impl;
|
||||
struct aligned_struct;
|
||||
|
||||
#define BOOST_MOVE_ALIGNED_STORAGE_WITH_BOOST_ALIGNMENT(A)\
|
||||
template<std::size_t Len>\
|
||||
struct BOOST_ALIGNMENT(A) aligned_storage_impl<Len, A>\
|
||||
struct BOOST_ALIGNMENT(A) aligned_struct<Len, A>\
|
||||
{\
|
||||
char dummy[Len];\
|
||||
typedef aligned_storage_impl<Len, A> type;\
|
||||
unsigned char data[Len];\
|
||||
};\
|
||||
//
|
||||
|
||||
@@ -995,13 +994,28 @@ BOOST_MOVE_ALIGNED_STORAGE_WITH_BOOST_ALIGNMENT(0x1000)
|
||||
|
||||
#undef BOOST_MOVE_ALIGNED_STORAGE_WITH_BOOST_ALIGNMENT
|
||||
|
||||
// Workaround for bogus [-Wignored-attributes] warning on GCC 6.x/7.x: don't use a type that "directly" carries the alignment attribute.
|
||||
// See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82270
|
||||
template<std::size_t Len, std::size_t Align>
|
||||
union aligned_struct_wrapper
|
||||
{
|
||||
aligned_struct<Len, Align> aligner;
|
||||
unsigned char data[sizeof(aligned_struct<Len, Align>)];
|
||||
};
|
||||
|
||||
template<std::size_t Len, std::size_t Align>
|
||||
struct aligned_storage_impl
|
||||
{
|
||||
typedef aligned_struct_wrapper<Len, Align> type;
|
||||
};
|
||||
|
||||
#else //BOOST_NO_ALIGNMENT
|
||||
|
||||
template<class T, std::size_t Len>
|
||||
union aligned_union
|
||||
{
|
||||
T aligner;
|
||||
char dummy[Len];
|
||||
unsigned char data[Len];
|
||||
};
|
||||
|
||||
template<std::size_t Len, std::size_t Align, class T, bool Ok>
|
||||
|
||||
@@ -446,7 +446,7 @@ class is_convertible
|
||||
#define BOOST_MOVE_TT_DECL
|
||||
#endif
|
||||
|
||||
#if defined(_MSC_EXTENSIONS) && !defined(__BORLAND__) && !defined(_WIN64) && !defined(_M_ARM) && !defined(UNDER_CE)
|
||||
#if defined(_MSC_EXTENSIONS) && !defined(__BORLAND__) && !defined(_WIN64) && !defined(_M_ARM) && !defined(_M_ARM64) && !defined(UNDER_CE)
|
||||
#define BOOST_MOVE_TT_TEST_MSC_FUNC_SIGS
|
||||
#endif
|
||||
|
||||
|
||||
Reference in New Issue
Block a user