1
0
forked from boostorg/move

Remove -Wconversion warnings

This commit is contained in:
Ion Gaztañaga
2021-10-05 23:30:54 +02:00
parent 6ab49a8d82
commit 122a84b366
9 changed files with 89 additions and 59 deletions

View File

@ -138,7 +138,7 @@ inline static SizeType adaptive_merge_n_keys_with_external_keys(SizeType l_block
{
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;
size_type n_keys = size_type((len1-l_intbuf)/l_block + len2/l_block);
return n_keys;
}
@ -223,7 +223,7 @@ void adaptive_merge_impl
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);
buffered_merge(first, first+len1, first + size_type(len1+len2), comp, xbuf);
}
else{
const size_type len = len1+len2;
@ -233,7 +233,7 @@ void adaptive_merge_impl
//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);
merge_bufferless(first, first+len1, first + size_type(len1+len2), comp);
return;
}
@ -249,7 +249,7 @@ void adaptive_merge_impl
//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);
merge_bufferless(first, first + len1, first + size_type(len1 + len2), comp);
return;
}

View File

@ -178,7 +178,7 @@ void adaptive_sort_combine_blocks
boost::ignore_unused(l_total_combined);
BOOST_ASSERT(l_total_combined <= len);
size_type const max_i = n_reg_combined + (l_irreg_combined != 0);
size_type const max_i = size_type(n_reg_combined + (l_irreg_combined != 0));
if(merge_left || !use_buf) {
for( size_type combined_i = 0; combined_i != max_i; ) {
@ -209,7 +209,7 @@ void adaptive_sort_combine_blocks
}
}
else{
combined_first += l_reg_combined*(max_i-1);
combined_first += size_type(l_reg_combined*(max_i-1u));
for( size_type combined_i = max_i; combined_i; ) {
--combined_i;
bool const is_last = combined_i==n_reg_combined;
@ -299,7 +299,7 @@ bool adaptive_sort_combine_all_blocks
//Combine to form l_merged*2 segments
if(n_keys){
size_type upper_n_keys_this_iter = 2*l_merged/l_block;
size_type upper_n_keys_this_iter = size_type(2u*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
@ -416,7 +416,8 @@ bool adaptive_sort_build_params
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)){
if(xbuf.template supports_aligned_trailing<size_type>
(l_intbuf, size_type((len-l_intbuf-1u)/l_intbuf+1u))){
n_keys = 0u;
l_build_buf = l_intbuf;
}
@ -455,8 +456,8 @@ bool adaptive_sort_build_params
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 & (n_keys-1u)){
n_keys &= size_type(n_keys-1u); // make it power or 2
}
while(n_keys > collected){
n_keys/=2;
@ -569,7 +570,9 @@ void adaptive_sort_impl
//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);
( first + size_type(n_key_plus_buf-l_build_buf)
, size_type(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

View File

@ -285,8 +285,8 @@ typename iterator_traits<RandIt>::size_type
BOOST_ASSERT(ix_first_block <= ix_last_block);
size_type ix_min_block = 0u;
for (size_type szt_i = ix_first_block; szt_i < ix_last_block; ++szt_i) {
const value_type &min_val = first[ix_min_block*l_block];
const value_type &cur_val = first[szt_i*l_block];
const value_type &min_val = first[size_type(ix_min_block*l_block)];
const value_type &cur_val = first[size_type(szt_i*l_block)];
const key_type &min_key = key_first[ix_min_block];
const key_type &cur_key = key_first[szt_i];
@ -322,7 +322,7 @@ void merge_blocks_bufferless
size_type n_bef_irreg2 = 0;
bool l_irreg_pos_count = true;
RandItKeys key_mid(key_first + n_block_a);
RandIt const first_irr2 = first + l_irreg1 + (n_block_a+n_block_b)*l_block;
RandIt const first_irr2 = first + size_type(l_irreg1 + (n_block_a+n_block_b)*l_block);
RandIt const last_irr2 = first_irr2 + l_irreg2;
{ //Selection sort blocks
@ -331,12 +331,12 @@ void merge_blocks_bufferless
size_type min_check = n_block_a == n_block_left ? 0u : n_block_a;
size_type max_check = min_value<size_type>(min_check+1, n_block_left);
for (RandIt f = first+l_irreg1; n_block_left; --n_block_left, ++key_range2, f += l_block, min_check -= min_check != 0, max_check -= max_check != 0) {
for ( RandIt f = first+l_irreg1; n_block_left; --n_block_left) {
size_type const next_key_idx = find_next_block(key_range2, key_comp, f, l_block, min_check, max_check, comp);
RandItKeys const key_next(key_range2 + next_key_idx);
max_check = min_value<size_type>(max_value<size_type>(max_check, next_key_idx+size_type(2)), n_block_left);
max_check = min_value<size_type>(max_value<size_type>(max_check, size_type(next_key_idx+2)), n_block_left);
RandIt const first_min = f + next_key_idx*l_block;
RandIt const first_min = f + size_type(next_key_idx*l_block);
//Check if irregular b block should go here.
//If so, break to the special code handling the irregular block
@ -349,6 +349,11 @@ void merge_blocks_bufferless
BOOST_MOVE_ADAPTIVE_SORT_INVARIANT(boost::movelib::is_sorted(f, f+l_block, comp));
BOOST_MOVE_ADAPTIVE_SORT_INVARIANT(boost::movelib::is_sorted(first_min, first_min + l_block, comp));
BOOST_MOVE_ADAPTIVE_SORT_INVARIANT((f == (first+l_irreg1)) || !comp(*f, *(f-l_block)));
//Update context
++key_range2;
f += l_block;
min_check = size_type(min_check - (min_check != 0));
max_check = size_type(max_check - (max_check != 0));
}
}
BOOST_MOVE_ADAPTIVE_SORT_INVARIANT(boost::movelib::is_sorted(first+l_irreg1+n_bef_irreg2*l_block, first_irr2, comp));
@ -436,7 +441,7 @@ Unsigned floor_sqrt(Unsigned const n)
Unsigned y = x/2 + (x&1);
while (y < x){
x = y;
y = (x + n / x)/2;
y = Unsigned((x + n / x)/2U);
}
return x;
}
@ -445,7 +450,7 @@ template<class Unsigned>
Unsigned ceil_sqrt(Unsigned const n)
{
Unsigned r = floor_sqrt(n);
return r + Unsigned((n%r) != 0);
return Unsigned(r + Unsigned((n%r) != 0));
}
template<class Unsigned>
@ -459,7 +464,7 @@ Unsigned floor_merge_multiple(Unsigned const n, Unsigned &base, Unsigned &pow)
}
base = s;
pow = p;
return s << p;
return Unsigned(s << p);
}
template<class Unsigned>
@ -476,7 +481,7 @@ Unsigned ceil_merge_multiple(Unsigned const n, Unsigned &base, Unsigned &pow)
++pow;
}
}
return base << pow;
return Unsigned(base << pow);
}
template<class Unsigned>
@ -688,10 +693,10 @@ void combine_params
typedef SizeType size_type;
//Initial parameters for selection sort blocks
l_irreg1 = l_prev_merged%l_block;
l_irreg2 = (l_combined-l_irreg1)%l_block;
l_irreg1 = size_type(l_prev_merged%l_block);
l_irreg2 = size_type((l_combined-l_irreg1)%l_block);
BOOST_ASSERT(((l_combined-l_irreg1-l_irreg2)%l_block) == 0);
size_type const n_reg_block = (l_combined-l_irreg1-l_irreg2)/l_block;
size_type const n_reg_block = size_type((l_combined-l_irreg1-l_irreg2)/l_block);
n_block_a = l_prev_merged/l_block;
n_block_b = n_reg_block - n_block_a;
BOOST_ASSERT(n_reg_block>=n_block_a);
@ -941,11 +946,11 @@ OutputIt op_merge_blocks_with_irreg
{
typedef typename iterator_traits<RandIt>::size_type size_type;
for(; n_block_left; --n_block_left, ++key_first, min_check -= min_check != 0, max_check -= max_check != 0){
for(; n_block_left; --n_block_left){
size_type next_key_idx = find_next_block(key_first, key_comp, first_reg, l_block, min_check, max_check, comp);
max_check = min_value<size_type>(max_value<size_type>(max_check, next_key_idx+size_type(2)), n_block_left);
RandIt const last_reg = first_reg + l_block;
RandIt first_min = first_reg + next_key_idx*l_block;
RandIt first_min = first_reg + size_type(next_key_idx*l_block);
RandIt const last_min = first_min + l_block;
boost::ignore_unused(last_min);
@ -973,6 +978,9 @@ OutputIt op_merge_blocks_with_irreg
BOOST_MOVE_ADAPTIVE_SORT_INVARIANT(boost::movelib::is_sorted(orig_dest, dest, comp));
first_reg = last_reg;
++key_first;
min_check = size_type(min_check - (min_check != 0));
max_check = size_type(max_check - (max_check != 0));
}
return dest;
}
@ -1016,7 +1024,7 @@ void op_merge_blocks_left
RandIt first1 = first;
RandIt last1 = first1 + l_irreg1;
RandIt first2 = last1;
RandIt const irreg2 = first2 + n_block_left*l_block;
RandIt const irreg2 = first2 + size_type(n_block_left*l_block);
bool is_range1_A = true;
RandItKeys key_range2(key_first);
@ -1026,10 +1034,10 @@ void op_merge_blocks_left
////////////////////////////////////////////////////////////////////////////
size_type min_check = n_block_a == n_block_left ? 0u : n_block_a;
size_type max_check = min_value<size_type>(min_check+size_type(1), n_block_left);
for (; n_block_left; --n_block_left, ++key_range2, min_check -= min_check != 0, max_check -= max_check != 0) {
for (; n_block_left; --n_block_left) {
size_type const next_key_idx = find_next_block(key_range2, key_comp, first2, l_block, min_check, max_check, comp);
max_check = min_value<size_type>(max_value<size_type>(max_check, next_key_idx+size_type(2)), n_block_left);
RandIt const first_min = first2 + next_key_idx*l_block;
RandIt const first_min = first2 + size_type(next_key_idx*l_block);
RandIt const last_min = first_min + l_block;
boost::ignore_unused(last_min);
@ -1100,6 +1108,10 @@ void op_merge_blocks_left
BOOST_MOVE_ADAPTIVE_SORT_INVARIANT( (is_range2_A && n_block_a_left) || (!is_range2_A && n_block_b_left));
is_range2_A ? --n_block_a_left : --n_block_b_left;
first2 = last2;
//Update context
++key_range2;
min_check = size_type(min_check - (min_check != 0));
max_check = size_type(max_check - (max_check != 0));
}
BOOST_MOVE_ADAPTIVE_SORT_INVARIANT(!n_block_b || n_block_a == count_if_with(key_first, key_range2 + n_block_left, key_comp, *key_mid));
@ -1191,10 +1203,11 @@ void merge_blocks_right
, Compare comp
, bool const xbuf_used)
{
typedef typename iterator_traits<RandIt>::size_type size_type;
merge_blocks_left
( (make_reverse_iterator)(key_first + needed_keys_count(n_block_a, n_block_b))
, inverse<KeyCompare>(key_comp)
, (make_reverse_iterator)(first + ((n_block_a+n_block_b)*l_block+l_irreg2))
, (make_reverse_iterator)(first + size_type((n_block_a+n_block_b)*l_block+l_irreg2))
, l_block
, l_irreg2
, n_block_b
@ -1235,7 +1248,7 @@ void op_merge_blocks_with_buf
size_type n_block_b_left = n_block_b;
size_type n_block_a_left = n_block_a;
size_type n_block_left = n_block_b + n_block_a;
size_type n_block_left = size_type(n_block_b + n_block_a);
RandItKeys key_mid(key_first + n_block_a);
RandItBuf buffer = buf_first;
@ -1243,9 +1256,9 @@ void op_merge_blocks_with_buf
RandIt first1 = first;
RandIt last1 = first1 + l_irreg1;
RandIt first2 = last1;
RandIt const first_irr2 = first2 + n_block_left*l_block;
RandIt const first_irr2 = first2 + size_type(n_block_left*l_block);
bool is_range1_A = true;
const size_type len = l_block * n_block_a + l_block * n_block_b + l_irreg1 + l_irreg2;
const size_type len = size_type(l_block * n_block_a + l_block * n_block_b + l_irreg1 + l_irreg2);
boost::ignore_unused(len);
RandItKeys key_range2(key_first);
@ -1255,10 +1268,10 @@ void op_merge_blocks_with_buf
////////////////////////////////////////////////////////////////////////////
size_type min_check = n_block_a == n_block_left ? 0u : n_block_a;
size_type max_check = min_value<size_type>(min_check+size_type(1), n_block_left);
for (; n_block_left; --n_block_left, ++key_range2, min_check -= min_check != 0, max_check -= max_check != 0) {
for (; n_block_left; --n_block_left) {
size_type const next_key_idx = find_next_block(key_range2, key_comp, first2, l_block, min_check, max_check, comp);
max_check = min_value<size_type>(max_value<size_type>(max_check, next_key_idx+size_type(2)), n_block_left);
RandIt first_min = first2 + next_key_idx*l_block;
RandIt first_min = first2 + size_type(next_key_idx*l_block);
RandIt const last_min = first_min + l_block;
boost::ignore_unused(last_min);
RandIt const last2 = first2 + l_block;
@ -1322,6 +1335,10 @@ void op_merge_blocks_with_buf
is_range2_A ? --n_block_a_left : --n_block_b_left;
last1 += l_block;
first2 = last2;
//Update context
++key_range2;
min_check = size_type(min_check - (min_check != 0));
max_check = size_type(max_check - (max_check != 0));
}
RandIt res = op(forward_t(), buffer, buffer_end, first1);
boost::ignore_unused(res);
@ -1392,7 +1409,7 @@ void op_merge_right_step_once
, Op op)
{
typedef typename iterator_traits<RandIt>::size_type size_type;
size_type restk = elements_in_blocks%(2*l_build_buf);
size_type restk = size_type(elements_in_blocks%(2*l_build_buf));
size_type p = elements_in_blocks - restk;
BOOST_ASSERT(0 == (p%(2*l_build_buf)));
@ -1403,8 +1420,10 @@ void op_merge_right_step_once
op_merge_right(first_block+p, first_block+p+l_build_buf, first_block+p+restk, first_block+p+restk+l_build_buf, comp, op);
}
while(p>0){
p -= 2*l_build_buf;
op_merge_right(first_block+p, first_block+p+l_build_buf, first_block+p+2*l_build_buf, first_block+p+3*l_build_buf, comp, op);
p -= size_type(2*l_build_buf);
op_merge_right( first_block+p, first_block+size_type(p+l_build_buf)
, first_block+size_type(p+2*l_build_buf)
, first_block+size_type(p+3*l_build_buf), comp, op);
}
}
@ -1463,18 +1482,22 @@ typename iterator_traits<RandIt>::size_type
size_type p0=0;
RandIt pos = first_block;
while((elements_in_blocks - p0) > 2*l_merged) {
op_merge_left(pos-l_merged, pos, pos+l_merged, pos+2*l_merged, comp, op);
op_merge_left(pos-l_merged, pos, pos+l_merged, pos+size_type(2*l_merged), comp, op);
BOOST_MOVE_ADAPTIVE_SORT_INVARIANT(boost::movelib::is_sorted(pos-l_merged, pos+l_merged, comp));
p0 += 2*l_merged;
p0 += size_type(2*l_merged);
pos = first_block+p0;
}
if((elements_in_blocks-p0) > l_merged) {
op_merge_left(pos-l_merged, pos, pos+l_merged, first_block+elements_in_blocks, comp, op);
BOOST_MOVE_ADAPTIVE_SORT_INVARIANT(boost::movelib::is_sorted(pos-l_merged, pos-l_merged+(first_block+elements_in_blocks-pos), comp));
BOOST_MOVE_ADAPTIVE_SORT_INVARIANT
(boost::movelib::is_sorted
(pos-l_merged, pos+size_type((first_block+elements_in_blocks-pos))-l_merged, comp));
}
else {
op(forward_t(), pos, first_block+elements_in_blocks, pos-l_merged);
BOOST_MOVE_ADAPTIVE_SORT_INVARIANT(boost::movelib::is_sorted(pos-l_merged, first_block+elements_in_blocks-l_merged, comp));
BOOST_MOVE_ADAPTIVE_SORT_INVARIANT
(boost::movelib::is_sorted
(pos-l_merged, first_block+size_type(elements_in_blocks-l_merged), comp));
}
first_block -= l_merged;
l_left_space -= l_merged;

View File

@ -39,26 +39,26 @@ class heap_sort_helper
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);
size_type second_child = size_type(2u*(hole_index + 1u));
while (second_child < len) {
if (comp(*(first + second_child), *(first + (second_child - 1))))
if (comp(*(first + second_child), *(first + size_type(second_child - 1u))))
second_child--;
*(first + hole_index) = boost::move(*(first + second_child));
hole_index = second_child;
second_child = 2 * (second_child + 1);
second_child = size_type(2u * (second_child + 1u));
}
if (second_child == len) {
*(first + hole_index) = boost::move(*(first + (second_child - 1)));
*(first + hole_index) = boost::move(*(first + size_type(second_child - 1u)));
hole_index = second_child - 1;
}
{ //push_heap-like ending
size_type parent = (hole_index - 1) / 2;
size_type parent = size_type((hole_index - 1u) / 2u);
while (hole_index > top_index && comp(*(first + parent), value)) {
*(first + hole_index) = boost::move(*(first + parent));
hole_index = parent;
parent = (hole_index - 1) / 2;
parent = size_type((hole_index - 1u) / 2u);
}
*(first + hole_index) = boost::move(value);
}
@ -68,7 +68,7 @@ class heap_sort_helper
{
size_type const len = size_type(last - first);
if (len > 1) {
size_type parent = len/2u - 1u;
size_type parent = size_type(len/2u - 1u);
do {
value_type v(boost::move(*(first + parent)));

View File

@ -316,11 +316,11 @@ Unsigned gcd(Unsigned x, Unsigned y)
else if(!(y&1))
y >>=1;
else if(x >=y)
x = (x-y) >> 1;
x = Unsigned((x-y) >> 1u);
else
y = (y-x) >> 1;
y = Unsigned((y-x) >> 1);
}
return z*(x+y);
return Unsigned(z*(x+y));
}
}
@ -351,7 +351,7 @@ RandIt rotate_gcd(RandIt first, RandIt middle, RandIt last)
*it_j = boost::move(*it_k);
it_j = it_k;
size_type const left = size_type(last - it_j);
it_k = left > middle_pos ? it_j + middle_pos : first + (middle_pos - left);
it_k = left > middle_pos ? it_j + middle_pos : first + size_type(middle_pos - left);
} while(it_k != it_i);
*it_j = boost::move(temp);
}
@ -375,7 +375,7 @@ RandIt lower_bound
if (comp(*middle, key)) {
first = ++middle;
len -= step + 1;
len -= size_type(step + 1);
}
else{
len = step;
@ -400,7 +400,7 @@ RandIt upper_bound
if (!comp(key, *middle)) {
first = ++middle;
len -= step + 1;
len -= size_type(step + 1);
}
else{
len = step;

View File

@ -82,7 +82,7 @@ inline boost::uint64_t nsec_clock() BOOST_NOEXCEPT
}
}
return static_cast<boost::uint64_t>((nanosecs_per_tic) * pcount.QuadPart);
return static_cast<boost::uint64_t>(nanosecs_per_tic * double(pcount.QuadPart));
}
}} //namespace boost { namespace move_detail {

View File

@ -31,7 +31,9 @@ using boost::move_detail::nanosecond_type;
void print_stats(const char *str, boost::ulong_long_type element_count)
{
std::printf("%sCmp:%8.04f Cpy:%9.04f\n", str, double(order_perf_type::num_compare)/element_count, double(order_perf_type::num_copy)/element_count );
std::printf( "%sCmp:%8.04f Cpy:%9.04f\n", str
, double(order_perf_type::num_compare)/double(element_count)
, double(order_perf_type::num_copy)/double(element_count));
}
#include <boost/move/algo/adaptive_merge.hpp>

View File

@ -30,7 +30,9 @@ using boost::move_detail::nanosecond_type;
//#define BOOST_MOVE_ADAPTIVE_SORT_INVARIANTS
void print_stats(const char *str, boost::ulong_long_type element_count)
{
std::printf("%sCmp:%7.03f Cpy:%8.03f\n", str, double(order_perf_type::num_compare)/element_count, double(order_perf_type::num_copy)/element_count );
std::printf( "%sCmp:%7.03f Cpy:%8.03f\n", str
, double(order_perf_type::num_compare)/double(element_count)
, double(order_perf_type::num_copy)/double(element_count) );
}

View File

@ -26,7 +26,7 @@ void random_shuffle( RandomIt first, RandomIt last )
typedef typename boost::movelib::iterator_traits<RandomIt>::difference_type difference_type;
difference_type n = last - first;
for (difference_type i = n-1; i > 0; --i) {
difference_type j = ullrand() % (i+1);
difference_type j = static_cast<difference_type>(ullrand() % (i+1));
if(j != i) {
boost::adl_move_swap(first[i], first[j]);
}