Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ parallel_sort<Block_size, Iter_t, Compare>
::parallel_sort(backbone_t &bkbn, Iter_t first, Iter_t last)
: bk(bkbn), counter(0)
{
using std::swap;
assert((last - first) >= 0);
size_t nelem = size_t(last - first);

Expand All @@ -153,7 +154,7 @@ ::parallel_sort(backbone_t &bkbn, Iter_t first, Iter_t last)
size_t nelem2 = nelem >> 1;
Iter_t it1 = first, it2 = last - 1;
for (size_t i = 0; i < nelem2; ++i)
std::swap(*(it1++), *(it2--));
swap(*(it1++), *(it2--));
return;
};

Expand Down Expand Up @@ -188,6 +189,7 @@ template<uint32_t Block_size, class Iter_t, class Compare>
void parallel_sort<Block_size, Iter_t, Compare>
::divide_sort(Iter_t first, Iter_t last, uint32_t level)
{
using std::swap;
//------------------- check if sort -----------------------------------
bool sorted = true;
for (Iter_t it1 = first, it2 = first + 1;
Expand All @@ -211,14 +213,14 @@ ::divide_sort(Iter_t first, Iter_t last, uint32_t level)

while (c_first < c_last)
{
std::swap(*(c_first++), *(c_last--));
swap(*(c_first++), *(c_last--));
while (bk.cmp(*c_first, val))
++c_first;
while (bk.cmp(val, *c_last))
--c_last;
};

std::swap(*first, *c_last);
swap(*first, *c_last);

// insert the work of the second half in the stack of works
function_divide_sort(c_first, last, level - 1, counter, bk.error);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,8 @@ ::block_indirect_sort(Iter_t first, Iter_t last, Compare cmp, uint32_t nthr)
Iter_t it1 = first, it2 = last - 1;
for (size_t i = 0; i < nelem2; ++i)
{
std::swap(*(it1++), *(it2--));
using std::swap;
swap(*(it1++), *(it2--));
};
return;
};
Expand Down
34 changes: 18 additions & 16 deletions include/boost/sort/common/merge_four.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ range<Iter1_t> full_merge4(const range<Iter1_t> &rdest,
range<Iter2_t> vrange_input[4],
uint32_t nrange_input, Compare comp)
{
using std::swap;
typedef range<Iter1_t> range1_t;
typedef util::value_iter<Iter1_t> type1;
typedef util::value_iter<Iter2_t> type2;
Expand Down Expand Up @@ -120,28 +121,28 @@ range<Iter1_t> full_merge4(const range<Iter1_t> &rdest,
if (less_range(vrange_input[pos[1]].first, pos[1],
vrange_input[pos[0]].first, pos[0], comp))
{
std::swap(pos[0], pos[1]);
swap(pos[0], pos[1]);
};
if (npos == 4 and less_range(vrange_input[pos[3]].first, pos[3],
vrange_input[pos[2]].first, pos[2], comp))
{
std::swap(pos[3], pos[2]);
swap(pos[3], pos[2]);
};
if (less_range (vrange_input[pos[2]].first, pos[2],
vrange_input[pos[0]].first, pos[0], comp))
{
std::swap(pos[0], pos[2]);
swap(pos[0], pos[2]);
};
if (npos == 4
and less_range (vrange_input[pos[3]].first, pos[3],
vrange_input[pos[1]].first, pos[1], comp))
{
std::swap(pos[1], pos[3]);
swap(pos[1], pos[3]);
};
if (less_range (vrange_input[pos[2]].first, pos[2],
vrange_input[pos[1]].first, pos[1], comp))
{
std::swap(pos[1], pos[2]);
swap(pos[1], pos[2]);
};

Iter1_t it_dest = rdest.first;
Expand All @@ -160,18 +161,18 @@ range<Iter1_t> full_merge4(const range<Iter1_t> &rdest,
if (less_range(vrange_input[pos[1]].first, pos[1],
vrange_input[pos[0]].first, pos[0], comp))
{
std::swap(pos[0], pos[1]);
swap(pos[0], pos[1]);
if (less_range(vrange_input[pos[2]].first, pos[2],
vrange_input[pos[1]].first, pos[1], comp))
{
std::swap(pos[1], pos[2]);
swap(pos[1], pos[2]);
if (npos == 4
and less_range(vrange_input[pos[3]].first,
pos[3],
vrange_input[pos[2]].first,
pos[2], comp))
{
std::swap(pos[2], pos[3]);
swap(pos[2], pos[3]);
};
};
};
Expand Down Expand Up @@ -208,6 +209,7 @@ range<Value_t *> uninit_full_merge4(const range<Value_t *> &dest,
range<Iter_t> vrange_input[4],
uint32_t nrange_input, Compare comp)
{
using std::swap;
typedef util::value_iter<Iter_t> type1;
static_assert (std::is_same< type1, Value_t >::value,
"Incompatible iterators\n");
Expand Down Expand Up @@ -248,27 +250,27 @@ range<Value_t *> uninit_full_merge4(const range<Value_t *> &dest,
if (less_range(vrange_input[pos[1]].first, pos[1],
vrange_input[pos[0]].first, pos[0], comp))
{
std::swap(pos[0], pos[1]);
swap(pos[0], pos[1]);
};
if (npos == 4 and less_range(vrange_input[pos[3]].first, pos[3],
vrange_input[pos[2]].first, pos[2], comp))
{
std::swap(pos[3], pos[2]);
swap(pos[3], pos[2]);
};
if (less_range(vrange_input[pos[2]].first, pos[2],
vrange_input[pos[0]].first, pos[0], comp))
{
std::swap(pos[0], pos[2]);
swap(pos[0], pos[2]);
};
if (npos == 4 and less_range(vrange_input[pos[3]].first, pos[3],
vrange_input[pos[1]].first, pos[1], comp))
{
std::swap(pos[1], pos[3]);
swap(pos[1], pos[3]);
};
if (less_range(vrange_input[pos[2]].first, pos[2],
vrange_input[pos[1]].first, pos[1], comp))
{
std::swap(pos[1], pos[2]);
swap(pos[1], pos[2]);
};

Value_t *it_dest = dest.first;
Expand All @@ -288,17 +290,17 @@ range<Value_t *> uninit_full_merge4(const range<Value_t *> &dest,
if (less_range (vrange_input[pos[1]].first, pos[1],
vrange_input[pos[0]].first, pos[0], comp))
{
std::swap(pos[0], pos[1]);
swap(pos[0], pos[1]);
if (less_range (vrange_input[pos[2]].first, pos[2],
vrange_input[pos[1]].first, pos[1], comp))
{
std::swap(pos[1], pos[2]);
swap(pos[1], pos[2]);
if (npos == 4 and less_range(vrange_input[pos[3]].first,
pos[3],
vrange_input[pos[2]].first,
pos[2], comp))
{
std::swap(pos[2], pos[3]);
swap(pos[2], pos[3]);
};
};
};
Expand Down
13 changes: 8 additions & 5 deletions include/boost/sort/common/pivot.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,11 @@ namespace common
template < typename Iter_t, typename Compare >
inline Iter_t mid3 (Iter_t iter_1, Iter_t iter_2, Iter_t iter_3, Compare comp)
{
if (comp (*iter_2, *iter_1)) std::swap ( *iter_2, *iter_1);
using std::swap;
if (comp (*iter_2, *iter_1)) swap ( *iter_2, *iter_1);
if (comp (*iter_3, *iter_2))
{ std::swap ( *iter_3, *iter_2);
if (comp (*iter_2, *iter_1)) std::swap ( *iter_2, *iter_1);
{ swap ( *iter_3, *iter_2);
if (comp (*iter_2, *iter_1)) swap ( *iter_2, *iter_1);
};
return iter_2;
};
Expand All @@ -64,9 +65,10 @@ inline Iter_t mid3 (Iter_t iter_1, Iter_t iter_2, Iter_t iter_3, Compare comp)
template < class Iter_t, class Compare >
inline void pivot3 (Iter_t first, Iter_t last, Compare comp)
{
using std::swap;
auto N2 = (last - first) >> 1;
Iter_t it_val = mid3 (first + 1, first + N2, last - 1, comp);
std::swap (*first, *it_val);
swap (*first, *it_val);
};

//
Expand Down Expand Up @@ -110,11 +112,12 @@ inline Iter_t mid9 (Iter_t iter_1, Iter_t iter_2, Iter_t iter_3, Iter_t iter_4,
template < class Iter_t, class Compare >
inline void pivot9 (Iter_t first, Iter_t last, Compare comp)
{
using std::swap;
size_t cupo = (last - first) >> 3;
Iter_t itaux = mid9 (first + 1, first + cupo, first + 2 * cupo,
first + 3 * cupo, first + 4 * cupo, first + 5 * cupo,
first + 6 * cupo, first + 7 * cupo, last - 1, comp);
std::swap (*first, *itaux);
swap (*first, *itaux);
};
//****************************************************************************
};// End namespace common
Expand Down
3 changes: 2 additions & 1 deletion include/boost/sort/common/rearrange.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,9 @@ void rearrange(Iter_data global_first, Iter_index itx_first,

while ((pos_src = pos(itx_src)) != pos_ini)
{
using std::swap;
data[pos_dest] = std::move(data[pos_src]);
std::swap(itx_src, index[pos_src]);
swap(itx_src, index[pos_src]);
pos_dest = pos_src;
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,10 +150,11 @@ ::parallel_stable_sort (Iter_t first, Iter_t last, Compare comp,
it2 != last and (sw = comp(*it2, *it1)); it1 = it2++);
if (sw)
{
using std::swap;
size_t nelem2 = nelem >> 1;
Iter_t it1 = first, it2 = last - 1;
for (size_t i = 0; i < nelem2; ++i)
std::swap(*(it1++), *(it2--));
swap(*(it1++), *(it2--));
return;
};

Expand Down
3 changes: 2 additions & 1 deletion include/boost/sort/sample_sort/sample_sort.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -273,10 +273,11 @@ ::sample_sort (Iter_t first, Iter_t last, Compare cmp, uint32_t num_thread,
it2 != last and (sw = comp(*it2, *it1)); it1 = it2++);
if (sw)
{
using std::swap;
size_t nelem2 = nelem >> 1;
Iter_t it1 = first, it2 = last - 1;
for (size_t i = 0; i < nelem2; ++i)
std::swap(*(it1++), *(it2--));
swap(*(it1++), *(it2--));
return;
};

Expand Down
9 changes: 6 additions & 3 deletions include/boost/sort/spinsort/spinsort.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -209,8 +209,10 @@ static bool check_stable_sort(const range<Iter1_t> &rng_data,
size_t nreverse = it2 - rng_data.first;
Iter1_t alpha(rng_data.first), beta(it2 - 1), mid(
rng_data.first + (nreverse >> 1));
while (alpha != mid)
std::swap(*(alpha++), *(beta--));
while (alpha != mid) {
using std::swap;
swap(*(alpha++), *(beta--));
}

// insert the elements between it1 and last
if (it2 != rng_data.last)
Expand Down Expand Up @@ -470,10 +472,11 @@ ::spinsort (Iter_t first, Iter_t last, Compare comp, value_t *paux, size_t naux)
it2 != last and (sw = comp(*it2, *it1)); it1 = it2++);
if (sw)
{
using std::swap;
size_t nelem2 = nelem >> 1;
Iter_t it1 = first, it2 = last - 1;
for (size_t i = 0; i < nelem2; ++i)
std::swap(*(it1++), *(it2--));
swap(*(it1++), *(it2--));
return;
};

Expand Down