update boost

This commit is contained in:
2023-11-24 12:56:13 -06:00
parent cfc99971af
commit 19d727037a
9260 changed files with 849256 additions and 299957 deletions

View File

@@ -14,15 +14,15 @@
#ifndef __BOOST_SORT_PARALLEL_DETAIL_BACKBONE_HPP
#define __BOOST_SORT_PARALLEL_DETAIL_BACKBONE_HPP
#include <ciso646>
#include <atomic>
#include <future>
#include <iostream>
#include <iterator>
#include <boost/sort/pdqsort/pdqsort.hpp>
#include <boost/sort/common/util/atomic.hpp>
#include <boost/sort/common/util/algorithm.hpp>
#include <boost/sort/common/stack_cnc.hpp>
#include <future>
#include <iostream>
#include <iterator>
#include <boost/sort/block_indirect_sort/blk_detail/block.hpp>
namespace boost

View File

@@ -14,6 +14,7 @@
#ifndef __BOOST_SORT_PARALLEL_DETAIL_BLOCK_HPP
#define __BOOST_SORT_PARALLEL_DETAIL_BLOCK_HPP
#include <ciso646>
#include <boost/sort/common/range.hpp>
namespace boost

View File

@@ -14,12 +14,14 @@
#ifndef __BOOST_SORT_PARALLEL_DETAIL_MERGE_BLOCKS_HPP
#define __BOOST_SORT_PARALLEL_DETAIL_MERGE_BLOCKS_HPP
#include <ciso646>
#include <atomic>
#include <boost/sort/block_indirect_sort/blk_detail/backbone.hpp>
#include <boost/sort/common/range.hpp>
#include <future>
#include <iostream>
#include <iterator>
#include <boost/sort/block_indirect_sort/blk_detail/backbone.hpp>
#include <boost/sort/common/range.hpp>
namespace boost
{
@@ -103,7 +105,7 @@ struct merge_blocks
{
this->merge_range_pos (rng_input);
}
catch (std::bad_alloc &ba)
catch (std::bad_alloc &)
{
error = true;
};

View File

@@ -15,10 +15,11 @@
#define __BOOST_SORT_PARALLEL_DETAIL_MOVE_BLOCKS_HPP
#include <atomic>
#include <boost/sort/block_indirect_sort/blk_detail/backbone.hpp>
#include <ciso646>
#include <future>
#include <iostream>
#include <iterator>
#include <boost/sort/block_indirect_sort/blk_detail/backbone.hpp>
namespace boost
{

View File

@@ -14,6 +14,7 @@
#ifndef __BOOST_SORT_PARALLEL_DETAIL_PARALLEL_SORT_HPP
#define __BOOST_SORT_PARALLEL_DETAIL_PARALLEL_SORT_HPP
#include <ciso646>
#include <boost/sort/block_indirect_sort/blk_detail/backbone.hpp>
#include <boost/sort/pdqsort/pdqsort.hpp>
#include <boost/sort/common/pivot.hpp>
@@ -159,7 +160,7 @@ parallel_sort<Block_size, Iter_t, Compare>
//-------------------max_per_thread ---------------------------
uint32_t nbits_size = (nbits64(sizeof(value_t))) >> 1;
if (nbits_size > 5) nbits_size = 5;
max_per_thread = 1 << (18 - nbits_size);
max_per_thread = (size_t) 1 << (18 - nbits_size);
uint32_t level = ((nbits64(nelem / max_per_thread)) * 3) / 2;

View File

@@ -13,15 +13,19 @@
#ifndef __BOOST_SORT_PARALLEL_DETAIL_BLOCK_INDIRECT_SORT_HPP
#define __BOOST_SORT_PARALLEL_DETAIL_BLOCK_INDIRECT_SORT_HPP
#include <ciso646>
#include <atomic>
#include <cstdlib>
#include <future>
#include <iterator>
#include <boost/sort/block_indirect_sort/blk_detail/merge_blocks.hpp>
#include <boost/sort/block_indirect_sort/blk_detail/move_blocks.hpp>
#include <boost/sort/block_indirect_sort/blk_detail/parallel_sort.hpp>
#include <boost/sort/pdqsort/pdqsort.hpp>
#include <boost/sort/common/util/traits.hpp>
#include <boost/sort/common/util/algorithm.hpp>
#include <future>
#include <iterator>
// This value is the minimal number of threads for to use the
// block_indirect_sort algorithm
@@ -141,7 +145,7 @@ struct block_indirect_sort
destroy(rglobal_buf);
construct = false;
};
std::return_temporary_buffer(ptr);
std::free (ptr);
ptr = nullptr;
};
}
@@ -223,7 +227,7 @@ block_indirect_sort<Block_size, Group_size, Iter_t, Compare>
uint32_t nbits_size = (nbits64(sizeof(value_t)) >> 1);
if (nbits_size > 5) nbits_size = 5;
size_t max_per_thread = 1 << (18 - nbits_size);
size_t max_per_thread = (size_t) 1 << (18 - nbits_size);
if (nelem < (max_per_thread) or nthread < 2)
{
@@ -233,8 +237,9 @@ block_indirect_sort<Block_size, Group_size, Iter_t, Compare>
};
//----------- creation of the temporary buffer --------------------
ptr = std::get_temporary_buffer<value_t>(Block_size * nthread).first;
if (ptr == nullptr)
ptr = reinterpret_cast <value_t*>
(std::malloc (Block_size * nthread * sizeof(value_t)));
if (ptr == nullptr)
{
bk.error = true;
throw std::bad_alloc();
@@ -271,7 +276,7 @@ block_indirect_sort<Block_size, Group_size, Iter_t, Compare>
// thread local buffer
for (uint32_t i = 0; i < nthread; ++i)
{
auto f1 = [=, &vbuf]( )
auto f1 = [&vbuf,i, this]( )
{ bk.exec (vbuf[i], this->counter);};
vfuture[i] = std::async(std::launch::async, f1);
};
@@ -322,7 +327,8 @@ void block_indirect_sort<Block_size, Group_size, Iter_t, Compare>
//-------------------------------------------------------------------------
if (level_thread != 0)
{
auto f1 = [=, &son_counter]( )
auto f1 = [this, &son_counter, pos_index_mid,
pos_index2, level_thread]( )
{
split_range (pos_index_mid, pos_index2, level_thread - 1);
bscu::atomic_sub (son_counter, 1);
@@ -334,9 +340,9 @@ void block_indirect_sort<Block_size, Group_size, Iter_t, Compare>
else
{
Iter_t mid = first + ((nblock >> 1) * Block_size);
auto f1 = [=, &son_counter]( )
auto f1 = [this, &son_counter, mid, last]( )
{
parallel_sort_t (bk, mid, last);
parallel_sort_t (this->bk, mid, last);
bscu::atomic_sub (son_counter, 1);
};
bk.works.emplace_back(f1);
@@ -364,7 +370,7 @@ void block_indirect_sort<Block_size, Group_size, Iter_t, Compare>
}
else
{
size_t level_thread = nbits64(nthread - 1) - 1;
uint32_t level_thread = nbits64 (nthread - 1) - 1;
split_range(0, bk.nblock, level_thread - 1);
if (bk.error) return;
move_blocks_t k(bk);
@@ -443,7 +449,7 @@ void block_indirect_sort(Iter_t first, Iter_t last)
//
//-----------------------------------------------------------------------------
// function : block_indirect_sort
/// @brief invocation of block_indirtect_sort with 3 parameters. The third is
/// @brief invocation of block_indirtect_sort with 3 parameters. The third is
/// the number of threads
///
/// @param first : iterator to the first element of the range to sort
@@ -460,7 +466,7 @@ void block_indirect_sort(Iter_t first, Iter_t last, uint32_t nthread)
//
//-----------------------------------------------------------------------------
// function : block_indirect_sort
/// @brief invocation of block_indirtect_sort with 3 parameters. The third is
/// @brief invocation of block_indirtect_sort with 3 parameters. The third is
/// the comparison object
///
/// @param first : iterator to the first element of the range to sort
@@ -479,7 +485,7 @@ void block_indirect_sort(Iter_t first, Iter_t last, Compare comp)
//
//-----------------------------------------------------------------------------
// function : block_indirect_sort
/// @brief invocation of block_indirtect_sort with 4 parameters.
/// @brief invocation of block_indirtect_sort with 4 parameters.
///
/// @param first : iterator to the first element of the range to sort
/// @param last : iterator after the last element to the range to sort

View File

@@ -14,13 +14,16 @@
#ifndef __TOOLS_DEQUE_CNC_HPP
#define __TOOLS_DEQUE_CNC_HPP
#include <sort/tools/spinlock.hpp>
#include <ciso646>
#include <vector>
#include <deque>
#include <boost/sort/common/spinlock.hpp>
namespace boost
{
namespace sort
{
namespace tools
namespace common
{
//###########################################################################
@@ -61,7 +64,7 @@ protected:
// VARIABLES
//------------------------------------------------------------------------
deque_t dq;
mutable spinlock spl;
mutable spinlock_t spl;
public:
//
@@ -94,7 +97,7 @@ public:
//----------------------------------------------------------------------
void clear(void)
{
std::lock_guard < spinlock > S(spl);
std::lock_guard < spinlock_t > S(spl);
dq.clear();
};
//
@@ -107,7 +110,7 @@ public:
void swap(deque_cnc & A) noexcept
{
if (this == &A) return;
std::lock_guard < spinlock > S(spl);
std::lock_guard < spinlock_t > S(spl);
dq.swap(A.dq);
};
//
@@ -123,7 +126,7 @@ public:
//------------------------------------------------------------------------
size_type size(void) const noexcept
{
std::lock_guard < spinlock > S(spl);
std::lock_guard < spinlock_t > S(spl);
return dq.size();
};
//
@@ -134,7 +137,7 @@ public:
//------------------------------------------------------------------------
size_type max_size(void) const noexcept
{
std::lock_guard < spinlock > S(spl);
std::lock_guard < spinlock_t > S(spl);
return (dq.max_size());
};
//
@@ -150,7 +153,7 @@ public:
//------------------------------------------------------------------------
void shrink_to_fit()
{
std::lock_guard < spinlock > S(spl);
std::lock_guard < spinlock_t > S(spl);
dq.shrink_to_fit();
};
//
@@ -161,7 +164,7 @@ public:
//------------------------------------------------------------------------
bool empty(void) const noexcept
{
std::lock_guard < spinlock > S(spl);
std::lock_guard < spinlock_t > S(spl);
return (dq.empty());
};
//---------------------------------------------------------------------------
@@ -172,7 +175,7 @@ public:
//---------------------------------------------------------------------------
void push_back(const value_type & D)
{
std::lock_guard < spinlock > S(spl);
std::lock_guard < spinlock_t > S(spl);
dq.push_back(D);
};
@@ -184,7 +187,7 @@ public:
template<class ... Args>
void emplace_back(Args && ... args)
{
std::lock_guard < spinlock > S(spl);
std::lock_guard < spinlock_t > S(spl);
dq.emplace_back(std::forward <Args>(args) ...);
};
//------------------------------------------------------------------------
@@ -197,7 +200,7 @@ public:
template<class Allocator2>
deque_cnc & push_back(const std::deque<value_type, Allocator2> & D)
{
std::lock_guard < spinlock > S(spl);
std::lock_guard < spinlock_t > S(spl);
for (size_type i = 0; i < D.size(); ++i)
dq.push_back(D[i]);
return *this;
@@ -211,7 +214,7 @@ public:
//------------------------------------------------------------------------
deque_cnc & push_back(std::deque<value_type, Allocator> && D)
{
std::lock_guard < spinlock > S(spl);
std::lock_guard < spinlock_t > S(spl);
for (size_type i = 0; i < D.size(); ++i)
dq.emplace_back(std::move(D[i]));
return *this;
@@ -223,7 +226,7 @@ public:
//-----------------------------------------------------------------------
void pop_back(void)
{
std::lock_guard < spinlock > S(spl);
std::lock_guard < spinlock_t > S(spl);
dq.pop_back();
};
//
@@ -237,7 +240,7 @@ public:
//------------------------------------------------------------------------
bool pop_copy_back(value_type & P)
{ //-------------------------- begin -----------------------------
std::lock_guard < spinlock > S(spl);
std::lock_guard < spinlock_t > S(spl);
if (dq.size() == 0) return false;
P = dq.back();
dq.pop_back();
@@ -254,7 +257,7 @@ public:
//------------------------------------------------------------------------
bool pop_move_back(value_type & P)
{ //-------------------------- begin -----------------------------
std::lock_guard < spinlock > S(spl);
std::lock_guard < spinlock_t > S(spl);
if (dq.size() == 0) return false;
P = std::move(dq.back());
dq.pop_back();
@@ -268,7 +271,7 @@ public:
//------------------------------------------------------------------------
void push_front(const value_type & D)
{
std::lock_guard < spinlock > S(spl);
std::lock_guard < spinlock_t > S(spl);
dq.push_front(D);
};
@@ -280,7 +283,7 @@ public:
template<class ... Args>
void emplace_front(Args && ... args)
{
std::lock_guard < spinlock > S(spl);
std::lock_guard < spinlock_t > S(spl);
dq.emplace_front(std::forward <Args>(args) ...);
};
//------------------------------------------------------------------------
@@ -293,7 +296,7 @@ public:
template<class Allocator2>
deque_cnc & push_front(const std::deque<value_type, Allocator2> & V1)
{
std::lock_guard < spinlock > S(spl);
std::lock_guard < spinlock_t > S(spl);
for (size_type i = 0; i < V1.size(); ++i)
dq.push_front(V1[i]);
return *this;
@@ -307,7 +310,7 @@ public:
//-----------------------------------------------------------------------
deque_cnc & push_front(std::deque<value_type, Allocator> && V1)
{
std::lock_guard < spinlock > S(spl);
std::lock_guard < spinlock_t > S(spl);
for (size_type i = 0; i < V1.size(); ++i)
dq.emplace_front(std::move(V1[i]));
return *this;
@@ -319,7 +322,7 @@ public:
//-----------------------------------------------------------------------
void pop_front(void)
{
std::lock_guard < spinlock > S(spl);
std::lock_guard < spinlock_t > S(spl);
dq.pop_front();
};
//
@@ -333,7 +336,7 @@ public:
//-----------------------------------------------------------------------
bool pop_copy_front(value_type & P)
{ //-------------------------- begin -----------------------------
std::lock_guard < spinlock > S(spl);
std::lock_guard < spinlock_t > S(spl);
if (dq.size() == 0) return false;
P = dq.front();
dq.pop_front();
@@ -350,7 +353,7 @@ public:
//------------------------------------------------------------------------
bool pop_move_front(value_type & P)
{ //-------------------------- begin -----------------------------
std::lock_guard < spinlock > S(spl);
std::lock_guard < spinlock_t > S(spl);
if (dq.size() == 0) return false;
P = std::move(dq.front());
dq.pop_front();
@@ -360,7 +363,8 @@ public:
// end class deque_cnc
//***************************************************************************
};// end namespace tools
};// end namespace common
};// end namespace sort
};// end namespace boost
//***************************************************************************
#endif

View File

@@ -43,7 +43,7 @@ namespace common
/// @return
/// @remarks
//-----------------------------------------------------------------------------
static int generate_file(const std::string & filename, size_t NElem)
inline int generate_file(const std::string & filename, size_t NElem)
{ //------------------------------- begin ----------------------------------
std::ofstream ofile;
ofile.open(filename, std::ios_base::out | std::ios_base::binary |
@@ -73,7 +73,7 @@ static int generate_file(const std::string & filename, size_t NElem)
/// @return
/// @remarks
//-----------------------------------------------------------------------------
static int fill_vector_uint64(const std::string & filename,
inline int fill_vector_uint64(const std::string & filename,
std::vector<uint64_t> & V, size_t NElem)
{ //----------------------- begin ------------------------------------------
std::ifstream input(filename, std::ios_base::in | std::ios_base::binary);
@@ -115,7 +115,7 @@ static int fill_vector_uint64(const std::string & filename,
/// @return
/// @remarks
//-----------------------------------------------------------------------------
static int write_file_uint64 (const std::vector<uint64_t> & V,
inline int write_file_uint64 (const std::vector<uint64_t> & V,
const std::string & filename)
{ //--------------------------------- begin --------------------------------
std::ofstream ofile;
@@ -144,7 +144,7 @@ static int write_file_uint64 (const std::vector<uint64_t> & V,
/// @return
/// @remarks
//-----------------------------------------------------------------------------
static int fill_vector_string (const std::string & filename,
inline int fill_vector_string (const std::string & filename,
std::vector<std::string> & V, size_t NElem)
{ //----------------------- begin ------------------------------------------
std::ifstream input(filename, std::ios_base::in | std::ios_base::binary);
@@ -189,7 +189,7 @@ static int fill_vector_string (const std::string & filename,
/// @return
/// @remarks
//-----------------------------------------------------------------------------
static int write_file_string (const std::vector<std::string> & V,
inline int write_file_string (const std::vector<std::string> & V,
const std::string & filename)
{ //--------------------------------- begin --------------------------------
std::ofstream ofile;

View File

@@ -72,7 +72,7 @@ struct less_ptr_no_null
/// @param index : vector where store the iterators
//-----------------------------------------------------------------------------
template<class Iter_t>
static void create_index(Iter_t first, Iter_t last, std::vector<Iter_t> &index)
void create_index(Iter_t first, Iter_t last, std::vector<Iter_t> &index)
{
auto nelem = last - first;
assert(nelem >= 0);
@@ -90,7 +90,7 @@ static void create_index(Iter_t first, Iter_t last, std::vector<Iter_t> &index)
/// @param [in] index : vector of the iterators
//-----------------------------------------------------------------------------
template<class Iter_t>
static void sort_index(Iter_t global_first, std::vector<Iter_t> &index)
void sort_index(Iter_t global_first, std::vector<Iter_t> &index)
{
typedef util::value_iter<Iter_t> value_t;
@@ -129,8 +129,8 @@ static void sort_index(Iter_t global_first, std::vector<Iter_t> &index)
};
};
template<class func, class Iter_t, class Compare = compare_iter<Iter_t> >
static void indirect_sort(func method, Iter_t first, Iter_t last, Compare comp)
template<class func, class Iter_t, class Compare = util::compare_iter<Iter_t> >
void indirect_sort(func method, Iter_t first, Iter_t last, Compare comp)
{
auto nelem = (last - first);
assert(nelem >= 0);

View File

@@ -15,6 +15,7 @@
#ifndef __BOOST_SORT_COMMON_INT_ARRAY_HPP
#define __BOOST_SORT_COMMON_INT_ARRAY_HPP
#include <ciso646>
#include <cstdint>
#include <iostream>

View File

@@ -14,6 +14,7 @@
#ifndef __BOOST_SORT_COMMON_MERGE_BLOCK_HPP
#define __BOOST_SORT_COMMON_MERGE_BLOCK_HPP
#include <ciso646>
#include <boost/sort/common/range.hpp>
#include <boost/sort/common/rearrange.hpp>
#include <boost/sort/common/util/merge.hpp>

View File

@@ -13,12 +13,14 @@
#ifndef __BOOST_SORT_PARALLEL_DETAIL_UTIL_MERGE_FOUR_HPP
#define __BOOST_SORT_PARALLEL_DETAIL_UTIL_MERGE_FOUR_HPP
#include <boost/sort/common/util/traits.hpp>
#include <boost/sort/common/range.hpp>
#include <ciso646>
#include <functional>
#include <iterator>
#include <memory>
#include <vector>
#include <boost/sort/common/util/traits.hpp>
#include <boost/sort/common/range.hpp>
namespace boost
{

View File

@@ -14,12 +14,14 @@
#ifndef __BOOST_SORT_PARALLEL_DETAIL_UTIL_MERGE_VECTOR_HPP
#define __BOOST_SORT_PARALLEL_DETAIL_UTIL_MERGE_VECTOR_HPP
#include <boost/sort/common/merge_four.hpp>
#include <ciso646>
#include <functional>
#include <iterator>
#include <memory>
#include <type_traits>
#include <vector>
#include <boost/sort/common/merge_four.hpp>
namespace boost
{
@@ -99,7 +101,7 @@ void merge_level4(range<Iter1_t> dest, std::vector<range<Iter2_t> > &v_input,
template<class Value_t, class Iter_t, class Compare>
void uninit_merge_level4(range<Value_t *> dest,
std::vector<range<Iter_t> > &v_input,
std::vector<range<Value_t *> > &v_output, Compare comp)
std::vector <range<Value_t *> > &v_output, Compare comp)
{
typedef range<Value_t *> range1_t;
typedef util::value_iter<Iter_t> type1;

1
linx64/include/boost/sort/common/pivot.hpp Executable file → Normal file
View File

@@ -13,6 +13,7 @@
#ifndef __BOOST_SORT_COMMON_PIVOT_HPP
#define __BOOST_SORT_COMMON_PIVOT_HPP
#include <ciso646>
#include <cstdint>
namespace boost

View File

@@ -13,13 +13,15 @@
#ifndef __BOOST_SORT_PARALLEL_DETAIL_UTIL_RANGE_HPP
#define __BOOST_SORT_PARALLEL_DETAIL_UTIL_RANGE_HPP
#include <boost/sort/common/util/algorithm.hpp>
#include <boost/sort/common/util/merge.hpp>
#include <boost/sort/common/util/traits.hpp>
#include <ciso646>
#include <cassert>
#include <functional>
#include <memory>
#include <vector>
#include <boost/sort/common/util/algorithm.hpp>
#include <boost/sort/common/util/merge.hpp>
#include <boost/sort/common/util/traits.hpp>
namespace boost
{

View File

@@ -13,13 +13,14 @@
#ifndef __BOOST_SORT_COMMON_REARRANGE_HPP
#define __BOOST_SORT_COMMON_REARRANGE_HPP
//#include <boost/sort/common/atomic.hpp>
#include <boost/sort/common/util/traits.hpp>
#include <ciso646>
#include <functional>
#include <iterator>
#include <type_traits>
#include <vector>
#include <cassert>
#include <boost/sort/common/util/traits.hpp>
namespace boost
{

View File

@@ -14,15 +14,16 @@
#ifndef __BOOST_SORT_COMMON_SCHEDULER_HPP
#define __BOOST_SORT_COMMON_SCHEDULER_HPP
#include <boost/sort/common/spinlock.hpp>
#include <boost/sort/common/search.hpp>
#include <boost/sort/common/compare_traits.hpp>
#include <ciso646>
#include <scoped_allocator>
#include <utility>
#include <vector>
#include <deque>
#include <iostream>
#include <unordered_map>
#include <boost/sort/common/spinlock.hpp>
#include <boost/sort/common/util/search.hpp>
#include <boost/sort/common/util/traits.hpp>
namespace boost
{
@@ -55,14 +56,21 @@ struct scheduler
// D E F I N I T I O N S
//-----------------------------------------------------------------------
typedef std::scoped_allocator_adaptor <Allocator> scoped_alloc;
template <class T>
using alloc_t = typename std::allocator_traits<Allocator>::
template rebind_alloc<T>;
typedef std::deque <Func_t, scoped_alloc> deque_t;
typedef typename deque_t::iterator it_deque;
typedef std::thread::id key_t;
typedef std::hash <key_t> hash_t;
typedef std::equal_to <key_t> equal_t;
typedef std::unique_lock <spinlock_t> lock_t;
typedef std::unordered_map <key_t, deque_t, hash_t,
equal_t, scoped_alloc> map_t;
typedef std::pair<const key_t, deque_t> pair_t;
typedef std::unordered_map <key_t, deque_t, hash_t,
equal_t, alloc_t <pair_t> > map_t;
typedef typename map_t::iterator it_map;
//-----------------------------------------------------------------------
@@ -184,7 +192,7 @@ struct scheduler
//--------------------------------------------------------------------
// Metaprogramming
//--------------------------------------------------------------------
typedef value_iter<it_func> value2_t;
typedef util::value_iter<it_func> value2_t;
static_assert (std::is_same< Func_t, value2_t >::value,
"Incompatible iterators\n");

View File

@@ -13,10 +13,7 @@
#ifndef __BOOST_SORT_COMMON_SORT_BASIC_HPP
#define __BOOST_SORT_COMMON_SORT_BASIC_HPP
//#include <boost/sort/spinsort/util/indirect.hpp>
#include <boost/sort/insert_sort/insert_sort.hpp>
#include <boost/sort/common/util/traits.hpp>
#include <boost/sort/common/range.hpp>
#include <ciso646>
#include <cstdlib>
#include <functional>
#include <iterator>
@@ -24,6 +21,9 @@
#include <type_traits>
#include <vector>
#include <cstddef>
#include <boost/sort/insert_sort/insert_sort.hpp>
#include <boost/sort/common/util/traits.hpp>
#include <boost/sort/common/range.hpp>
namespace boost
{

View File

@@ -13,6 +13,7 @@
#ifndef __BOOST_SORT_PARALLEL_DETAIL_UTIL_SPINLOCK_HPP
#define __BOOST_SORT_PARALLEL_DETAIL_UTIL_SPINLOCK_HPP
#include <ciso646>
#include <atomic>
#include <ctime>
#include <functional>
@@ -69,7 +70,7 @@ class spinlock_t
//-------------------------------------------------------------------------
bool try_lock ( ) noexcept
{
return not af.test_and_set (std::memory_order_acquire);
return !af.test_and_set (std::memory_order_acquire);
};
//
//-------------------------------------------------------------------------

View File

@@ -13,8 +13,10 @@
#ifndef __BOOST_SORT_PARALLEL_DETAIL_UTIL_STACK_CNC_HPP
#define __BOOST_SORT_PARALLEL_DETAIL_UTIL_STACK_CNC_HPP
#include <boost/sort/common/spinlock.hpp>
#include <ciso646>
#include <vector>
#include <boost/sort/common/spinlock.hpp>
namespace boost
{

View File

@@ -14,13 +14,14 @@
#ifndef __BOOST_SORT_PARALLEL_TOOLS_TIME_MEASURE_HPP
#define __BOOST_SORT_PARALLEL_TOOLS_TIME_MEASURE_HPP
#include <ciso646>
#include <chrono>
namespace boost
namespace boost
{
namespace sort
namespace sort
{
namespace common
namespace common
{
namespace chrn = std::chrono;
@@ -30,15 +31,13 @@ namespace chrn = std::chrono;
//***************************************************************************
typedef chrn::steady_clock::time_point time_point;
time_point now ( );
double subtract_time ( const time_point & t1, const time_point & t2 );
//
//---------------------------------------------------------------------------
// function : now
/// @brief return the time system in a internal format ( steady_clock)
/// @return time in steady_clock format
//---------------------------------------------------------------------------
time_point now ( ) { return chrn::steady_clock::now( ); };
inline time_point now ( ) { return chrn::steady_clock::now( ); };
//
//---------------------------------------------------------------------------
// function : subtract_time
@@ -47,7 +46,7 @@ time_point now ( ) { return chrn::steady_clock::now( ); };
/// @param [in] t2 : second time in time_point format
/// @return time in seconds of the difference of t1 - t2
//---------------------------------------------------------------------------
double subtract_time ( const time_point & t1, const time_point & t2 )
inline double subtract_time ( const time_point & t1, const time_point & t2 )
{ //------------------------ begin ---------------------------------
chrn::duration<double> time_span =
chrn::duration_cast < chrn::duration < double > > ( t1 - t2 );

View File

@@ -13,6 +13,7 @@
#ifndef __BOOST_SORT_COMMON_UTIL_ALGORITHM_HPP
#define __BOOST_SORT_COMMON_UTIL_ALGORITHM_HPP
#include <ciso646>
#include <algorithm>
#include <functional>
#include <iterator>

View File

@@ -12,6 +12,7 @@
#ifndef __BOOST_SORT_PARALLEL_DETAIL_UTIL_ATOMIC_HPP
#define __BOOST_SORT_PARALLEL_DETAIL_UTIL_ATOMIC_HPP
#include <ciso646>
#include <atomic>
#include <cassert>
#include <type_traits>

View File

@@ -13,6 +13,7 @@
#ifndef __BOOST_SORT_COMMON_UTIL_CIRCULAR_BUFFER_HPP
#define __BOOST_SORT_COMMON_UTIL_CIRCULAR_BUFFER_HPP
#include <ciso646>
#include <memory>
#include <cassert>
#include <exception>
@@ -70,7 +71,7 @@ struct circular_buffer
circular_buffer(void)
: ptr(nullptr), nelem(0), first_pos(0), initialized(false)
{
ptr = std::get_temporary_buffer < Value_t > (NMAX).first;
ptr = static_cast <Value_t*> (std::malloc (NMAX * sizeof(Value_t)));
if (ptr == nullptr) throw std::bad_alloc();
};
//
@@ -84,7 +85,7 @@ struct circular_buffer
{ for (size_t i = 0; i < NMAX; ++i) (ptr + i)->~Value_t();
initialized = false;
};
std::return_temporary_buffer(ptr);
std::free(static_cast <void*> (ptr));
}
;
//

View File

@@ -13,10 +13,8 @@
#ifndef __BOOST_SORT_COMMON_UTIL_INSERT_HPP
#define __BOOST_SORT_COMMON_UTIL_INSERT_HPP
//#include <boost/sort/spinsort/util/indirect.hpp>
#include <boost/sort/common/util/insert.hpp>
#include <boost/sort/common/util/traits.hpp>
#include <boost/sort/common/util/algorithm.hpp>
#include <ciso646>
#include <cstdlib>
#include <functional>
#include <iterator>
@@ -24,6 +22,9 @@
#include <type_traits>
#include <vector>
#include <cstddef>
#include <boost/sort/common/util/insert.hpp>
#include <boost/sort/common/util/traits.hpp>
#include <boost/sort/common/util/algorithm.hpp>
namespace boost
{

View File

@@ -13,6 +13,7 @@
#ifndef __BOOST_SORT_COMMON_UTIL_MERGE_HPP
#define __BOOST_SORT_COMMON_UTIL_MERGE_HPP
#include <ciso646>
#include <algorithm>
#include <functional>
#include <iterator>

View File

@@ -9,8 +9,10 @@
#ifndef __BOOST_SORT_COMMON_SEARCH_HPP
#define __BOOST_SORT_COMMON_SEARCH_HPP
#include <boost/sort/common/util/traits.hpp>
#include <ciso646>
#include <cassert>
#include <boost/sort/common/util/traits.hpp>
namespace boost
{

View File

@@ -12,6 +12,7 @@
#ifndef __BOOST_SORT_COMMON_UTIL_TRAITS_HPP
#define __BOOST_SORT_COMMON_UTIL_TRAITS_HPP
#include <ciso646>
#include <functional>
#include <iterator>
#include <type_traits>

View File

@@ -13,6 +13,14 @@
#ifndef __BOOST_SORT_FLAT_STABLE_SORT_HPP
#define __BOOST_SORT_FLAT_STABLE_SORT_HPP
#include <ciso646>
#include <cstdlib>
#include <functional>
#include <iterator>
#include <memory>
#include <type_traits>
#include <vector>
#include <boost/sort/insert_sort/insert_sort.hpp>
#include <boost/sort/common/util/insert.hpp>
#include <boost/sort/common/merge_block.hpp>
@@ -21,12 +29,7 @@
#include <boost/sort/common/util/traits.hpp>
#include <boost/sort/common/indirect.hpp>
#include <cstdlib>
#include <functional>
#include <iterator>
#include <memory>
#include <type_traits>
#include <vector>
namespace boost
{
@@ -179,7 +182,7 @@ bool flat_stable_sort <Iter_t, Compare, Power2>
size_t nblock = size_t(itx_last - itx_first);
range_it rng = get_group_range(*itx_first, nblock);
size_t nelem = rng.size();
size_t min_process = std::max(BLOCK_SIZE, (nelem >> 3));
size_t min_process = (std::max)(BLOCK_SIZE, (nelem >> 3));
size_t nsorted1 = bsc::number_stable_sorted_forward (rng.first, rng.last,
min_process, cmp);
@@ -221,7 +224,7 @@ bool flat_stable_sort <Iter_t, Compare, Power2>
range_it rng = get_group_range(*itx_first, nblock);
size_t nelem = rng.size();
size_t min_process = std::max(BLOCK_SIZE, (nelem >> 3));
size_t min_process = (std::max)(BLOCK_SIZE, (nelem >> 3));
size_t nsorted2 = bsc::number_stable_sorted_backward(rng.first, rng.last,
min_process, cmp);
@@ -299,7 +302,7 @@ inline void indirect_flat_stable_sort (Iter_t first, Iter_t last,
Compare comp = Compare())
{
typedef typename std::vector<Iter_t>::iterator itx_iter;
typedef common::less_ptr_no_null<Iter_t, Compare> itx_comp;
typedef common::less_ptr_no_null <Iter_t, Compare> itx_comp;
common::indirect_sort ( flat_stable_sort<itx_iter, itx_comp>,
first, last, comp);
};

View File

@@ -1,215 +0,0 @@
//----------------------------------------------------------------------------
/// @file heap_sort.hpp
/// @brief Insertion Sort algorithm
///
/// @author Copyright (c) 2016 Francisco Jose Tapia (fjtapia@gmail.com )\n
/// Distributed under the Boost Software License, Version 1.0.\n
/// ( See accompanying file LICENSE_1_0.txt or copy at
/// http://www.boost.org/LICENSE_1_0.txt )
/// @version 0.1
///
/// @remarks
//-----------------------------------------------------------------------------
#ifndef __BOOST_SORT_INTROSORT_DETAIL_HEAP_SORT_HPP
#define __BOOST_SORT_INTROSORT_DETAIL_HEAP_SORT_HPP
#include <cassert>
#include <cstdint>
#include <iterator>
#include <stdexcept>
#include <utility> // for std::swap
#include <boost/sort/common/util/traits.hpp>
namespace boost
{
namespace sort
{
namespace heap_detail
{
namespace bscu = boost::sort::common::util;
//
//---------------------------------------------------------------------------
// struct : heap_sort
/// @brief : Heap sort algorithm
/// @remarks This algorithm is O(NLogN)
//---------------------------------------------------------------------------
template < class Iter_t, class Compare >
struct heap_sort
{
typedef bscu::value_iter<Iter_t> value_t;
//
//------------------------------------------------------------------------
// function : sort3
/// @brief Sort and signal the changes of three values
/// @param val_0 : first value to compare
/// @param val_1 : second value to compare
/// @param val_2 : third value to compare
/// @param [out] bool_0 : if true indicates val_0 had been changed
/// @param [out] bool_1 : if true indicates val_1 had been changed
/// @param [out] bool_2 : if true indicates val_2 had been changed
/// @return if true , some value had changed
/// @remarks
//------------------------------------------------------------------------
bool sort3 (value_t &val_0, value_t &val_1, value_t &val_2, bool &bool_0,
bool &bool_1, bool &bool_2)
{
bool_0 = bool_1 = bool_2 = false;
int value = 0;
if (val_0 < val_1) value += 4;
if (val_1 < val_2) value += 2;
if (val_0 < val_2) value += 1;
switch (value)
{
case 0: break;
case 2:
std::swap (val_1, val_2);
bool_1 = bool_2 = true;
break;
case 3:
if (not(val_0 > val_1)) {
std::swap (val_0, val_2);
bool_0 = bool_2 = true;
}
else
{
auto aux = std::move (val_2);
val_2 = std::move (val_1);
val_1 = std::move (val_0);
val_0 = std::move (aux);
bool_0 = bool_1 = bool_2 = true;
};
break;
case 4:
std::swap (val_0, val_1);
bool_0 = bool_1 = true;
break;
case 5:
if (val_1 > val_2) {
auto aux = std::move (val_0);
val_0 = std::move (val_1);
val_1 = std::move (val_2);
val_2 = std::move (aux);
bool_0 = bool_1 = bool_2 = true;
}
else
{
std::swap (val_0, val_2);
bool_0 = bool_2 = true;
};
break;
case 7:
std::swap (val_0, val_2);
bool_0 = bool_2 = true;
break;
default: abort ( );
};
return (bool_0 or bool_1 or bool_2);
};
//
//-----------------------------------------------------------------------
// function : make_heap
/// @brief Make the heap for to extract the sorted elements
/// @param first : iterator to the first element of the range
/// @param nelem : number of lements of the range
/// @param comp : object for to compare two elements
/// @remarks This algorithm is O(NLogN)
//------------------------------------------------------------------------
void make_heap (Iter_t first, size_t nelem, Compare comp)
{
size_t pos_father, pos_son;
Iter_t iter_father = first, iter_son = first;
bool sw = false;
for (size_t i = 1; i < nelem; ++i)
{
pos_father = i;
iter_father = first + i;
sw = false;
do
{
iter_son = iter_father;
pos_son = pos_father;
pos_father = (pos_son - 1) >> 1;
iter_father = first + pos_father;
if ((sw = comp (*iter_father, *iter_son)))
std::swap (*iter_father, *iter_son);
} while (sw and pos_father != 0);
};
};
//
//------------------------------------------------------------------------
// function : heap_sort
/// @brief : Heap sort algorithm
/// @param first: iterator to the first element of the range
/// @param last : iterator to the next element of the last in the range
/// @param comp : object for to do the comparison between the elements
/// @remarks This algorithm is O(NLogN)
//------------------------------------------------------------------------
heap_sort (Iter_t first, Iter_t last, Compare comp)
{
assert ((last - first) >= 0);
size_t nelem = last - first;
if (nelem < 2) return;
//--------------------------------------------------------------------
// Creating the initial heap
//--------------------------------------------------------------------
make_heap (first, nelem, comp);
//--------------------------------------------------------------------
// Sort the heap
//--------------------------------------------------------------------
size_t pos_father, pos_son;
Iter_t iter_father = first, iter_son = first;
bool sw = false;
for (size_t i = 1; i < nelem; ++i)
{
std::swap (*first, *(first + (nelem - i)));
pos_father = 0;
pos_son = 1;
iter_father = first;
sw = true;
while (sw and pos_son < (nelem - i))
{
// if the father have two sons must select the bigger
iter_son = first + pos_son;
if ((pos_son + 1) < (nelem - i) and
comp (*iter_son, *(iter_son + 1)))
{
++pos_son;
++iter_son;
};
if ((sw = comp (*iter_father, *iter_son)))
std::swap (*iter_father, *iter_son);
pos_father = pos_son;
iter_father = iter_son;
pos_son = (pos_father << 1) + 1;
};
};
};
}; // End class heap_sort
}; // end namespace heap_sort
namespace bscu = boost::sort::common::util;
template < class Iter_t, typename Compare = bscu::compare_iter < Iter_t > >
void heap_sort (Iter_t first, Iter_t last, Compare comp = Compare())
{
heap_detail::heap_sort<Iter_t, Compare> ( first, last, comp);
}
//
//****************************************************************************
}; // End namespace sort
}; // End namespace boost
//****************************************************************************
//
#endif

View File

@@ -13,6 +13,7 @@
#ifndef __BOOST_SORT_INTROSORT_DETAIL_INSERT_SORT_HPP
#define __BOOST_SORT_INTROSORT_DETAIL_INSERT_SORT_HPP
#include <ciso646>
#include <functional>
#include <iterator>
#include <algorithm>

View File

@@ -13,14 +13,16 @@
#ifndef __BOOST_SORT_PARALLEL_DETAIL_PARALLEL_STABLE_SORT_HPP
#define __BOOST_SORT_PARALLEL_DETAIL_PARALLEL_STABLE_SORT_HPP
#include <boost/sort/sample_sort/sample_sort.hpp>
#include <boost/sort/common/util/traits.hpp>
#include <ciso646>
#include <functional>
#include <future>
#include <iterator>
#include <memory>
#include <type_traits>
#include <vector>
#include <boost/sort/sample_sort/sample_sort.hpp>
#include <boost/sort/common/util/traits.hpp>
namespace boost
{
@@ -86,7 +88,7 @@ struct parallel_stable_sort
//-----------------------------------------------------------------------------
void destroy_all()
{
if (ptr != nullptr) std::return_temporary_buffer(ptr);
if (ptr != nullptr) std::free (ptr);
};
//
//-----------------------------------------------------------------------------
@@ -155,7 +157,9 @@ parallel_stable_sort <Iter_t, Compare>
return;
};
ptr = std::get_temporary_buffer<value_t>(nptr).first;
ptr = reinterpret_cast <value_t*>
(std::malloc (nptr * sizeof(value_t)));
if (ptr == nullptr) throw std::bad_alloc();
//---------------------------------------------------------------------
@@ -189,8 +193,12 @@ parallel_stable_sort <Iter_t, Compare>
throw std::bad_alloc();
};
range_buffer = move_forward(range_buffer, range_first);
range_buffer = move_construct(range_buffer, range_first);
range_initial = merge_half(range_initial, range_buffer, range_second, comp);
destroy (range_buffer);
}; // end of constructor
//

View File

@@ -1,6 +1,6 @@
// Pattern-defeating quicksort
// Copyright Orson Peters 2017.
// Copyright Orson Peters 2021.
// 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)
@@ -112,10 +112,8 @@ namespace pdqsort_detail {
typedef typename std::iterator_traits<Iter>::value_type T;
if (begin == end) return true;
int limit = 0;
std::size_t 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;
@@ -129,6 +127,8 @@ namespace pdqsort_detail {
*sift = BOOST_PDQSORT_PREFER_MOVE(tmp);
limit += cur - sift;
}
if (limit > partial_insertion_sort_limit) return false;
}
return true;
@@ -161,18 +161,18 @@ namespace pdqsort_detail {
template<class Iter>
inline void swap_offsets(Iter first, Iter last,
unsigned char* offsets_l, unsigned char* offsets_r,
int num, bool use_swaps) {
size_t num, bool use_swaps) {
typedef typename std::iterator_traits<Iter>::value_type T;
if (use_swaps) {
// This case is needed for the descending distribution, where we need
// to have proper swapping for pdqsort to remain O(n).
for (int i = 0; i < num; ++i) {
for (size_t i = 0; i < num; ++i) {
std::iter_swap(first + offsets_l[i], last - offsets_r[i]);
}
} else if (num > 0) {
Iter l = first + offsets_l[0]; Iter r = last - offsets_r[0];
T tmp(BOOST_PDQSORT_PREFER_MOVE(*l)); *l = BOOST_PDQSORT_PREFER_MOVE(*r);
for (int i = 1; i < num; ++i) {
for (size_t i = 1; i < num; ++i) {
l = first + offsets_l[i]; *r = BOOST_PDQSORT_PREFER_MOVE(*l);
r = last - offsets_r[i]; *l = BOOST_PDQSORT_PREFER_MOVE(*r);
}
@@ -209,108 +209,94 @@ namespace pdqsort_detail {
if (!already_partitioned) {
std::iter_swap(first, last);
++first;
}
// The following branchless partitioning is derived from "BlockQuicksort: How Branch
// Mispredictions don't affect Quicksort" by Stefan Edelkamp and Armin Weiss.
unsigned char offsets_l_storage[block_size + cacheline_size];
unsigned char offsets_r_storage[block_size + cacheline_size];
unsigned char* offsets_l = align_cacheline(offsets_l_storage);
unsigned char* offsets_r = align_cacheline(offsets_r_storage);
int num_l, num_r, start_l, start_r;
num_l = num_r = start_l = start_r = 0;
while (last - first > 2 * block_size) {
// Fill up offset blocks with elements that are on the wrong side.
if (num_l == 0) {
start_l = 0;
Iter it = first;
for (unsigned char i = 0; i < block_size;) {
offsets_l[num_l] = i++; num_l += !comp(*it, pivot); ++it;
offsets_l[num_l] = i++; num_l += !comp(*it, pivot); ++it;
offsets_l[num_l] = i++; num_l += !comp(*it, pivot); ++it;
offsets_l[num_l] = i++; num_l += !comp(*it, pivot); ++it;
offsets_l[num_l] = i++; num_l += !comp(*it, pivot); ++it;
offsets_l[num_l] = i++; num_l += !comp(*it, pivot); ++it;
offsets_l[num_l] = i++; num_l += !comp(*it, pivot); ++it;
offsets_l[num_l] = i++; num_l += !comp(*it, pivot); ++it;
// The following branchless partitioning is derived from "BlockQuicksort: How Branch
// Mispredictions don’t affect Quicksort" by Stefan Edelkamp and Armin Weiss, but
// heavily micro-optimized.
unsigned char offsets_l_storage[block_size + cacheline_size];
unsigned char offsets_r_storage[block_size + cacheline_size];
unsigned char* offsets_l = align_cacheline(offsets_l_storage);
unsigned char* offsets_r = align_cacheline(offsets_r_storage);
Iter offsets_l_base = first;
Iter offsets_r_base = last;
size_t num_l, num_r, start_l, start_r;
num_l = num_r = start_l = start_r = 0;
while (first < last) {
// Fill up offset blocks with elements that are on the wrong side.
// First we determine how much elements are considered for each offset block.
size_t num_unknown = last - first;
size_t left_split = num_l == 0 ? (num_r == 0 ? num_unknown / 2 : num_unknown) : 0;
size_t right_split = num_r == 0 ? (num_unknown - left_split) : 0;
// Fill the offset blocks.
if (left_split >= block_size) {
for (size_t i = 0; i < block_size;) {
offsets_l[num_l] = i++; num_l += !comp(*first, pivot); ++first;
offsets_l[num_l] = i++; num_l += !comp(*first, pivot); ++first;
offsets_l[num_l] = i++; num_l += !comp(*first, pivot); ++first;
offsets_l[num_l] = i++; num_l += !comp(*first, pivot); ++first;
offsets_l[num_l] = i++; num_l += !comp(*first, pivot); ++first;
offsets_l[num_l] = i++; num_l += !comp(*first, pivot); ++first;
offsets_l[num_l] = i++; num_l += !comp(*first, pivot); ++first;
offsets_l[num_l] = i++; num_l += !comp(*first, pivot); ++first;
}
} else {
for (size_t i = 0; i < left_split;) {
offsets_l[num_l] = i++; num_l += !comp(*first, pivot); ++first;
}
}
}
if (num_r == 0) {
start_r = 0;
Iter it = last;
for (unsigned char i = 0; i < block_size;) {
offsets_r[num_r] = ++i; num_r += comp(*--it, pivot);
offsets_r[num_r] = ++i; num_r += comp(*--it, pivot);
offsets_r[num_r] = ++i; num_r += comp(*--it, pivot);
offsets_r[num_r] = ++i; num_r += comp(*--it, pivot);
offsets_r[num_r] = ++i; num_r += comp(*--it, pivot);
offsets_r[num_r] = ++i; num_r += comp(*--it, pivot);
offsets_r[num_r] = ++i; num_r += comp(*--it, pivot);
offsets_r[num_r] = ++i; num_r += comp(*--it, pivot);
if (right_split >= block_size) {
for (size_t i = 0; i < block_size;) {
offsets_r[num_r] = ++i; num_r += comp(*--last, pivot);
offsets_r[num_r] = ++i; num_r += comp(*--last, pivot);
offsets_r[num_r] = ++i; num_r += comp(*--last, pivot);
offsets_r[num_r] = ++i; num_r += comp(*--last, pivot);
offsets_r[num_r] = ++i; num_r += comp(*--last, pivot);
offsets_r[num_r] = ++i; num_r += comp(*--last, pivot);
offsets_r[num_r] = ++i; num_r += comp(*--last, pivot);
offsets_r[num_r] = ++i; num_r += comp(*--last, pivot);
}
} else {
for (size_t i = 0; i < right_split;) {
offsets_r[num_r] = ++i; num_r += comp(*--last, pivot);
}
}
// Swap elements and update block sizes and first/last boundaries.
size_t num = (std::min)(num_l, num_r);
swap_offsets(offsets_l_base, offsets_r_base,
offsets_l + start_l, offsets_r + start_r,
num, num_l == num_r);
num_l -= num; num_r -= num;
start_l += num; start_r += num;
if (num_l == 0) {
start_l = 0;
offsets_l_base = first;
}
if (num_r == 0) {
start_r = 0;
offsets_r_base = last;
}
}
// Swap elements and update block sizes and first/last boundaries.
int num = (std::min)(num_l, num_r);
swap_offsets(first, last, offsets_l + start_l, offsets_r + start_r,
num, num_l == num_r);
num_l -= num; num_r -= num;
start_l += num; start_r += num;
if (num_l == 0) first += block_size;
if (num_r == 0) last -= block_size;
}
int l_size = 0, r_size = 0;
int unknown_left = (last - first) - ((num_r || num_l) ? block_size : 0);
if (num_r) {
// Handle leftover block by assigning the unknown elements to the other block.
l_size = unknown_left;
r_size = block_size;
} else if (num_l) {
l_size = block_size;
r_size = unknown_left;
} else {
// No leftover block, split the unknown elements in two blocks.
l_size = unknown_left/2;
r_size = unknown_left - l_size;
}
// Fill offset buffers if needed.
if (unknown_left && !num_l) {
start_l = 0;
Iter it = first;
for (unsigned char i = 0; i < l_size;) {
offsets_l[num_l] = i++; num_l += !comp(*it, pivot); ++it;
// We have now fully identified [first, last)'s proper position. Swap the last elements.
if (num_l) {
offsets_l += start_l;
while (num_l--) std::iter_swap(offsets_l_base + offsets_l[num_l], --last);
first = last;
}
}
if (unknown_left && !num_r) {
start_r = 0;
Iter it = last;
for (unsigned char i = 0; i < r_size;) {
offsets_r[num_r] = ++i; num_r += comp(*--it, pivot);
if (num_r) {
offsets_r += start_r;
while (num_r--) std::iter_swap(offsets_r_base - offsets_r[num_r], first), ++first;
last = first;
}
}
int num = (std::min)(num_l, num_r);
swap_offsets(first, last, offsets_l + start_l, offsets_r + start_r, num, num_l == num_r);
num_l -= num; num_r -= num;
start_l += num; start_r += num;
if (num_l == 0) first += l_size;
if (num_r == 0) last -= r_size;
// We have now fully identified [first, last)'s proper position. Swap the last elements.
if (num_l) {
offsets_l += start_l;
while (num_l--) std::iter_swap(first + offsets_l[num_l], --last);
first = last;
}
if (num_r) {
offsets_r += start_r;
while (num_r--) std::iter_swap(last - offsets_r[num_r], first), ++first;
last = first;
}
// Put the pivot in the right place.
Iter pivot_pos = first - 1;
*begin = BOOST_PDQSORT_PREFER_MOVE(*pivot_pos);

View File

@@ -13,6 +13,7 @@
#ifndef __BOOST_SORT_PARALLEL_DETAIL_SAMPLE_SORT_HPP
#define __BOOST_SORT_PARALLEL_DETAIL_SAMPLE_SORT_HPP
#include <ciso646>
#include <functional>
#include <future>
#include <iterator>
@@ -288,7 +289,9 @@ sample_sort<Iter_t, Compare>
}
else
{
value_t *ptr = std::get_temporary_buffer<value_t>(nelem).first;
value_t * ptr = reinterpret_cast <value_t*>
(std::malloc (nelem * sizeof(value_t)));
if (ptr == nullptr) throw std::bad_alloc();
owner = true;
global_buf = range_buf(ptr, ptr + nelem);
@@ -331,7 +334,7 @@ void sample_sort<Iter_t, Compare>::destroy_all(void)
construct = false;
}
if (global_buf.first != nullptr and owner)
std::return_temporary_buffer(global_buf.first);
std::free(global_buf.first);
}
//
//-----------------------------------------------------------------------------
@@ -370,10 +373,10 @@ void sample_sort<Iter_t, Compare>::initial_configuration(void)
for (uint32_t i = 0; i < nthread; ++i)
{
auto func = [=]()
auto func = [this, &vmem_thread, i, &vbuf_thread]()
{
bss::spinsort<Iter_t, Compare> (vmem_thread[i].first,
vmem_thread[i].last, comp,
vmem_thread[i].last, this->comp,
vbuf_thread[i]);
};
vfuture[i] = std::async(std::launch::async, func);

View File

@@ -13,12 +13,8 @@
#ifndef __BOOST_SORT_PARALLEL_ALGORITHM_SPIN_SORT_HPP
#define __BOOST_SORT_PARALLEL_ALGORITHM_SPIN_SORT_HPP
//#include <boost/sort/spinsort/util/indirect.hpp>
#include <boost/sort/insert_sort/insert_sort.hpp>
#include <boost/sort/common/util/traits.hpp>
#include <boost/sort/common/util/algorithm.hpp>
#include <boost/sort/common/range.hpp>
#include <boost/sort/common/indirect.hpp>
#include <ciso646>
#include <cstdlib>
#include <functional>
#include <iterator>
@@ -26,6 +22,12 @@
#include <type_traits>
#include <vector>
#include <cstddef>
#include <boost/sort/insert_sort/insert_sort.hpp>
#include <boost/sort/common/util/traits.hpp>
#include <boost/sort/common/util/algorithm.hpp>
#include <boost/sort/common/range.hpp>
#include <boost/sort/common/indirect.hpp>
namespace boost
{
@@ -82,7 +84,7 @@ static void sort_range_sort (const range<Iter1_t> &rng_data,
//-----------------------------------------------------------------------------
template<class Iter1_t, class Iter2_t, typename Compare>
static void insert_partial_sort (Iter1_t first, Iter1_t mid, Iter1_t last,
Compare comp, const range<Iter2_t> &rng_aux)
Compare comp, const range <Iter2_t> &rng_aux)
{
//------------------------------------------------------------------------
// metaprogram
@@ -416,7 +418,7 @@ public:
destroy(range<value_t *>(ptr, ptr + nptr));
construct = false;
};
if (owner and ptr != nullptr) std::return_temporary_buffer(ptr);
if (owner and ptr != nullptr) std::free (ptr);
};
};
//----------------------------------------------------------------------------
@@ -477,7 +479,9 @@ spinsort <Iter_t, Compare>
if (ptr == nullptr)
{
ptr = std::get_temporary_buffer<value_t>(nptr).first;
ptr = reinterpret_cast <value_t*>
(std::malloc (nptr * sizeof(value_t)));
if (ptr == nullptr) throw std::bad_alloc();
owner = true;
};

View File

@@ -21,7 +21,6 @@ Scott McMurray
#include <limits>
#include <functional>
#include <boost/static_assert.hpp>
#include <boost/serialization/static_warning.hpp>
#include <boost/utility/enable_if.hpp>
#include <boost/sort/spreadsort/detail/constants.hpp>
#include <boost/sort/spreadsort/detail/integer_sort.hpp>
@@ -735,7 +734,7 @@ namespace spreadsort {
void >::type
float_sort(RandomAccessIter first, RandomAccessIter last)
{
BOOST_STATIC_WARNING(!(sizeof(boost::uint64_t) ==
BOOST_STATIC_ASSERT(!(sizeof(boost::uint64_t) ==
sizeof(typename std::iterator_traits<RandomAccessIter>::value_type)
|| sizeof(boost::uint32_t) ==
sizeof(typename std::iterator_traits<RandomAccessIter>::value_type))
@@ -778,7 +777,6 @@ namespace spreadsort {
float_sort(RandomAccessIter first, RandomAccessIter last, Div_type,
Right_shift rshift)
{
BOOST_STATIC_WARNING(sizeof(boost::uintmax_t) >= sizeof(Div_type));
boost::sort::pdqsort(first, last);
}
@@ -820,7 +818,6 @@ namespace spreadsort {
float_sort(RandomAccessIter first, RandomAccessIter last, Div_type,
Right_shift rshift, Compare comp)
{
BOOST_STATIC_WARNING(sizeof(boost::uintmax_t) >= sizeof(Div_type));
boost::sort::pdqsort(first, last, comp);
}
}

View File

@@ -19,7 +19,6 @@ Phil Endecott and Frank Gennari
#include <limits>
#include <functional>
#include <boost/static_assert.hpp>
#include <boost/serialization/static_warning.hpp>
#include <boost/utility/enable_if.hpp>
#include <boost/sort/spreadsort/detail/constants.hpp>
#include <boost/sort/spreadsort/detail/spreadsort_common.hpp>
@@ -391,8 +390,6 @@ namespace spreadsort {
//defaulting to boost::sort::pdqsort when integer_sort won't work
integer_sort(RandomAccessIter first, RandomAccessIter last, Div_type)
{
//Warning that we're using boost::sort::pdqsort, even though integer_sort was called
BOOST_STATIC_WARNING( sizeof(Div_type) <= sizeof(size_t) );
boost::sort::pdqsort(first, last);
}
@@ -438,8 +435,6 @@ namespace spreadsort {
integer_sort(RandomAccessIter first, RandomAccessIter last, Div_type,
Right_shift shift, Compare comp)
{
//Warning that we're using boost::sort::pdqsort, even though integer_sort was called
BOOST_STATIC_WARNING( sizeof(Div_type) <= sizeof(size_t) );
boost::sort::pdqsort(first, last, comp);
}
@@ -482,8 +477,6 @@ namespace spreadsort {
integer_sort(RandomAccessIter first, RandomAccessIter last, Div_type,
Right_shift shift)
{
//Warning that we're using boost::sort::pdqsort, even though integer_sort was called
BOOST_STATIC_WARNING( sizeof(Div_type) <= sizeof(size_t) );
boost::sort::pdqsort(first, last);
}
}

View File

@@ -21,7 +21,6 @@ Phil Endecott and Frank Gennari
#include <limits>
#include <functional>
#include <boost/static_assert.hpp>
#include <boost/serialization/static_warning.hpp>
#include <boost/sort/pdqsort/pdqsort.hpp>
#include <boost/sort/spreadsort/detail/constants.hpp>
#include <boost/cstdint.hpp>

View File

@@ -20,7 +20,6 @@ Phil Endecott and Frank Gennari
#include <limits>
#include <functional>
#include <boost/static_assert.hpp>
#include <boost/serialization/static_warning.hpp>
#include <boost/utility/enable_if.hpp>
#include <boost/sort/spreadsort/detail/constants.hpp>
#include <boost/sort/spreadsort/detail/spreadsort_common.hpp>
@@ -700,8 +699,7 @@ namespace spreadsort {
string_sort(RandomAccessIter first, RandomAccessIter last,
Unsigned_char_type)
{
//Warning that we're using boost::sort::pdqsort, even though string_sort was called
BOOST_STATIC_WARNING( sizeof(Unsigned_char_type) <= 2 );
// Use boost::sort::pdqsort if the char_type is too large for string_sort.
boost::sort::pdqsort(first, last);
}
@@ -726,8 +724,7 @@ namespace spreadsort {
{
typedef typename std::iterator_traits<RandomAccessIter>::value_type
Data_type;
//Warning that we're using boost::sort::pdqsort, even though string_sort was called
BOOST_STATIC_WARNING( sizeof(Unsigned_char_type) <= 2 );
// Use boost::sort::pdqsort if the char_type is too large for string_sort.
boost::sort::pdqsort(first, last, std::greater<Data_type>());
}
@@ -752,8 +749,7 @@ namespace spreadsort {
string_sort(RandomAccessIter first, RandomAccessIter last,
Get_char get_character, Get_length length, Unsigned_char_type)
{
//Warning that we're using boost::sort::pdqsort, even though string_sort was called
BOOST_STATIC_WARNING( sizeof(Unsigned_char_type) <= 2 );
// Use boost::sort::pdqsort if the char_type is too large for string_sort.
boost::sort::pdqsort(first, last);
}
@@ -780,8 +776,7 @@ namespace spreadsort {
string_sort(RandomAccessIter first, RandomAccessIter last,
Get_char get_character, Get_length length, Compare comp, Unsigned_char_type)
{
//Warning that we're using boost::sort::pdqsort, even though string_sort was called
BOOST_STATIC_WARNING( sizeof(Unsigned_char_type) <= 2 );
// Use boost::sort::pdqsort if the char_type is too large for string_sort.
boost::sort::pdqsort(first, last, comp);
}
@@ -807,8 +802,7 @@ namespace spreadsort {
reverse_string_sort(RandomAccessIter first, RandomAccessIter last,
Get_char get_character, Get_length length, Compare comp, Unsigned_char_type)
{
//Warning that we're using boost::sort::pdqsort, even though string_sort was called
BOOST_STATIC_WARNING( sizeof(Unsigned_char_type) <= 2 );
// Use boost::sort::pdqsort if the char_type is too large for string_sort.
boost::sort::pdqsort(first, last, comp);
}
}