mirror of
https://github.com/boostorg/sort.git
synced 2026-01-19 04:42:11 +00:00
226
.github/workflows/ci.yml
vendored
226
.github/workflows/ci.yml
vendored
@@ -17,200 +17,48 @@ jobs:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
include:
|
||||
- name: "TOOLSET=gcc CXXSTD=03,11 Job 0"
|
||||
buildtype: "boost"
|
||||
packages: ""
|
||||
packages_to_remove: ""
|
||||
os: "ubuntu-20.04"
|
||||
container: "ubuntu:16.04"
|
||||
cxx: "g++"
|
||||
sources: ""
|
||||
llvm_os: ""
|
||||
llvm_ver: ""
|
||||
toolset: "gcc"
|
||||
cxxstd: "03,11"
|
||||
- name: "TOOLSET=clang CXXSTD=03,11,14,1z Job 1"
|
||||
buildtype: "boost"
|
||||
packages: "libstdc++-4.9-dev clang"
|
||||
packages_to_remove: ""
|
||||
os: "ubuntu-20.04"
|
||||
container: "ubuntu:16.04"
|
||||
cxx: "clang++"
|
||||
sources: ""
|
||||
llvm_os: ""
|
||||
llvm_ver: ""
|
||||
- name: "g++-13"
|
||||
os: ubuntu-latest
|
||||
packages: "g++-13"
|
||||
toolset: "gcc-13"
|
||||
- name: "clang-15"
|
||||
os: ubuntu-latest
|
||||
packages: "clang-15"
|
||||
toolset: "clang-15"
|
||||
- name: "xcode"
|
||||
os: macos-latest
|
||||
toolset: "clang"
|
||||
cxxstd: "03,11,14,1z"
|
||||
|
||||
runs-on: ${{ matrix.os }}
|
||||
container: ${{ matrix.container }}
|
||||
|
||||
runs-on: ${{matrix.os}}
|
||||
steps:
|
||||
- name: Check if running in container
|
||||
if: matrix.container != ''
|
||||
run: echo "GHA_CONTAINER=${{ matrix.container }}" >> $GITHUB_ENV
|
||||
- name: If running in container, upgrade packages
|
||||
if: matrix.container != ''
|
||||
- uses: actions/checkout@main
|
||||
- name: Install
|
||||
if: matrix.packages
|
||||
run: |
|
||||
apt-get -o Acquire::Retries=3 update && DEBIAN_FRONTEND=noninteractive apt-get -y install tzdata && apt-get -o Acquire::Retries=3 install -y sudo software-properties-common wget curl apt-transport-https make apt-file sudo unzip libssl-dev build-essential autotools-dev autoconf automake g++ libc++-helpers python ruby cpio gcc-multilib g++-multilib pkgconf python3 ccache libpython-dev
|
||||
sudo apt-add-repository ppa:git-core/ppa
|
||||
sudo apt-get -o Acquire::Retries=3 update && apt-get -o Acquire::Retries=3 -y install git
|
||||
python_version=$(python3 -c 'import sys; print("{0.major}.{0.minor}".format(sys.version_info))')
|
||||
sudo wget https://bootstrap.pypa.io/pip/$python_version/get-pip.py
|
||||
sudo python3 get-pip.py
|
||||
sudo /usr/local/bin/pip install cmake
|
||||
|
||||
- uses: actions/checkout@v2
|
||||
|
||||
- name: linux
|
||||
shell: bash
|
||||
env:
|
||||
CXX: ${{ matrix.cxx }}
|
||||
SOURCES: ${{ matrix.sources }}
|
||||
LLVM_OS: ${{ matrix.llvm_os }}
|
||||
LLVM_VER: ${{ matrix.llvm_ver }}
|
||||
PACKAGES: ${{ matrix.packages }}
|
||||
PACKAGES_TO_REMOVE: ${{ matrix.packages_to_remove }}
|
||||
JOB_BUILDTYPE: ${{ matrix.buildtype }}
|
||||
TOOLSET: ${{ matrix.toolset }}
|
||||
CXXSTD: ${{ matrix.cxxstd }}
|
||||
TRAVIS_BRANCH: ${{ github.base_ref }}
|
||||
TRAVIS_OS_NAME: "linux"
|
||||
sudo add-apt-repository ppa:ubuntu-toolchain-r/test -y
|
||||
sudo apt-get -o Acquire::Retries=3 update -y
|
||||
sudo apt-get -o Acquire::Retries=3 -y install ${{matrix.packages}}
|
||||
- name: Setup
|
||||
run: |
|
||||
echo '==================================> SETUP'
|
||||
echo '==================================> PACKAGES'
|
||||
set -e
|
||||
if [ -n "$PACKAGES_TO_REMOVE" ]; then sudo apt-get purge -y $PACKAGES_TO_REMOVE; fi
|
||||
echo ">>>>> APT: REPO.."
|
||||
for i in {1..3}; do sudo -E apt-add-repository -y "ppa:ubuntu-toolchain-r/test" && break || sleep 2; done
|
||||
|
||||
if test -n "${LLVM_OS}" ; then
|
||||
wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add -
|
||||
if test -n "${LLVM_VER}" ; then
|
||||
sudo -E apt-add-repository "deb http://apt.llvm.org/${LLVM_OS}/ llvm-toolchain-${LLVM_OS}-${LLVM_VER} main"
|
||||
else
|
||||
# Snapshot (i.e. trunk) build of clang
|
||||
sudo -E apt-add-repository "deb http://apt.llvm.org/${LLVM_OS}/ llvm-toolchain-${LLVM_OS} main"
|
||||
fi
|
||||
fi
|
||||
echo ">>>>> APT: UPDATE.."
|
||||
sudo -E apt-get -o Acquire::Retries=3 update
|
||||
if test -n "${SOURCES}" ; then
|
||||
echo ">>>>> APT: INSTALL SOURCES.."
|
||||
for SOURCE in $SOURCES; do
|
||||
sudo -E apt-add-repository ppa:$SOURCE
|
||||
done
|
||||
fi
|
||||
echo ">>>>> APT: INSTALL ${PACKAGES}.."
|
||||
sudo -E DEBIAN_FRONTEND=noninteractive apt-get -o Acquire::Retries=3 -y --no-install-suggests --no-install-recommends install ${PACKAGES}
|
||||
|
||||
echo '==================================> INSTALL AND COMPILE'
|
||||
set -e
|
||||
export TRAVIS_BUILD_DIR=$(pwd)
|
||||
export TRAVIS_BRANCH=${TRAVIS_BRANCH:-$(echo $GITHUB_REF | awk 'BEGIN { FS = "/" } ; { print $3 }')}
|
||||
export VCS_COMMIT_ID=$GITHUB_SHA
|
||||
export GIT_COMMIT=$GITHUB_SHA
|
||||
export REPO_NAME=$(basename $GITHUB_REPOSITORY)
|
||||
export USER=$(whoami)
|
||||
export CC=${CC:-gcc}
|
||||
export PATH=~/.local/bin:/usr/local/bin:$PATH
|
||||
|
||||
if [ "$JOB_BUILDTYPE" == "boost" ]; then
|
||||
|
||||
echo '==================================> INSTALL'
|
||||
|
||||
BOOST_BRANCH=develop && [ "$TRAVIS_BRANCH" == "master" ] && BOOST_BRANCH=master || true
|
||||
echo GITHUB_BASE_REF: $GITHUB_BASE_REF
|
||||
echo GITHUB_REF: $GITHUB_REF
|
||||
REF=${GITHUB_BASE_REF:-$GITHUB_REF}
|
||||
REF=${REF#refs/heads/}
|
||||
echo REF: $REF
|
||||
BOOST_BRANCH=develop && ( test "${GITHUB_REF_NAME}" == "master" || test "${GITHUB_REF_NAME}" == "modular" ) && BOOST_BRANCH=${GITHUB_REF_NAME} || true
|
||||
BOOST_GIT=https://github.com/${GITHUB_REPOSITORY/sort/boost}.git
|
||||
echo BOOST_GIT: ${BOOST_GIT}
|
||||
echo BOOST_BRANCH: ${BOOST_BRANCH}
|
||||
cd ..
|
||||
git clone -b $BOOST_BRANCH https://github.com/boostorg/boost.git boost-root
|
||||
git clone -b "${BOOST_BRANCH}" --depth 1 "${BOOST_GIT}" boost-root
|
||||
cd boost-root
|
||||
git submodule update --init tools/build
|
||||
git submodule update --init libs/config
|
||||
git submodule update --init tools/boostdep
|
||||
cp -r $TRAVIS_BUILD_DIR/* libs/sort
|
||||
python tools/boostdep/depinst/depinst.py sort
|
||||
git submodule update --init --jobs 3 tools/boostdep libs/assert libs/config libs/core libs/test libs/sort
|
||||
python tools/boostdep/depinst/depinst.py -X test -g "--jobs 3" test
|
||||
python tools/boostdep/depinst/depinst.py -X test -g "--jobs 3" sort
|
||||
rm -rf libs/sort/*
|
||||
cp -r $GITHUB_WORKSPACE/* libs/sort
|
||||
./bootstrap.sh
|
||||
./b2 headers
|
||||
|
||||
echo '==================================> SCRIPT'
|
||||
|
||||
./b2 libs/sort/test toolset=$TOOLSET cxxstd=$CXXSTD
|
||||
|
||||
fi
|
||||
osx:
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
include:
|
||||
- name: "TOOLSET=clang CXXSTD=03,11,14,1z Job 2"
|
||||
buildtype: "boost"
|
||||
packages: ""
|
||||
os: "macos-12"
|
||||
cxx: "clang++"
|
||||
sources: ""
|
||||
llvm_os: ""
|
||||
llvm_ver: ""
|
||||
xcode_version: 14.2
|
||||
toolset: "clang"
|
||||
cxxstd: "03,11,14,1z"
|
||||
|
||||
runs-on: ${{ matrix.os }}
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
|
||||
- name: Set DEVELOPER_DIR
|
||||
if: matrix.xcode_version != ''
|
||||
run: echo "DEVELOPER_DIR=/Applications/Xcode_${{ matrix.xcode_version }}.app/Contents/Developer" >> $GITHUB_ENV
|
||||
- name: Test DEVELOPER_DIR
|
||||
run: echo $DEVELOPER_DIR
|
||||
|
||||
- name: "osx"
|
||||
shell: bash
|
||||
env:
|
||||
CXX: ${{ matrix.cxx }}
|
||||
SOURCES: ${{ matrix.sources }}
|
||||
LLVM_OS: ${{ matrix.llvm_os }}
|
||||
LLVM_VER: ${{ matrix.llvm_ver }}
|
||||
PACKAGES: ${{ matrix.packages }}
|
||||
JOB_BUILDTYPE: ${{ matrix.buildtype }}
|
||||
TOOLSET: ${{ matrix.toolset }}
|
||||
CXXSTD: ${{ matrix.cxxstd }}
|
||||
TRAVIS_BRANCH: ${{ github.base_ref }}
|
||||
TRAVIS_OS_NAME: "osx"
|
||||
./b2 -d0 headers
|
||||
- name: Test
|
||||
run: |
|
||||
echo '==================================> SETUP'
|
||||
set -e
|
||||
sudo mv /Library/Developer/CommandLineTools /Library/Developer/CommandLineTools.bck
|
||||
echo '==================================> PACKAGES'
|
||||
echo '==================================> INSTALL AND COMPILE'
|
||||
set -e
|
||||
export TRAVIS_BUILD_DIR=$(pwd)
|
||||
export TRAVIS_BRANCH=${TRAVIS_BRANCH:-$(echo $GITHUB_REF | awk 'BEGIN { FS = "/" } ; { print $3 }')}
|
||||
export VCS_COMMIT_ID=$GITHUB_SHA
|
||||
export GIT_COMMIT=$GITHUB_SHA
|
||||
export REPO_NAME=$(basename $GITHUB_REPOSITORY)
|
||||
export USER=$(whoami)
|
||||
export CC=${CC:-gcc}
|
||||
export PATH=~/.local/bin:/usr/local/bin:$PATH
|
||||
|
||||
if [ "$JOB_BUILDTYPE" == "boost" ]; then
|
||||
|
||||
echo '==================================> INSTALL'
|
||||
|
||||
BOOST_BRANCH=develop && [ "$TRAVIS_BRANCH" == "master" ] && BOOST_BRANCH=master || true
|
||||
cd ..
|
||||
git clone -b $BOOST_BRANCH https://github.com/boostorg/boost.git boost-root
|
||||
cd boost-root
|
||||
git submodule update --init tools/build
|
||||
git submodule update --init libs/config
|
||||
git submodule update --init tools/boostdep
|
||||
cp -r $TRAVIS_BUILD_DIR/* libs/sort
|
||||
python tools/boostdep/depinst/depinst.py sort
|
||||
./bootstrap.sh
|
||||
./b2 headers
|
||||
|
||||
echo '==================================> SCRIPT'
|
||||
|
||||
./b2 libs/sort/test toolset=$TOOLSET cxxstd=$CXXSTD
|
||||
|
||||
fi
|
||||
cd ../boost-root
|
||||
./b2 -j3 libs/sort/test toolset=${{matrix.toolset}} cxxstd=11,14,17,20
|
||||
|
||||
5
.vscode/settings.json
vendored
Normal file
5
.vscode/settings.json
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"githubPullRequests.ignoredPullRequestBranches": [
|
||||
"develop"
|
||||
]
|
||||
}
|
||||
@@ -50,8 +50,7 @@ void Generator_reverse_sorted (void);
|
||||
void Generator_reverse_sorted_end (size_t n_last);
|
||||
void Generator_reverse_sorted_middle (size_t n_last);
|
||||
|
||||
template<class IA, class compare>
|
||||
int Test (std::vector<IA> &B, compare comp = compare ());
|
||||
void Test (std::vector<uint64_t> &B);
|
||||
|
||||
int main (int argc, char *argv[])
|
||||
{
|
||||
@@ -66,205 +65,203 @@ int main (int argc, char *argv[])
|
||||
cout << "************************************************************\n";
|
||||
cout << std::endl;
|
||||
|
||||
cout<<"[ 1 ] block_indirect_sort [ 2 ] sample_sort\n";
|
||||
cout<<"[ 3 ] parallel_stable_sort\n\n";
|
||||
cout<<" | | | |\n";
|
||||
cout<<" | [ 1 ]| [ 2 ]| [ 3 ]|\n";
|
||||
cout<<"--------------------+------+------+------+\n";
|
||||
cout << "[ 1 ] block_indirect_sort [ 2 ] sample_sort\n";
|
||||
cout << "[ 3 ] parallel_stable_sort\n\n";
|
||||
cout << " | | | |\n";
|
||||
cout << " | [ 1 ]| [ 2 ]| [ 3 ]|\n";
|
||||
cout << "--------------------+------+------+------+\n";
|
||||
std::string empty_line =
|
||||
" | | | |\n";
|
||||
cout<<"random |";
|
||||
cout << "random |";
|
||||
Generator_random ();
|
||||
cout<<empty_line;
|
||||
cout<<"sorted |";
|
||||
cout << empty_line;
|
||||
cout << "sorted |";
|
||||
Generator_sorted ();
|
||||
|
||||
cout<<"sorted + 0.1% end |";
|
||||
cout << "sorted + 0.1% end |";
|
||||
Generator_sorted_end (NELEM / 1000);
|
||||
|
||||
cout<<"sorted + 1% end |";
|
||||
cout << "sorted + 1% end |";
|
||||
Generator_sorted_end (NELEM / 100);
|
||||
|
||||
cout<<"sorted + 10% end |";
|
||||
cout << "sorted + 10% end |";
|
||||
Generator_sorted_end (NELEM / 10);
|
||||
|
||||
cout<<empty_line;
|
||||
cout<<"sorted + 0.1% mid |";
|
||||
cout << empty_line;
|
||||
cout << "sorted + 0.1% mid |";
|
||||
Generator_sorted_middle (NELEM / 1000);
|
||||
|
||||
cout<<"sorted + 1% mid |";
|
||||
cout << "sorted + 1% mid |";
|
||||
Generator_sorted_middle (NELEM / 100);
|
||||
|
||||
cout<<"sorted + 10% mid |";
|
||||
cout << "sorted + 10% mid |";
|
||||
Generator_sorted_middle (NELEM / 10);
|
||||
|
||||
cout<<empty_line;
|
||||
cout<<"reverse sorted |";
|
||||
cout << empty_line;
|
||||
cout << "reverse sorted |";
|
||||
Generator_reverse_sorted ();
|
||||
|
||||
cout<<"rv sorted + 0.1% end|";
|
||||
cout << "rv sorted + 0.1% end|";
|
||||
Generator_reverse_sorted_end (NELEM / 1000);
|
||||
|
||||
cout<<"rv sorted + 1% end|";
|
||||
cout << "rv sorted + 1% end|";
|
||||
Generator_reverse_sorted_end (NELEM / 100);
|
||||
|
||||
cout<<"rv sorted + 10% end|";
|
||||
cout << "rv sorted + 10% end|";
|
||||
Generator_reverse_sorted_end (NELEM / 10);
|
||||
|
||||
cout<<empty_line;
|
||||
cout<<"rv sorted + 0.1% mid|";
|
||||
cout << empty_line;
|
||||
cout << "rv sorted + 0.1% mid|";
|
||||
Generator_reverse_sorted_middle (NELEM / 1000);
|
||||
|
||||
cout<<"rv sorted + 1% mid|";
|
||||
cout << "rv sorted + 1% mid|";
|
||||
Generator_reverse_sorted_middle (NELEM / 100);
|
||||
|
||||
cout<<"rv sorted + 10% mid|";
|
||||
cout << "rv sorted + 10% mid|";
|
||||
Generator_reverse_sorted_middle (NELEM / 10);
|
||||
cout<<"--------------------+------+------+------+\n";
|
||||
cout<<endl<<endl ;
|
||||
cout << "--------------------+------+------+------+\n";
|
||||
cout << endl << endl ;
|
||||
return 0;
|
||||
}
|
||||
void
|
||||
Generator_random (void)
|
||||
void Generator_random (void)
|
||||
{
|
||||
vector<uint64_t> A;
|
||||
vector <uint64_t> A;
|
||||
A.reserve (NELEM);
|
||||
A.clear ();
|
||||
if (fill_vector_uint64 ("input.bin", A, NELEM) != 0)
|
||||
{
|
||||
std::cout << "Error in the input file\n";
|
||||
return;
|
||||
std::exit (EXIT_FAILURE);
|
||||
};
|
||||
Test<uint64_t, std::less<uint64_t>> (A);
|
||||
}
|
||||
;
|
||||
void
|
||||
Generator_sorted (void)
|
||||
Test (A);
|
||||
};
|
||||
void Generator_sorted (void)
|
||||
{
|
||||
vector<uint64_t> A;
|
||||
|
||||
std::vector <uint64_t> A;
|
||||
A.reserve (NELEM);
|
||||
A.clear ();
|
||||
for (size_t i = 0; i < NELEM; ++i)
|
||||
for (uint64_t i = 0; i < NELEM; ++i)
|
||||
A.push_back (i);
|
||||
Test<uint64_t, std::less<uint64_t>> (A);
|
||||
|
||||
}
|
||||
|
||||
void Generator_sorted_end (size_t n_last)
|
||||
Test (A);
|
||||
};
|
||||
void Generator_sorted_end (uint64_t n_last)
|
||||
{
|
||||
vector<uint64_t> A;
|
||||
std::vector <uint64_t> A;
|
||||
A.reserve (NELEM);
|
||||
A.clear ();
|
||||
if (fill_vector_uint64 ("input.bin", A, NELEM + n_last) != 0)
|
||||
{
|
||||
std::cout << "Error in the input file\n";
|
||||
return;
|
||||
std::exit (EXIT_FAILURE);
|
||||
};
|
||||
std::sort (A.begin (), A.begin () + NELEM);
|
||||
|
||||
Test<uint64_t, std::less<uint64_t>> (A);
|
||||
|
||||
}
|
||||
;
|
||||
void Generator_sorted_middle (size_t n_last)
|
||||
Test (A);
|
||||
};
|
||||
void Generator_sorted_middle (uint64_t n_middle)
|
||||
{
|
||||
vector<uint64_t> A, B, C;
|
||||
A.reserve (NELEM);
|
||||
A.clear ();
|
||||
if (fill_vector_uint64 ("input.bin", A, NELEM + n_last) != 0)
|
||||
assert (n_middle > 1 && NELEM >= (n_middle -1));
|
||||
std::vector <uint64_t> A, aux;
|
||||
A.reserve (NELEM + n_middle);
|
||||
aux.reserve (n_middle);
|
||||
|
||||
if (fill_vector_uint64 ("input.bin", A, NELEM + n_middle) != 0)
|
||||
{
|
||||
std::cout << "Error in the input file\n";
|
||||
return;
|
||||
std::exit (EXIT_FAILURE);
|
||||
};
|
||||
for (size_t i = NELEM; i < A.size (); ++i)
|
||||
B.push_back (std::move (A[i]));
|
||||
A.resize ( NELEM);
|
||||
for (size_t i = 0; i < (NELEM >> 1); ++i)
|
||||
std::swap (A[i], A[NELEM - 1 - i]);
|
||||
for (uint64_t i = 0; i < n_middle; ++i) aux.push_back (A [i]);
|
||||
|
||||
std::sort (A.begin (), A.end ());
|
||||
size_t step = NELEM / n_last + 1;
|
||||
size_t pos = 0;
|
||||
std::sort (A.begin () + n_middle, A.end ());
|
||||
//------------------------------------------------------------------------
|
||||
// To insert n_middle elements, must have (n_middle - 1) intervals between
|
||||
// them. The size of the interval is step
|
||||
// The elements after the last element of aux don't need to be moved
|
||||
//-------------------------------------------------------------------------
|
||||
uint64_t step = NELEM / (n_middle - 1);
|
||||
A [0] = aux [0];
|
||||
uint64_t pos_read = n_middle, pos_write = 1;
|
||||
|
||||
for (size_t i = 0; i < B.size (); ++i, pos += step)
|
||||
for (uint64_t i = 1; i < n_middle; ++i)
|
||||
{
|
||||
C.push_back (B[i]);
|
||||
for (size_t k = 0; k < step; ++k)
|
||||
C.push_back (A[pos + k]);
|
||||
for (uint64_t k = 0 ; k < step; ++k)
|
||||
A [pos_write ++] = A [pos_read ++];
|
||||
A [pos_write ++] = aux [i];
|
||||
};
|
||||
while (pos < A.size ())
|
||||
C.push_back (A[pos++]);
|
||||
A = C;
|
||||
Test<uint64_t, std::less<uint64_t>> (A);
|
||||
}
|
||||
;
|
||||
aux.clear ();
|
||||
aux.reserve (0);
|
||||
Test (A);
|
||||
};
|
||||
void Generator_reverse_sorted (void)
|
||||
{
|
||||
vector<uint64_t> A;
|
||||
|
||||
std::vector<uint64_t> A;
|
||||
A.reserve (NELEM);
|
||||
A.clear ();
|
||||
for (size_t i = NELEM; i > 0; --i)
|
||||
for (uint64_t i = NELEM; i > 0; --i)
|
||||
A.push_back (i);
|
||||
Test<uint64_t, std::less<uint64_t>> (A);
|
||||
}
|
||||
void Generator_reverse_sorted_end (size_t n_last)
|
||||
Test (A);
|
||||
};
|
||||
void Generator_reverse_sorted_end (uint64_t n_last)
|
||||
{
|
||||
vector<uint64_t> A;
|
||||
std::vector <uint64_t> A;
|
||||
A.reserve (NELEM);
|
||||
A.clear ();
|
||||
if (fill_vector_uint64 ("input.bin", A, NELEM + n_last) != 0)
|
||||
{
|
||||
std::cout << "Error in the input file\n";
|
||||
return;
|
||||
std::exit (EXIT_FAILURE);
|
||||
};
|
||||
std::sort (A.begin (), A.begin () + NELEM);
|
||||
for (size_t i = 0; i < (NELEM >> 1); ++i)
|
||||
std::swap (A[i], A[NELEM - 1 - i]);
|
||||
for (uint64_t i = 0; i < (NELEM >> 1); ++i)
|
||||
std::swap (A [i], A [NELEM - 1 - i]);
|
||||
|
||||
Test<uint64_t, std::less<uint64_t>> (A);
|
||||
Test (A);
|
||||
}
|
||||
void Generator_reverse_sorted_middle (size_t n_last)
|
||||
void Generator_reverse_sorted_middle (uint64_t n_middle)
|
||||
{
|
||||
vector<uint64_t> A, B, C;
|
||||
A.reserve (NELEM);
|
||||
A.clear ();
|
||||
if (fill_vector_uint64 ("input.bin", A, NELEM + n_last) != 0)
|
||||
assert (n_middle > 1 && NELEM >= (n_middle -1));
|
||||
std::vector <uint64_t> A, aux;
|
||||
A.reserve (NELEM + n_middle);
|
||||
aux.reserve (n_middle);
|
||||
|
||||
if (fill_vector_uint64 ("input.bin", A, NELEM + n_middle) != 0)
|
||||
{
|
||||
std::cout << "Error in the input file\n";
|
||||
return;
|
||||
std::exit (EXIT_FAILURE);
|
||||
};
|
||||
for (size_t i = NELEM; i < A.size (); ++i)
|
||||
B.push_back (std::move (A[i]));
|
||||
A.resize ( NELEM);
|
||||
for (size_t i = 0; i < (NELEM >> 1); ++i)
|
||||
std::swap (A[i], A[NELEM - 1 - i]);
|
||||
for (uint64_t i = 0; i < n_middle; ++i) aux.push_back (A [i]);
|
||||
|
||||
std::sort (A.begin (), A.end ());
|
||||
size_t step = NELEM / n_last + 1;
|
||||
size_t pos = 0;
|
||||
std::sort (A.begin () + n_middle, A.end ());
|
||||
uint64_t pos1 = n_middle, pos2 = A.size () - 1;
|
||||
for (uint64_t i = 0; i < (NELEM >> 1); ++i)
|
||||
std::swap (A [pos1 ++], A [pos2 --]);
|
||||
//------------------------------------------------------------------------
|
||||
// To insert n_middle elements, must have (n_middle - 1) intervals between
|
||||
// them. The size of the interval is step
|
||||
// The elements after the last element of aux don't need to be moved
|
||||
//-------------------------------------------------------------------------
|
||||
uint64_t step = NELEM / (n_middle - 1);
|
||||
A [0] = aux [0];
|
||||
uint64_t pos_read = n_middle, pos_write = 1;
|
||||
|
||||
for (size_t i = 0; i < B.size (); ++i, pos += step)
|
||||
for (uint64_t i = 1; i < n_middle; ++i)
|
||||
{
|
||||
C.push_back (B[i]);
|
||||
for (size_t k = 0; k < step; ++k)
|
||||
C.push_back (A[pos + k]);
|
||||
for (uint64_t k = 0 ; k < step; ++k)
|
||||
A [pos_write ++] = A [pos_read ++];
|
||||
A [pos_write ++] = aux [i];
|
||||
};
|
||||
while (pos < A.size ())
|
||||
C.push_back (A[pos++]);
|
||||
A = C;
|
||||
Test<uint64_t, std::less<uint64_t>> (A);
|
||||
aux.clear ();
|
||||
aux.reserve (0);
|
||||
Test (A);
|
||||
};
|
||||
|
||||
|
||||
template<class IA, class compare>
|
||||
int Test (std::vector<IA> &B, compare comp)
|
||||
{ //---------------------------- begin --------------------------------
|
||||
void Test (std::vector <uint64_t> &B)
|
||||
{
|
||||
//---------------------------- begin --------------------------------
|
||||
std::less <uint64_t> comp ;
|
||||
double duration;
|
||||
time_point start, finish;
|
||||
std::vector<IA> A (B);
|
||||
std::vector<double> V;
|
||||
std::vector <uint64_t> A (B);
|
||||
std::vector <double> V;
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
A = B;
|
||||
@@ -291,11 +288,10 @@ int Test (std::vector<IA> &B, compare comp)
|
||||
//-----------------------------------------------------------------------
|
||||
// printing the vector
|
||||
//-----------------------------------------------------------------------
|
||||
std::cout<<std::setprecision(2)<<std::fixed;
|
||||
for ( uint32_t i =0 ; i < V.size() ; ++i)
|
||||
{ std::cout<<std::right<<std::setw(5)<<V[i]<<" |";
|
||||
std::cout << std::setprecision (2) << std::fixed;
|
||||
for (uint32_t i = 0; i < V.size (); ++i)
|
||||
{ std::cout << std::right << std::setw (5) << V [i] << " |";
|
||||
};
|
||||
std::cout<<std::endl;
|
||||
return 0;
|
||||
std::cout << std::endl;
|
||||
};
|
||||
|
||||
|
||||
@@ -26,12 +26,8 @@
|
||||
#include <boost/sort/common/time_measure.hpp>
|
||||
#include <boost/sort/common/file_vector.hpp>
|
||||
#include "boost/sort/common/int_array.hpp"
|
||||
|
||||
#include <boost/sort/sort.hpp>
|
||||
|
||||
#define NELEM 100000000
|
||||
#define NMAXSTRING 10000000
|
||||
|
||||
using namespace std;
|
||||
namespace bsc = boost::sort::common;
|
||||
namespace bsp = boost::sort;
|
||||
@@ -45,52 +41,38 @@ using bsc::int_array;
|
||||
using bsc::H_comp;
|
||||
using bsc::L_comp;
|
||||
|
||||
|
||||
template <class IA>
|
||||
void Generator_random (uint64_t N);
|
||||
|
||||
template <class IA>
|
||||
void Generator_random(uint64_t N);
|
||||
void Generator_sorted (uint64_t N);
|
||||
|
||||
template <class IA>
|
||||
void Generator_sorted(uint64_t N);
|
||||
template <class IA>
|
||||
void Generator_sorted_end(uint64_t N, size_t n_last );
|
||||
void Generator_sorted_end (uint64_t N, size_t n_last);
|
||||
|
||||
template <class IA>
|
||||
void Generator_sorted_middle(uint64_t N, size_t n_last );
|
||||
void Generator_sorted_middle (uint64_t N, size_t n_middle);
|
||||
|
||||
template <class IA>
|
||||
void Generator_reverse_sorted(uint64_t N);
|
||||
void Generator_reverse_sorted (uint64_t N);
|
||||
|
||||
template <class IA>
|
||||
void Generator_reverse_sorted_end(uint64_t N, size_t n_last );
|
||||
void Generator_reverse_sorted_end (uint64_t N, size_t n_last);
|
||||
|
||||
template <class IA>
|
||||
void Generator_reverse_sorted_middle(uint64_t N, size_t n_last );
|
||||
void Generator_reverse_sorted_middle (uint64_t N, size_t n_middle);
|
||||
|
||||
template < class IA >
|
||||
struct H_rightshift {
|
||||
inline uint64_t operator()(const IA& A1, unsigned offset) {
|
||||
return A1.counter() >> offset;
|
||||
}
|
||||
};
|
||||
|
||||
template < class IA >
|
||||
struct L_rightshift {
|
||||
inline uint64_t operator()(const IA& A1, unsigned offset) {
|
||||
return A1.M[0] >> offset;
|
||||
}
|
||||
};
|
||||
|
||||
template <class IA, class rightshift, class compare>
|
||||
int Test(std::vector<IA> &B, rightshift shift, compare comp, std::vector<double> & V );
|
||||
template <class IA, class compare>
|
||||
void Test (std::vector <IA> &B, compare comp, std::vector <double> & V );
|
||||
|
||||
template <class IA>
|
||||
void Test_size ( uint64_t N);
|
||||
void Test_size (uint64_t N);
|
||||
|
||||
void Print_vectors ( std::vector<double> & V1, std::vector<double> & V2);
|
||||
void Print_vectors (std::vector<double> &V1, std::vector<double> & V2);
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
const uint64_t NELEM = 100000000;
|
||||
cout << "\n\n";
|
||||
cout << "************************************************************\n";
|
||||
cout << "** **\n";
|
||||
@@ -172,320 +154,349 @@ int main(int argc, char *argv[])
|
||||
template <class IA>
|
||||
void Test_size ( uint64_t N)
|
||||
{
|
||||
cout<<"[ 1 ] block_indirect_sort [ 2 ] sample_sort\n";
|
||||
cout<<"[ 3 ] parallel_stable_sort\n\n";
|
||||
cout << "[ 1 ] block_indirect_sort [ 2 ] sample_sort\n";
|
||||
cout << "[ 3 ] parallel_stable_sort\n\n";
|
||||
|
||||
cout << " | [ 1 ] | [ 2 ] | [ 3 ] |\n";
|
||||
cout << " | H L | H L | H L |\n";
|
||||
cout << "--------------------+-----------+-----------+-----------+\n";
|
||||
std::string empty_line = " | | | |\n";
|
||||
|
||||
cout<<"random |";
|
||||
Generator_random<IA>(N);
|
||||
cout << "random |";
|
||||
Generator_random <IA> (N);
|
||||
|
||||
cout<<empty_line;
|
||||
cout<<"sorted |";
|
||||
Generator_sorted<IA>(N);
|
||||
cout << empty_line;
|
||||
cout << "sorted |";
|
||||
Generator_sorted <IA> (N);
|
||||
|
||||
cout<<"sorted + 0.1% end |";
|
||||
Generator_sorted_end<IA>(N, N / 1000);
|
||||
cout << "sorted + 0.1% end |";
|
||||
Generator_sorted_end <IA> (N, N / 1000);
|
||||
|
||||
cout<<"sorted + 1% end |";
|
||||
Generator_sorted_end<IA>(N, N / 100);
|
||||
cout << "sorted + 1% end |";
|
||||
Generator_sorted_end< IA> (N, N / 100);
|
||||
|
||||
cout<<"sorted + 10% end |";
|
||||
Generator_sorted_end<IA>(N, N / 10);
|
||||
cout << "sorted + 10% end |";
|
||||
Generator_sorted_end <IA> (N, N / 10);
|
||||
|
||||
cout<<empty_line;
|
||||
cout<<"sorted + 0.1% mid |";
|
||||
Generator_sorted_middle<IA>(N, N / 1000);
|
||||
cout << empty_line;
|
||||
cout << "sorted + 0.1% mid |";
|
||||
Generator_sorted_middle <IA> (N, N / 1000);
|
||||
|
||||
cout<<"sorted + 1% mid |";
|
||||
Generator_sorted_middle<IA>(N, N / 100);
|
||||
cout << "sorted + 1% mid |";
|
||||
Generator_sorted_middle <IA> (N, N / 100);
|
||||
|
||||
cout<<"sorted + 10% mid |";
|
||||
Generator_sorted_middle<IA>(N, N / 10);
|
||||
cout << "sorted + 10% mid |";
|
||||
Generator_sorted_middle <IA> (N, N / 10);
|
||||
|
||||
cout<<empty_line;
|
||||
cout<<"reverse sorted |";
|
||||
Generator_reverse_sorted<IA>(N);
|
||||
cout << empty_line;
|
||||
cout << "reverse sorted |";
|
||||
Generator_reverse_sorted <IA> (N);
|
||||
|
||||
cout<<"rv sorted + 0.1% end|";
|
||||
Generator_reverse_sorted_end<IA>(N, N / 1000);
|
||||
cout << "rv sorted + 0.1% end|";
|
||||
Generator_reverse_sorted_end <IA> (N, N / 1000);
|
||||
|
||||
cout<<"rv sorted + 1% end|";
|
||||
Generator_reverse_sorted_end<IA>(N, N / 100);
|
||||
cout << "rv sorted + 1% end|";
|
||||
Generator_reverse_sorted_end <IA> (N, N / 100);
|
||||
|
||||
cout<<"rv sorted + 10% end|";
|
||||
Generator_reverse_sorted_end<IA>(N, N / 10);
|
||||
cout << "rv sorted + 10% end|";
|
||||
Generator_reverse_sorted_end <IA> (N, N / 10);
|
||||
|
||||
cout<<empty_line;
|
||||
cout<<"rv sorted + 0.1% mid|";
|
||||
Generator_reverse_sorted_middle<IA>(N, N / 1000);
|
||||
cout << empty_line;
|
||||
cout << "rv sorted + 0.1% mid|";
|
||||
Generator_reverse_sorted_middle <IA> (N, N / 1000);
|
||||
|
||||
cout<<"rv sorted + 1% mid|";
|
||||
Generator_reverse_sorted_middle<IA>(N, N / 100);
|
||||
cout << "rv sorted + 1% mid|";
|
||||
Generator_reverse_sorted_middle <IA> (N, N / 100);
|
||||
|
||||
cout<<"rv sorted + 10% mid|";
|
||||
Generator_reverse_sorted_middle<IA>(N, N / 10);
|
||||
cout<< "--------------------+-----------+-----------+-----------+\n";
|
||||
cout<<endl<<endl<<endl;
|
||||
cout << "rv sorted + 10% mid|";
|
||||
Generator_reverse_sorted_middle <IA> (N, N / 10);
|
||||
cout << "--------------------+-----------+-----------+-----------+\n";
|
||||
cout << endl << endl << endl;
|
||||
}
|
||||
void Print_vectors ( std::vector<double> & V1, std::vector<double> & V2)
|
||||
{
|
||||
assert ( V1.size() == V2.size());
|
||||
std::cout<<std::setprecision(2)<<std::fixed;
|
||||
std::cout << std::setprecision(2)<<std::fixed;
|
||||
for ( uint32_t i =0 ; i < V1.size() ; ++i)
|
||||
{ std::cout<<std::right<<std::setw(5)<<V1[i]<<" ";
|
||||
std::cout<<std::right<<std::setw(5)<<V2[i]<<"|";
|
||||
{ std::cout << std::right<<std::setw(5)<<V1[i]<<" ";
|
||||
std::cout << std::right<<std::setw(5)<<V2[i]<<"|";
|
||||
};
|
||||
std::cout<<std::endl;
|
||||
std::cout << std::endl;
|
||||
}
|
||||
|
||||
template <class IA>
|
||||
void Generator_random(uint64_t N)
|
||||
void Generator_random (uint64_t N)
|
||||
{
|
||||
bsc::uint64_file_generator gen("input.bin");
|
||||
vector<IA> A;
|
||||
A.reserve(N);
|
||||
std::vector<double> V1, V2 ;
|
||||
bsc::uint64_file_generator gen ("input.bin");
|
||||
vector <IA> A;
|
||||
A.reserve (N);
|
||||
std::vector <double> V1, V2 ;
|
||||
|
||||
gen.reset();
|
||||
A.clear();
|
||||
for (uint32_t i = 0; i < N; i++) A.emplace_back(IA::generate(gen));
|
||||
gen.reset ();
|
||||
A.clear ();
|
||||
for (uint32_t i = 0; i < N; i++) A.emplace_back (IA::generate(gen));
|
||||
|
||||
Test(A, H_rightshift<IA>(), H_comp<IA>(), V1);
|
||||
|
||||
Test(A, L_rightshift<IA>(), L_comp<IA>(), V2);
|
||||
Print_vectors ( V1, V2 ) ;
|
||||
Test (A, H_comp <IA> (), V1);
|
||||
Test (A, L_comp <IA> (), V2);
|
||||
Print_vectors (V1, V2) ;
|
||||
};
|
||||
|
||||
template <class IA>
|
||||
void Generator_sorted(uint64_t N)
|
||||
{
|
||||
bsc::uint64_file_generator gen("input.bin");
|
||||
vector<IA> A;
|
||||
A.reserve(N);
|
||||
std::vector<double> V1, V2 ;
|
||||
bsc::uint64_file_generator gen ("input.bin");
|
||||
vector <IA> A;
|
||||
A.reserve (N);
|
||||
std::vector <double> V1, V2 ;
|
||||
|
||||
gen.reset();
|
||||
A.clear();
|
||||
for (uint32_t i = 0; i < N; i++) A.emplace_back(IA::generate(gen));
|
||||
gen.reset ();
|
||||
A.clear ();
|
||||
for (uint32_t i = 0; i < N; i++) A.emplace_back (IA::generate (gen));
|
||||
|
||||
std::sort( A.begin() , A.end(),H_comp<IA>() );
|
||||
Test(A, H_rightshift<IA>(), H_comp<IA>(), V1);
|
||||
std::sort (A.begin (), A.end (), H_comp <IA> ());
|
||||
Test (A, H_comp <IA> (), V1);
|
||||
|
||||
std::sort( A.begin() , A.end(),L_comp<IA>() );
|
||||
Test(A, L_rightshift<IA>(), L_comp<IA>(), V2);
|
||||
Print_vectors ( V1, V2 ) ;
|
||||
std::sort (A.begin (), A.end (), L_comp <IA> ());
|
||||
Test (A, L_comp <IA> (), V2);
|
||||
Print_vectors (V1, V2) ;
|
||||
};
|
||||
|
||||
template <class IA>
|
||||
void Generator_sorted_end(uint64_t N, size_t n_last )
|
||||
void Generator_sorted_end (uint64_t N, size_t n_last )
|
||||
{
|
||||
bsc::uint64_file_generator gen("input.bin");
|
||||
vector<IA> A;
|
||||
A.reserve(N);
|
||||
std::vector<double> V1, V2 ;
|
||||
bsc::uint64_file_generator gen ("input.bin");
|
||||
vector <IA> A;
|
||||
A.reserve (N);
|
||||
std::vector <double> V1, V2 ;
|
||||
|
||||
gen.reset();
|
||||
A.clear();
|
||||
gen.reset ();
|
||||
A.clear ();
|
||||
for (uint32_t i = 0; i < (N + n_last); i++)
|
||||
A.emplace_back(IA::generate(gen));
|
||||
std::sort ( A.begin() , A.begin() + N ,H_comp<IA>());
|
||||
A.emplace_back (IA::generate (gen));
|
||||
|
||||
std::sort (A.begin (), A.begin () + N, H_comp <IA> ());
|
||||
|
||||
Test(A, H_rightshift<IA>(), H_comp<IA>(),V1);
|
||||
std::sort ( A.begin() , A.begin() + N ,L_comp<IA>());
|
||||
Test (A, H_comp <IA> (), V1);
|
||||
std::sort (A.begin (), A.begin () + N, L_comp <IA> ());
|
||||
|
||||
Test(A, L_rightshift<IA>(), L_comp<IA>(), V2);
|
||||
Print_vectors ( V1, V2 ) ;
|
||||
Test (A, L_comp <IA> (), V2);
|
||||
Print_vectors (V1, V2) ;
|
||||
};
|
||||
template <class IA>
|
||||
void Generator_sorted_middle(uint64_t N, size_t n_last )
|
||||
void Generator_sorted_middle (uint64_t N, size_t n_middle )
|
||||
{
|
||||
bsc::uint64_file_generator gen("input.bin");
|
||||
std::vector<double> V1, V2 ;
|
||||
vector<IA> A;
|
||||
A.reserve(N + n_last);
|
||||
assert (n_middle > 1 && N >= (n_middle -1));
|
||||
bsc::uint64_file_generator gen ("input.bin");
|
||||
|
||||
std::vector <double> V1, V2; // vector with the times used
|
||||
vector <IA> A, aux;
|
||||
A.reserve (N + n_middle);
|
||||
aux.reserve (n_middle);
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
// H _ C O M P
|
||||
//-----------------------------------------------------------------------
|
||||
for (uint32_t i = 0; i < (N + n_middle); i++)
|
||||
A.emplace_back (IA::generate (gen));
|
||||
|
||||
for (size_t i = 0; i < n_middle; ++i)
|
||||
aux.push_back (std::move (A [i]));
|
||||
|
||||
std::sort (A.begin () + n_middle, A.end (), H_comp <IA> ());
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
// To insert n_middle elements, must have (n_middle - 1) intervals between
|
||||
// them. The size of the interval is step
|
||||
// The elements after the last element of aux don't need to be moved
|
||||
//-------------------------------------------------------------------------
|
||||
size_t step = N / (n_middle - 1);
|
||||
A [0] = std::move (aux [0]);
|
||||
size_t pos_read = n_middle, pos_write = 1;
|
||||
|
||||
{ A.clear() ;
|
||||
gen.reset();
|
||||
vector<IA> B, C;
|
||||
C.reserve(N + n_last);
|
||||
B.reserve ( n_last);
|
||||
for (uint32_t i = 0; i < (N + n_last); i++)
|
||||
C.emplace_back(IA::generate(gen));
|
||||
|
||||
for ( size_t i = N ; i < C.size() ; ++i)
|
||||
B.push_back ( std::move ( C[i]));
|
||||
|
||||
C.resize ( N);
|
||||
|
||||
std::sort ( C.begin() , C.end() ,H_comp<IA>());
|
||||
size_t step = N /n_last ;
|
||||
size_t pos = 0 ;
|
||||
|
||||
for ( size_t i =0 ; i < B.size() ; ++i)
|
||||
{ A.push_back ( B[i]);
|
||||
for ( size_t k = 0 ; k < step ; ++k )
|
||||
A.push_back ( C[pos++] );
|
||||
};
|
||||
while ( pos < C.size() )
|
||||
A.push_back ( C[pos++]);
|
||||
for (size_t i = 1; i < n_middle; ++i)
|
||||
{
|
||||
for (size_t k = 0 ; k < step; ++k)
|
||||
A [pos_write ++] = std::move (A [pos_read ++]);
|
||||
A [pos_write ++] = std::move (aux [i]);
|
||||
};
|
||||
|
||||
Test(A, H_rightshift<IA>(), H_comp<IA>(), V1);
|
||||
Test (A, H_comp <IA> (), V1);
|
||||
|
||||
{ A.clear() ;
|
||||
gen.reset();
|
||||
vector<IA> B,C;
|
||||
C.reserve(N + n_last);
|
||||
B.reserve ( n_last);
|
||||
for (uint32_t i = 0; i < (N + n_last); i++)
|
||||
C.emplace_back(IA::generate(gen));
|
||||
//----------------------------------------------------------------------
|
||||
// L _ C O M P
|
||||
//-----------------------------------------------------------------------
|
||||
gen.reset ();
|
||||
A.clear ();
|
||||
A.reserve (N + n_middle);
|
||||
aux.clear ();
|
||||
aux.reserve (n_middle);
|
||||
|
||||
for (uint32_t i = 0; i < (N + n_middle); i++)
|
||||
A.emplace_back (IA::generate (gen));
|
||||
|
||||
for (size_t i = 0; i < n_middle; ++i)
|
||||
aux.push_back (std::move (A [i]));
|
||||
|
||||
std::sort (A.begin () + n_middle, A.end (), L_comp <IA> ());
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
// To insert n_middle elements, must have (n_middle - 1) intervals between
|
||||
// them. The size of the interval is step
|
||||
// The elements after the last element of aux don't need to be moved
|
||||
//-------------------------------------------------------------------------
|
||||
step = N / (n_middle - 1);
|
||||
A [0] = std::move (aux [0]);
|
||||
pos_read = n_middle;
|
||||
pos_write = 1;
|
||||
|
||||
for ( size_t i = N ; i < C.size() ; ++i)
|
||||
B.push_back ( std::move ( C[i]));
|
||||
|
||||
C.resize ( N);
|
||||
|
||||
std::sort ( C.begin() , C.end() ,L_comp<IA>());
|
||||
size_t step = N /n_last ;
|
||||
size_t pos = 0 ;
|
||||
|
||||
for ( size_t i =0 ; i < B.size() ; ++i)
|
||||
{ A.push_back ( B[i]);
|
||||
for ( size_t k = 0 ; k < step ; ++k )
|
||||
A.push_back ( C[pos++] );
|
||||
};
|
||||
while ( pos < C.size() )
|
||||
A.push_back ( C[pos++]);
|
||||
for (size_t i = 1; i < n_middle; ++i)
|
||||
{
|
||||
for (size_t k = 0 ; k < step; ++k)
|
||||
A [pos_write ++] = std::move (A [pos_read ++]);
|
||||
A [pos_write ++] = std::move (aux [i]);
|
||||
};
|
||||
Test(A, L_rightshift<IA>(), L_comp<IA>(), V2);
|
||||
Print_vectors ( V1, V2 ) ;
|
||||
|
||||
Test (A, L_comp <IA> (), V2);
|
||||
Print_vectors (V1, V2) ;
|
||||
};
|
||||
template <class IA>
|
||||
void Generator_reverse_sorted(uint64_t N)
|
||||
void Generator_reverse_sorted (uint64_t N)
|
||||
{
|
||||
bsc::uint64_file_generator gen("input.bin");
|
||||
vector<IA> A;
|
||||
A.reserve(N);
|
||||
std::vector<double> V1, V2 ;
|
||||
bsc::uint64_file_generator gen ("input.bin");
|
||||
vector <IA> A;
|
||||
A.reserve (N);
|
||||
std::vector <double> V1, V2 ;
|
||||
|
||||
gen.reset();
|
||||
A.clear();
|
||||
for (uint32_t i = 0; i < N; i++) A.emplace_back(IA::generate(gen));
|
||||
gen.reset ();
|
||||
A.clear ();
|
||||
for (uint32_t i = 0; i < N; i++) A.emplace_back (IA::generate (gen));
|
||||
|
||||
std::sort( A.begin() , A.end(),H_comp<IA>() );
|
||||
for ( size_t i = 0; i < (A.size() >>1) ; ++i)
|
||||
std::swap ( A[i], A[A.size() - i -1 ]);
|
||||
std::sort (A.begin (), A.end (), H_comp <IA> ());
|
||||
for (size_t i = 0; i < (A.size () >>1); ++i)
|
||||
std::swap (A [i], A [A.size () - i - 1]);
|
||||
|
||||
Test(A, H_rightshift<IA>(), H_comp<IA>(), V1);
|
||||
Test (A, H_comp <IA> (), V1);
|
||||
|
||||
std::sort( A.begin() , A.end(),L_comp<IA>() );
|
||||
for ( size_t i = 0; i < (A.size() >>1) ; ++i)
|
||||
std::swap ( A[i], A[A.size() - i -1 ]);
|
||||
Test(A, L_rightshift<IA>(), L_comp<IA>(), V2);
|
||||
Print_vectors ( V1, V2 ) ;
|
||||
std::sort (A.begin (), A.end (), L_comp <IA> ());
|
||||
for (size_t i = 0; i < (A.size () >> 1); ++i)
|
||||
std::swap (A [i], A [A.size() - i - 1]);
|
||||
|
||||
Test (A, L_comp <IA> (), V2);
|
||||
Print_vectors (V1, V2) ;
|
||||
};
|
||||
template <class IA>
|
||||
void Generator_reverse_sorted_end(uint64_t N, size_t n_last )
|
||||
{
|
||||
bsc::uint64_file_generator gen("input.bin");
|
||||
vector<IA> A;
|
||||
A.reserve(N);
|
||||
std::vector<double> V1, V2 ;
|
||||
|
||||
gen.reset();
|
||||
A.clear();
|
||||
template <class IA>
|
||||
void Generator_reverse_sorted_end (uint64_t N, size_t n_last )
|
||||
{
|
||||
bsc::uint64_file_generator gen ("input.bin");
|
||||
vector <IA> A;
|
||||
A.reserve (N);
|
||||
std::vector <double> V1, V2 ;
|
||||
|
||||
gen.reset ();
|
||||
A.clear ();
|
||||
for (uint32_t i = 0; i < (N + n_last); i++)
|
||||
A.emplace_back(IA::generate(gen));
|
||||
std::sort ( A.begin() , A.begin() + N ,H_comp<IA>());
|
||||
for ( size_t i =0 ; i < (N>>1); ++i)
|
||||
std::swap ( A[i], A[N-1-i]);
|
||||
A.emplace_back (IA::generate (gen));
|
||||
|
||||
std::sort (A.begin (), A.begin () + N , H_comp <IA> ());
|
||||
for (size_t i =0 ; i < (N >> 1); ++i)
|
||||
std::swap (A [i], A [N - 1 - i]);
|
||||
|
||||
Test(A, H_rightshift<IA>(), H_comp<IA>(), V1);
|
||||
std::sort ( A.begin() , A.begin() + N ,L_comp<IA>());
|
||||
for ( size_t i =0 ; i < (N>>1); ++i)
|
||||
std::swap ( A[i], A[N-1-i]);
|
||||
Test (A, H_comp <IA> (), V1);
|
||||
std::sort (A.begin (), A.begin () + N, L_comp <IA> ());
|
||||
for (size_t i = 0; i < (N >> 1); ++i)
|
||||
std::swap (A [i], A [N - 1 - i]);
|
||||
|
||||
Test(A, L_rightshift<IA>(), L_comp<IA>(), V2);
|
||||
Print_vectors ( V1, V2 ) ;
|
||||
Test (A, L_comp <IA> (), V2);
|
||||
Print_vectors (V1, V2) ;
|
||||
};
|
||||
|
||||
template <class IA>
|
||||
void Generator_reverse_sorted_middle(uint64_t N, size_t n_last )
|
||||
void Generator_reverse_sorted_middle (uint64_t N, size_t n_middle )
|
||||
{
|
||||
bsc::uint64_file_generator gen("input.bin");
|
||||
std::vector<double> V1, V2 ;
|
||||
vector<IA> A;
|
||||
A.reserve(N + n_last);
|
||||
assert (n_middle > 1 && N >= (n_middle -1));
|
||||
bsc::uint64_file_generator gen ("input.bin");
|
||||
|
||||
std::vector <double> V1, V2; // vector with the times used
|
||||
vector <IA> A, aux;
|
||||
A.reserve (N + n_middle);
|
||||
aux.reserve (n_middle);
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
// H _ C O M P
|
||||
//-----------------------------------------------------------------------
|
||||
for (uint32_t i = 0; i < (N + n_middle); i++)
|
||||
A.emplace_back (IA::generate (gen));
|
||||
|
||||
for (size_t i = 0; i < n_middle; ++i)
|
||||
aux.push_back (std::move (A [i]));
|
||||
|
||||
std::sort (A.begin () + n_middle, A.end (), H_comp <IA> ());
|
||||
uint64_t pos1 = n_middle, pos2 = A.size () - 1;
|
||||
for (uint64_t i = 0; i < (N >> 1); ++i)
|
||||
std::swap (A [pos1 ++], A [pos2 --]);
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
// To insert n_middle elements, must have (n_middle - 1) intervals between
|
||||
// them. The size of the interval is step
|
||||
// The elements after the last element of aux don't need to be moved
|
||||
//-------------------------------------------------------------------------
|
||||
size_t step = N / (n_middle - 1);
|
||||
A [0] = std::move (aux [0]);
|
||||
size_t pos_read = n_middle, pos_write = 1;
|
||||
|
||||
{ A.clear() ;
|
||||
gen.reset();
|
||||
vector<IA> B,C;
|
||||
C.reserve(N + n_last);
|
||||
B.reserve ( n_last);
|
||||
for (uint32_t i = 0; i < (N + n_last); i++)
|
||||
C.emplace_back(IA::generate(gen));
|
||||
|
||||
for ( size_t i = N ; i < C.size() ; ++i)
|
||||
B.push_back ( std::move ( C[i]));
|
||||
|
||||
C.resize ( N);
|
||||
|
||||
std::sort ( C.begin() , C.end() ,H_comp<IA>());
|
||||
|
||||
for ( size_t i =0 ; i < (N>>1); ++i)
|
||||
std::swap ( C[i], C[N-1-i]);
|
||||
|
||||
size_t step = N /n_last ;
|
||||
size_t pos = 0 ;
|
||||
|
||||
for ( size_t i =0 ; i < B.size() ; ++i)
|
||||
{ A.push_back ( B[i]);
|
||||
for ( size_t k = 0 ; k < step ; ++k )
|
||||
A.push_back ( C[pos++ ] );
|
||||
};
|
||||
while ( pos < C.size() )
|
||||
A.push_back ( C[pos++]);
|
||||
for (size_t i = 1; i < n_middle; ++i)
|
||||
{
|
||||
for (size_t k = 0 ; k < step; ++k)
|
||||
A [pos_write ++] = std::move (A [pos_read ++]);
|
||||
A [pos_write ++] = std::move (aux [i]);
|
||||
};
|
||||
|
||||
Test(A, H_rightshift<IA>(), H_comp<IA>(), V1);
|
||||
Test (A, H_comp <IA> (), V1);
|
||||
|
||||
{ A.clear() ;
|
||||
gen.reset();
|
||||
vector<IA> B,C;
|
||||
C.reserve(N + n_last);
|
||||
B.reserve ( n_last);
|
||||
for (uint32_t i = 0; i < (N + n_last); i++)
|
||||
C.emplace_back(IA::generate(gen));
|
||||
//----------------------------------------------------------------------
|
||||
// L _ C O M P
|
||||
//-----------------------------------------------------------------------
|
||||
gen.reset ();
|
||||
A.clear ();
|
||||
A.reserve (N + n_middle);
|
||||
aux.clear ();
|
||||
aux.reserve (n_middle);
|
||||
|
||||
for (uint32_t i = 0; i < (N + n_middle); i++)
|
||||
A.emplace_back (IA::generate (gen));
|
||||
|
||||
for (size_t i = 0; i < n_middle; ++i)
|
||||
aux.push_back (std::move (A [i]));
|
||||
|
||||
std::sort (A.begin () + n_middle, A.end (), L_comp <IA> ());
|
||||
pos1 = n_middle;
|
||||
pos2 = A.size () - 1;
|
||||
for (uint64_t i = 0; i < (N >> 1); ++i)
|
||||
std::swap (A [pos1 ++], A [pos2 --]);
|
||||
//------------------------------------------------------------------------
|
||||
// To insert n_middle elements, must have (n_middle - 1) intervals between
|
||||
// them. The size of the interval is step
|
||||
// The elements after the last element of aux don't need to be moved
|
||||
//-------------------------------------------------------------------------
|
||||
step = N / (n_middle - 1);
|
||||
A [0] = std::move (aux [0]);
|
||||
pos_read = n_middle;
|
||||
pos_write = 1;
|
||||
|
||||
for ( size_t i = N ; i < C.size() ; ++i)
|
||||
B.push_back ( std::move ( C[i]));
|
||||
|
||||
C.resize ( N);
|
||||
|
||||
std::sort ( C.begin() , C.end() ,L_comp<IA>());
|
||||
|
||||
for ( size_t i =0 ; i < (N>>1); ++i)
|
||||
std::swap ( C[i], C[N-1-i]);
|
||||
size_t step = N /n_last ;
|
||||
size_t pos = 0 ;
|
||||
|
||||
for ( size_t i =0 ; i < B.size() ; ++i)
|
||||
{ A.push_back ( B[i]);
|
||||
for ( size_t k = 0 ; k < step ; ++k )
|
||||
A.push_back ( C[pos++ ] );
|
||||
};
|
||||
while ( pos < C.size() )
|
||||
A.push_back ( C[pos++]);
|
||||
for (size_t i = 1; i < n_middle; ++i)
|
||||
{
|
||||
for (size_t k = 0 ; k < step; ++k)
|
||||
A [pos_write ++] = std::move (A [pos_read ++]);
|
||||
A [pos_write ++] = std::move (aux [i]);
|
||||
};
|
||||
|
||||
Test(A, L_rightshift<IA>(), L_comp<IA>(), V2);
|
||||
Print_vectors ( V1, V2 ) ;
|
||||
Test (A, L_comp <IA> (), V2);
|
||||
Print_vectors (V1, V2) ;
|
||||
};
|
||||
|
||||
template<class IA, class rightshift, class compare>
|
||||
int Test (std::vector<IA> &B, rightshift shift, compare comp,std::vector<double> &V)
|
||||
template<class IA, class compare>
|
||||
void Test (std::vector <IA> &B, compare comp, std::vector <double> &V)
|
||||
{ //---------------------------- begin --------------------------------
|
||||
double duration;
|
||||
time_point start, finish;
|
||||
@@ -514,52 +525,5 @@ int Test (std::vector<IA> &B, rightshift shift, compare comp,std::vector<double>
|
||||
finish = now ();
|
||||
duration = subtract_time (finish, start);
|
||||
V.push_back (duration);
|
||||
//cout << duration << " secs\n";
|
||||
/*
|
||||
A = B;
|
||||
start = now ();
|
||||
spinsort (A.begin (), A.end (), comp);
|
||||
finish = now ();
|
||||
duration = subtract_time (finish, start);
|
||||
V.push_back (duration);
|
||||
|
||||
A = B;
|
||||
start = now ();
|
||||
timsort (A.begin (), A.end (), comp);
|
||||
finish = now ();
|
||||
duration = subtract_time (finish, start);
|
||||
V.push_back (duration);
|
||||
|
||||
|
||||
A = B;
|
||||
//cout << "Boost spreadsort : ";
|
||||
int sorted_count = 0;
|
||||
for (unsigned i = 0; i + 1 < A.size(); ++i)
|
||||
{
|
||||
if (comp(A[i], A[i+1]))
|
||||
{
|
||||
sorted_count++;
|
||||
};
|
||||
};
|
||||
start = now ();
|
||||
boost::sort::spreadsort::integer_sort (A.begin (), A.end (), shift, comp);
|
||||
finish = now ();
|
||||
duration = subtract_time (finish, start);
|
||||
int identical = 0;
|
||||
for (unsigned i = 0; i + 1 < A.size(); ++i)
|
||||
{
|
||||
if (A[i].counter() != sorted[i].counter())
|
||||
{
|
||||
cout << "incorrect!" << std::endl;
|
||||
}
|
||||
if (!comp(A[i], A[i+1]) && !comp(A[i+1], A[i]))
|
||||
{
|
||||
identical++;
|
||||
};
|
||||
};
|
||||
// cout << "identical: " << identical << " pre-sorted: " << sorted_count << std::endl;
|
||||
V.push_back (duration);
|
||||
//cout << duration << " secs\n";
|
||||
*/
|
||||
return 0;
|
||||
};
|
||||
|
||||
@@ -40,18 +40,17 @@ using bsc::subtract_time;
|
||||
|
||||
|
||||
void Generator_random (void);
|
||||
void Generator_sorted(void);
|
||||
void Generator_sorted_end(size_t n_last);
|
||||
void Generator_sorted_middle (size_t n_last);
|
||||
void Generator_reverse_sorted(void);
|
||||
void Generator_reverse_sorted_end(size_t n_last);
|
||||
void Generator_reverse_sorted_middle(size_t n_last);
|
||||
void Generator_sorted (void);
|
||||
void Generator_sorted_end( size_t n_last);
|
||||
void Generator_sorted_middle (size_t n_middle);
|
||||
void Generator_reverse_sorted (void);
|
||||
void Generator_reverse_sorted_end (size_t n_last);
|
||||
void Generator_reverse_sorted_middle (size_t n_middle);
|
||||
|
||||
template <class IA, class compare>
|
||||
int Test(std::vector<IA> &B, compare comp = compare());
|
||||
void Test (std::vector <std::string> &B);
|
||||
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
int main(int argc, char *argv [])
|
||||
{
|
||||
cout << "\n\n";
|
||||
cout << "************************************************************\n";
|
||||
@@ -64,212 +63,223 @@ int main(int argc, char *argv[])
|
||||
cout << "************************************************************\n";
|
||||
cout << std::endl;
|
||||
|
||||
cout<<"[ 1 ] block_indirect_sort [ 2 ] sample_sort\n";
|
||||
cout<<"[ 3 ] parallel_stable_sort\n\n";
|
||||
cout<<" | | | |\n";
|
||||
cout<<" | [ 1 ]| [ 2 ]| [ 3 ]|\n";
|
||||
cout<<"--------------------+------+------+------+\n";
|
||||
cout << "[ 1 ] block_indirect_sort [ 2 ] sample_sort\n";
|
||||
cout << "[ 3 ] parallel_stable_sort\n\n";
|
||||
cout << " | | | |\n";
|
||||
cout << " | [ 1 ]| [ 2 ]| [ 3 ]|\n";
|
||||
cout << "--------------------+------+------+------+\n";
|
||||
std::string empty_line =
|
||||
" | | | |\n";
|
||||
|
||||
cout<<"random |";
|
||||
cout << "random |";
|
||||
Generator_random ();
|
||||
|
||||
cout<<empty_line;
|
||||
cout<<"sorted |";
|
||||
Generator_sorted();
|
||||
cout << empty_line;
|
||||
cout << "sorted |";
|
||||
Generator_sorted ();
|
||||
|
||||
cout<<"sorted + 0.1% end |";
|
||||
Generator_sorted_end(NMAXSTRING / 1000);
|
||||
cout << "sorted + 0.1% end |";
|
||||
Generator_sorted_end (NMAXSTRING / 1000);
|
||||
|
||||
cout<<"sorted + 1% end |";
|
||||
Generator_sorted_end(NMAXSTRING / 100);
|
||||
cout << "sorted + 1% end |";
|
||||
Generator_sorted_end (NMAXSTRING / 100);
|
||||
|
||||
cout<<"sorted + 10% end |";
|
||||
Generator_sorted_end(NMAXSTRING / 10);
|
||||
cout << "sorted + 10% end |";
|
||||
Generator_sorted_end (NMAXSTRING / 10);
|
||||
|
||||
cout<<empty_line;
|
||||
cout<<"sorted + 0.1% mid |";
|
||||
cout << empty_line;
|
||||
cout << "sorted + 0.1% mid |";
|
||||
Generator_sorted_middle (NMAXSTRING / 1000);
|
||||
|
||||
cout<<"sorted + 1% mid |";
|
||||
cout << "sorted + 1% mid |";
|
||||
Generator_sorted_middle (NMAXSTRING / 100);
|
||||
|
||||
cout<<"sorted + 10% mid |";
|
||||
cout << "sorted + 10% mid |";
|
||||
Generator_sorted_middle (NMAXSTRING / 10 );
|
||||
|
||||
cout<<empty_line;
|
||||
cout<<"reverse sorted |";
|
||||
Generator_reverse_sorted();
|
||||
cout << empty_line;
|
||||
cout << "reverse sorted |";
|
||||
Generator_reverse_sorted ();
|
||||
|
||||
cout<<"rv sorted + 0.1% end|";
|
||||
Generator_reverse_sorted_end(NMAXSTRING / 1000);
|
||||
cout << "rv sorted + 0.1% end|";
|
||||
Generator_reverse_sorted_end (NMAXSTRING / 1000);
|
||||
|
||||
cout<<"rv sorted + 1% end|";
|
||||
Generator_reverse_sorted_end(NMAXSTRING / 100);
|
||||
cout << "rv sorted + 1% end|";
|
||||
Generator_reverse_sorted_end (NMAXSTRING / 100);
|
||||
|
||||
cout<<"rv sorted + 10% end|";
|
||||
Generator_reverse_sorted_end(NMAXSTRING / 10);
|
||||
cout << "rv sorted + 10% end|";
|
||||
Generator_reverse_sorted_end (NMAXSTRING / 10);
|
||||
|
||||
cout<<empty_line;
|
||||
cout<<"rv sorted + 0.1% mid|";
|
||||
Generator_reverse_sorted_middle(NMAXSTRING / 1000);
|
||||
cout << empty_line;
|
||||
cout << "rv sorted + 0.1% mid|";
|
||||
Generator_reverse_sorted_middle (NMAXSTRING / 1000);
|
||||
|
||||
cout<<"rv sorted + 1% mid|";
|
||||
Generator_reverse_sorted_middle(NMAXSTRING / 100);
|
||||
cout << "rv sorted + 1% mid|";
|
||||
Generator_reverse_sorted_middle (NMAXSTRING / 100);
|
||||
|
||||
cout<<"rv sorted + 10% mid|";
|
||||
Generator_reverse_sorted_middle(NMAXSTRING / 10);
|
||||
cout << "rv sorted + 10% mid|";
|
||||
Generator_reverse_sorted_middle (NMAXSTRING / 10);
|
||||
|
||||
cout<< "--------------------+------+------+------+\n";
|
||||
cout<<endl<<endl ;
|
||||
cout << "--------------------+------+------+------+\n";
|
||||
cout << endl <<endl ;
|
||||
return 0;
|
||||
}
|
||||
|
||||
void Generator_random(void)
|
||||
void Generator_random (void)
|
||||
{
|
||||
std::vector<std::string> A;
|
||||
A.reserve(NMAXSTRING);
|
||||
A.clear();
|
||||
if (bsc::fill_vector_string("input.bin", A, NMAXSTRING) != 0)
|
||||
std::vector <std::string> A;
|
||||
A.reserve (NMAXSTRING);
|
||||
A.clear ();
|
||||
if (bsc::fill_vector_string ("input.bin", A, NMAXSTRING) != 0)
|
||||
{
|
||||
std::cout << "Error in the input file\n";
|
||||
return;
|
||||
std::exit (EXIT_FAILURE);
|
||||
};
|
||||
Test<std::string, std::less<std::string>>(A);
|
||||
|
||||
Test (A);
|
||||
};
|
||||
void Generator_sorted(void)
|
||||
void Generator_sorted (void)
|
||||
{
|
||||
std::vector<std::string> A;
|
||||
A.reserve(NMAXSTRING);
|
||||
A.clear();
|
||||
if (bsc::fill_vector_string("input.bin", A, NMAXSTRING) != 0)
|
||||
std::vector <std::string> A;
|
||||
A.reserve (NMAXSTRING);
|
||||
A.clear ();
|
||||
if (bsc::fill_vector_string ("input.bin", A, NMAXSTRING) != 0)
|
||||
{
|
||||
std::cout << "Error in the input file\n";
|
||||
return;
|
||||
std::exit (EXIT_FAILURE);
|
||||
};
|
||||
std::sort( A.begin() , A.end() );
|
||||
Test<std::string, std::less<std::string>>(A);
|
||||
std::sort (A.begin (), A.end ());
|
||||
Test (A);
|
||||
};
|
||||
|
||||
void Generator_sorted_end(size_t n_last)
|
||||
void Generator_sorted_end (size_t n_last)
|
||||
{
|
||||
std::vector<std::string> A;
|
||||
A.reserve(NMAXSTRING);
|
||||
A.clear();
|
||||
if (bsc::fill_vector_string("input.bin", A, NMAXSTRING+ n_last) != 0)
|
||||
std::vector <std::string> A;
|
||||
A.reserve (NMAXSTRING);
|
||||
A.clear ();
|
||||
if (bsc::fill_vector_string ("input.bin", A, NMAXSTRING+ n_last) != 0)
|
||||
{
|
||||
std::cout << "Error in the input file\n";
|
||||
return;
|
||||
std::exit (EXIT_FAILURE);
|
||||
};
|
||||
std::sort (A.begin() , A.begin() + NMAXSTRING );
|
||||
Test<std::string, std::less<std::string>>(A);
|
||||
std::sort (A.begin (), A.begin () + NMAXSTRING );
|
||||
Test (A);
|
||||
};
|
||||
void Generator_sorted_middle(size_t n_last)
|
||||
void Generator_sorted_middle (size_t n_middle)
|
||||
{
|
||||
std::vector<std::string> A,B,C;
|
||||
A.reserve(NMAXSTRING);
|
||||
A.clear();
|
||||
if (bsc::fill_vector_string("input.bin", A, NMAXSTRING + n_last) != 0)
|
||||
assert (n_middle > 1 && NMAXSTRING >= (n_middle -1));
|
||||
vector <std::string> A, aux;
|
||||
A.reserve (NMAXSTRING + n_middle);
|
||||
aux.reserve (n_middle);
|
||||
|
||||
if (bsc::fill_vector_string ("input.bin", A, NMAXSTRING + n_middle) != 0)
|
||||
{
|
||||
std::cout << "Error in the input file\n";
|
||||
return;
|
||||
std::exit (EXIT_FAILURE);
|
||||
};
|
||||
for ( size_t i = NMAXSTRING ; i < A.size() ; ++i)
|
||||
B.push_back ( std::move ( A[i]));
|
||||
A.resize ( NMAXSTRING);
|
||||
std::sort (A.begin() , A.end() );
|
||||
size_t step = NMAXSTRING /n_last +1 ;
|
||||
size_t pos = 0 ;
|
||||
for (size_t i = 0; i < n_middle; ++i) aux.push_back (std::move (A [i]));
|
||||
|
||||
for ( size_t i =0 ; i < B.size() ; ++i, pos += step)
|
||||
{ C.push_back ( B[i]);
|
||||
for ( size_t k = 0 ; k < step ; ++k )
|
||||
C.push_back ( A[pos + k] );
|
||||
std::sort (A.begin () + n_middle, A.end ());
|
||||
//------------------------------------------------------------------------
|
||||
// To insert n_middle elements, must have (n_middle - 1) intervals between
|
||||
// them. The size of the interval is step
|
||||
// The elements after the last element of aux don't need to be moved
|
||||
//-------------------------------------------------------------------------
|
||||
size_t step = NMAXSTRING / (n_middle - 1);
|
||||
A [0] = std::move (aux [0]);
|
||||
size_t pos_read = n_middle, pos_write = 1;
|
||||
|
||||
for (size_t i = 1; i < n_middle; ++i)
|
||||
{
|
||||
for (size_t k = 0 ; k < step; ++k)
|
||||
A [pos_write ++] = std::move (A [pos_read ++]);
|
||||
A [pos_write ++] = std::move (aux [i]);
|
||||
};
|
||||
while ( pos < A.size() ) C.push_back ( A[pos++]);
|
||||
A = C ;
|
||||
|
||||
Test<std::string, std::less<std::string>>(A);
|
||||
aux.clear ();
|
||||
aux.reserve (0);
|
||||
Test (A);
|
||||
};
|
||||
|
||||
void Generator_reverse_sorted(void)
|
||||
void Generator_reverse_sorted (void)
|
||||
{
|
||||
std::vector<std::string> A;
|
||||
A.reserve(NMAXSTRING);
|
||||
A.clear();
|
||||
if (bsc::fill_vector_string("input.bin", A, NMAXSTRING) != 0)
|
||||
std::vector <std::string> A;
|
||||
A.reserve (NMAXSTRING);
|
||||
{
|
||||
std::vector <std::string> B;
|
||||
B.reserve (NMAXSTRING);
|
||||
if (bsc::fill_vector_string ("input.bin", B, NMAXSTRING) != 0)
|
||||
{
|
||||
std::cout << "Error in the input file\n";
|
||||
std::exit (EXIT_FAILURE);
|
||||
};
|
||||
std::sort (B.begin(), B.end());
|
||||
A.clear ();
|
||||
for (size_t i = 0; i < NMAXSTRING; ++i)
|
||||
A.push_back (B [NMAXSTRING - 1 - i]);
|
||||
};
|
||||
Test (A);
|
||||
};
|
||||
void Generator_reverse_sorted_end (size_t n_last)
|
||||
{
|
||||
std::vector <std::string> A;
|
||||
A.reserve (NMAXSTRING);
|
||||
A.clear ();
|
||||
if (bsc::fill_vector_string ("input.bin", A, NMAXSTRING + n_last) != 0)
|
||||
{
|
||||
std::cout << "Error in the input file\n";
|
||||
return;
|
||||
std::exit (EXIT_FAILURE);
|
||||
};
|
||||
std::sort( A.begin() , A.end());
|
||||
size_t nmid = (A.size() >>1), nlast = A.size() -1 ;
|
||||
for (size_t i = 0 ; i < nmid ;++i)
|
||||
std::swap ( A[i], A [nlast -i]);
|
||||
|
||||
Test<std::string, std::less<std::string>>(A);
|
||||
std::sort (A.begin (), A.begin () + NMAXSTRING);
|
||||
for (size_t i = 0; i < (NMAXSTRING >> 1); ++i)
|
||||
std::swap (A [i], A [NMAXSTRING - 1 - i]);
|
||||
|
||||
Test (A);
|
||||
};
|
||||
void Generator_reverse_sorted_end(size_t n_last)
|
||||
void Generator_reverse_sorted_middle (size_t n_middle)
|
||||
{
|
||||
std::vector<std::string> A;
|
||||
A.reserve(NMAXSTRING);
|
||||
A.clear();
|
||||
if (bsc::fill_vector_string("input.bin", A, NMAXSTRING+ n_last) != 0)
|
||||
assert (n_middle > 1 && NMAXSTRING >= (n_middle -1));
|
||||
vector <std::string> A, aux;
|
||||
A.reserve (NMAXSTRING + n_middle);
|
||||
aux.reserve (n_middle);
|
||||
|
||||
if (bsc::fill_vector_string ("input.bin", A, NMAXSTRING + n_middle) != 0)
|
||||
{
|
||||
std::cout << "Error in the input file\n";
|
||||
return;
|
||||
std::exit (EXIT_FAILURE);
|
||||
};
|
||||
std::sort (A.begin() , A.begin() + NMAXSTRING );
|
||||
for ( size_t i =0 ; i< (NMAXSTRING >>1); ++i)
|
||||
std::swap ( A[i], A[NMAXSTRING - 1 - i]);
|
||||
for (size_t i = 0; i < n_middle; ++i) aux.push_back (std::move (A [i]));
|
||||
|
||||
Test<std::string, std::less<std::string>>(A);
|
||||
std::sort (A.begin () + n_middle, A.end ());
|
||||
|
||||
size_t pos1 = n_middle, pos2 = A.size () - 1;
|
||||
for (size_t i = 0; i < (NMAXSTRING >> 1); ++i)
|
||||
std::swap (A [pos1 ++], A [pos2 --]);
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
// To insert n_middle elements, must have (n_middle - 1) intervals between
|
||||
// them. The size of the interval is step
|
||||
// The elements after the last element of aux don't need to be moved
|
||||
//-------------------------------------------------------------------------
|
||||
size_t step = NMAXSTRING / (n_middle - 1);
|
||||
A [0] = std::move (aux [0]);
|
||||
size_t pos_read = n_middle, pos_write = 1;
|
||||
|
||||
};
|
||||
void Generator_reverse_sorted_middle(size_t n_last)
|
||||
{
|
||||
std::vector<std::string> A,B,C;
|
||||
A.reserve(NMAXSTRING);
|
||||
A.clear();
|
||||
if (bsc::fill_vector_string("input.bin", A, NMAXSTRING + n_last) != 0)
|
||||
for (size_t i = 1; i < n_middle; ++i)
|
||||
{
|
||||
std::cout << "Error in the input file\n";
|
||||
return;
|
||||
for (size_t k = 0 ; k < step; ++k)
|
||||
A [pos_write ++] = std::move (A [pos_read ++]);
|
||||
A [pos_write ++] = std::move (aux [i]);
|
||||
};
|
||||
for ( size_t i = NMAXSTRING ; i < A.size() ; ++i)
|
||||
B.push_back ( std::move ( A[i]));
|
||||
A.resize ( NMAXSTRING);
|
||||
|
||||
std::sort (A.begin() , A.end() );
|
||||
for ( size_t i =0 ; i< (NMAXSTRING >>1); ++i)
|
||||
std::swap ( A[i], A[NMAXSTRING - 1 - i]);
|
||||
|
||||
size_t step = NMAXSTRING /n_last +1 ;
|
||||
size_t pos = 0 ;
|
||||
|
||||
for ( size_t i =0 ; i < B.size() ; ++i, pos += step)
|
||||
{ C.push_back ( B[i]);
|
||||
for ( size_t k = 0 ; k < step ; ++k )
|
||||
C.push_back ( A[pos + k] );
|
||||
};
|
||||
while ( pos < A.size() )
|
||||
C.push_back ( A[pos++]);
|
||||
A = C ;
|
||||
|
||||
Test<std::string, std::less<std::string>>(A);
|
||||
aux.clear ();
|
||||
aux.reserve (0);
|
||||
Test (A);
|
||||
};
|
||||
|
||||
|
||||
template<class IA, class compare>
|
||||
int Test (std::vector<IA> &B, compare comp)
|
||||
void Test (std::vector <std::string> &B)
|
||||
{ //---------------------------- begin --------------------------------
|
||||
std::less <std::string> comp;
|
||||
double duration;
|
||||
time_point start, finish;
|
||||
std::vector<IA> A (B);
|
||||
std::vector<double> V;
|
||||
std::vector <std::string> A (B);
|
||||
std::vector <double> V;
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
A = B;
|
||||
@@ -296,11 +306,11 @@ int Test (std::vector<IA> &B, compare comp)
|
||||
//-----------------------------------------------------------------------
|
||||
// printing the vector
|
||||
//-----------------------------------------------------------------------
|
||||
std::cout<<std::setprecision(2)<<std::fixed;
|
||||
for ( uint32_t i =0 ; i < V.size() ; ++i)
|
||||
{ std::cout<<std::right<<std::setw(5)<<V[i]<<" |";
|
||||
std::cout << std::setprecision (2) << std::fixed;
|
||||
for (uint32_t i = 0; i < V.size (); ++i)
|
||||
{ std::cout << std::right << std::setw (5) << V [i] << " |";
|
||||
};
|
||||
std::cout<<std::endl;
|
||||
return 0;
|
||||
std::cout << std::endl;
|
||||
|
||||
};
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@ namespace bsc = boost::sort::common;
|
||||
|
||||
void print_banner();
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
int main(int argc, char *argv [])
|
||||
{ //---------------------------- begin--------------------------------------
|
||||
std::string name;
|
||||
size_t number;
|
||||
@@ -38,13 +38,13 @@ int main(int argc, char *argv[])
|
||||
return 0;
|
||||
};
|
||||
name = argv[1];
|
||||
number = atoi(argv[2]);
|
||||
number = atoi (argv[ 2]);
|
||||
if (number == 0) {
|
||||
cout << "error, the number can't be zero\n";
|
||||
return 0;
|
||||
};
|
||||
|
||||
if (bsc::generate_file(name, number) != 0)
|
||||
if (bsc::generate_file (name, number) != 0)
|
||||
std::cout << "Error in the file creation\n";
|
||||
return 0;
|
||||
};
|
||||
|
||||
@@ -7,9 +7,9 @@ echo "=================================================================="
|
||||
echo "."
|
||||
echo "C O M P I L I N G . . . . . . . . . . ."
|
||||
echo "."
|
||||
clang++ ./file_generator.cpp -std=c++11 -march=native -w -fexceptions -O3 -I../../include -s -o file_generator
|
||||
clang++ ./file_generator.cpp -std=c++11 -march=native -w -fno-exceptions -fno-operator-names -O3 -I../../include -s -o file_generator
|
||||
|
||||
clang++ ./benchmark_numbers.cpp -std=c++11 -march=native -w -fexceptions -O3 -I../../include -pthread -s -lpthread -o benchmark_numbers
|
||||
clang++ ./benchmark_numbers.cpp -std=c++11 -march=native -w -fno-exceptions -fno-operator-names -O3 -I../../include -pthread -s -lpthread -o benchmark_numbers
|
||||
|
||||
echo "R U N N I N G . . . . . . . . . . ."
|
||||
echo "( The time needed is around 10 minutes depending of your machine )"
|
||||
|
||||
@@ -7,9 +7,9 @@ echo "=================================================================="
|
||||
echo "."
|
||||
echo "C O M P I L I N G . . . . . . . . . . ."
|
||||
|
||||
clang++ ./file_generator.cpp -std=c++11 -march=native -w -fexceptions -O3 -I../../include -s -o file_generator
|
||||
clang++ ./file_generator.cpp -std=c++11 -march=native -w -fno-exceptions -fno-operator-names -O3 -I../../include -s -o file_generator
|
||||
|
||||
clang++ ./benchmark_objects.cpp -std=c++11 -march=native -w -fexceptions -O3 -I../../include -pthread -s -lpthread -o benchmark_objects
|
||||
clang++ ./benchmark_objects.cpp -std=c++11 -march=native -w -fno-exceptions -fno-operator-names -O3 -I../../include -pthread -s -lpthread -o benchmark_objects
|
||||
echo "."
|
||||
echo "R U N N I N G . . . . . . . . . . ."
|
||||
echo "( The time needed is around 60 minutes depending of your machine )"
|
||||
|
||||
@@ -7,9 +7,9 @@ echo "=================================================================="
|
||||
echo "."
|
||||
echo "C O M P I L I N G . . . . . . . . . . ."
|
||||
echo "."
|
||||
g++ ./file_generator.cpp -std=c++11 -march=native -w -fexceptions -O3 -I../../include -s -o file_generator
|
||||
g++ ./file_generator.cpp -std=c++11 -march=native -w -fno-exceptions -fno-operator-names -O3 -I../../include -s -o file_generator
|
||||
|
||||
g++ ./benchmark_strings.cpp -std=c++11 -march=native -w -fexceptions -O3 -I../../include -pthread -s -lpthread -o benchmark_strings
|
||||
g++ ./benchmark_strings.cpp -std=c++11 -march=native -w -fno-exceptions -fno-operator-names -O3 -I../../include -pthread -s -lpthread -o benchmark_strings
|
||||
|
||||
echo "R U N N I N G . . . . . . . . . . ."
|
||||
echo "( The time needed is around 10 minutes depending of your machine )"
|
||||
|
||||
@@ -7,9 +7,9 @@ echo "=================================================================="
|
||||
echo "."
|
||||
echo "C O M P I L I N G . . . . . . . . . . ."
|
||||
echo "."
|
||||
g++ ./file_generator.cpp -std=c++11 -march=native -w -fexceptions -O3 -I../../include -s -o file_generator
|
||||
g++ ./file_generator.cpp -std=c++11 -march=native -w -fno-exceptions -fno-operator-names -O3 -I../../include -s -o file_generator
|
||||
|
||||
g++ ./benchmark_numbers.cpp -std=c++11 -march=native -w -fexceptions -O3 -I../../include -pthread -s -lpthread -o benchmark_numbers
|
||||
g++ ./benchmark_numbers.cpp -std=c++11 -march=native -w -fno-exceptions -fno-operator-names -O3 -I../../include -pthread -s -lpthread -o benchmark_numbers
|
||||
|
||||
echo "R U N N I N G . . . . . . . . . . ."
|
||||
echo "( The time needed is around 10 minutes depending of your machine )"
|
||||
|
||||
@@ -7,9 +7,9 @@ echo "=================================================================="
|
||||
echo "."
|
||||
echo "C O M P I L I N G . . . . . . . . . . ."
|
||||
|
||||
g++ ./file_generator.cpp -std=c++11 -march=native -w -fexceptions -O3 -I../../include -s -o file_generator
|
||||
g++ ./file_generator.cpp -std=c++11 -march=native -w -fno-exceptions -fno-operator-names -O3 -I../../include -s -o file_generator
|
||||
|
||||
g++ ./benchmark_objects.cpp -std=c++11 -march=native -w -fexceptions -O3 -I../../include -pthread -s -lpthread -o benchmark_objects
|
||||
g++ ./benchmark_objects.cpp -std=c++11 -march=native -w -fno-exceptions -fno-operator-names -O3 -I../../include -pthread -s -lpthread -o benchmark_objects
|
||||
echo "."
|
||||
echo "R U N N I N G . . . . . . . . . . ."
|
||||
echo "( The time needed is around 60 minutes depending of your machine )"
|
||||
|
||||
@@ -7,9 +7,9 @@ echo "=================================================================="
|
||||
echo "."
|
||||
echo "C O M P I L I N G . . . . . . . . . . ."
|
||||
echo "."
|
||||
g++ ./file_generator.cpp -std=c++11 -march=native -w -fexceptions -O3 -I../../include -s -o file_generator
|
||||
g++ ./file_generator.cpp -std=c++11 -march=native -w -fno-exceptions -fno-operator-names -O3 -I../../include -s -o file_generator
|
||||
|
||||
g++ ./benchmark_strings.cpp -std=c++11 -march=native -w -fexceptions -O3 -I../../include -pthread -s -lpthread -o benchmark_strings
|
||||
g++ ./benchmark_strings.cpp -std=c++11 -march=native -w -fno-exceptions -fno-operator-names -O3 -I../../include -pthread -s -lpthread -o benchmark_strings
|
||||
|
||||
echo "R U N N I N G . . . . . . . . . . ."
|
||||
echo "( The time needed is around 10 minutes depending of your machine )"
|
||||
|
||||
@@ -48,14 +48,13 @@ using bsort::pdqsort;
|
||||
|
||||
void Generator_random (void);
|
||||
void Generator_sorted (void);
|
||||
void Generator_sorted_end (size_t n_last);
|
||||
void Generator_sorted_middle (size_t n_last);
|
||||
void Generator_sorted_end (uint64_t n_last);
|
||||
void Generator_sorted_middle (uint64_t n_middle);
|
||||
void Generator_reverse_sorted (void);
|
||||
void Generator_reverse_sorted_end (size_t n_last);
|
||||
void Generator_reverse_sorted_middle (size_t n_last);
|
||||
void Generator_reverse_sorted_end (uint64_t n_last);
|
||||
void Generator_reverse_sorted_middle (uint64_t n_middle);
|
||||
|
||||
template<class IA, class compare>
|
||||
int Test (std::vector<IA> &B, compare comp = compare ());
|
||||
void Test (const std::vector <uint64_t> &B);
|
||||
|
||||
int main (int argc, char *argv[])
|
||||
{
|
||||
@@ -129,34 +128,28 @@ int main (int argc, char *argv[])
|
||||
cout<<endl<<endl ;
|
||||
return 0;
|
||||
}
|
||||
void
|
||||
Generator_random (void)
|
||||
void Generator_random (void)
|
||||
{
|
||||
vector<uint64_t> A;
|
||||
vector <uint64_t> A;
|
||||
A.reserve (NELEM);
|
||||
A.clear ();
|
||||
if (fill_vector_uint64 ("input.bin", A, NELEM) != 0)
|
||||
{
|
||||
std::cout << "Error in the input file\n";
|
||||
return;
|
||||
std::exit (EXIT_FAILURE);
|
||||
};
|
||||
Test<uint64_t, std::less<uint64_t>> (A);
|
||||
}
|
||||
;
|
||||
void
|
||||
Generator_sorted (void)
|
||||
Test (A);
|
||||
};
|
||||
void Generator_sorted (void)
|
||||
{
|
||||
vector<uint64_t> A;
|
||||
|
||||
A.reserve (NELEM);
|
||||
A.clear ();
|
||||
for (size_t i = 0; i < NELEM; ++i)
|
||||
for (uint64_t i = 0; i < NELEM; ++i)
|
||||
A.push_back (i);
|
||||
Test<uint64_t, std::less<uint64_t>> (A);
|
||||
|
||||
}
|
||||
|
||||
void Generator_sorted_end (size_t n_last)
|
||||
Test (A);
|
||||
};
|
||||
void Generator_sorted_end (uint64_t n_last)
|
||||
{
|
||||
vector<uint64_t> A;
|
||||
A.reserve (NELEM);
|
||||
@@ -164,112 +157,115 @@ void Generator_sorted_end (size_t n_last)
|
||||
if (fill_vector_uint64 ("input.bin", A, NELEM + n_last) != 0)
|
||||
{
|
||||
std::cout << "Error in the input file\n";
|
||||
return;
|
||||
std::exit (EXIT_FAILURE);
|
||||
};
|
||||
std::sort (A.begin (), A.begin () + NELEM);
|
||||
|
||||
Test<uint64_t, std::less<uint64_t>> (A);
|
||||
|
||||
}
|
||||
;
|
||||
void Generator_sorted_middle (size_t n_last)
|
||||
Test (A);
|
||||
};
|
||||
void Generator_sorted_middle (uint64_t n_middle)
|
||||
{
|
||||
vector<uint64_t> A, B, C;
|
||||
A.reserve (NELEM);
|
||||
A.clear ();
|
||||
if (fill_vector_uint64 ("input.bin", A, NELEM + n_last) != 0)
|
||||
assert (n_middle > 1 && NELEM >= (n_middle -1));
|
||||
vector <uint64_t> A, aux;
|
||||
A.reserve (NELEM + n_middle);
|
||||
aux.reserve (n_middle);
|
||||
|
||||
if (fill_vector_uint64 ("input.bin", A, NELEM + n_middle) != 0)
|
||||
{
|
||||
std::cout << "Error in the input file\n";
|
||||
return;
|
||||
std::exit (EXIT_FAILURE);
|
||||
};
|
||||
for (size_t i = NELEM; i < A.size (); ++i)
|
||||
B.push_back (std::move (A[i]));
|
||||
A.resize ( NELEM);
|
||||
for (size_t i = 0; i < (NELEM >> 1); ++i)
|
||||
std::swap (A[i], A[NELEM - 1 - i]);
|
||||
for (uint64_t i = 0; i < n_middle; ++i) aux.push_back (A [i]);
|
||||
|
||||
std::sort (A.begin (), A.end ());
|
||||
size_t step = NELEM / n_last + 1;
|
||||
size_t pos = 0;
|
||||
std::sort (A.begin () + n_middle, A.end ());
|
||||
//------------------------------------------------------------------------
|
||||
// To insert n_middle elements, must have (n_middle - 1) intervals between
|
||||
// them. The size of the interval is step
|
||||
// The elements after the last element of aux don't need to be moved
|
||||
//-------------------------------------------------------------------------
|
||||
uint64_t step = NELEM / (n_middle - 1);
|
||||
A [0] = aux [0];
|
||||
uint64_t pos_read = n_middle, pos_write = 1;
|
||||
|
||||
for (size_t i = 0; i < B.size (); ++i, pos += step)
|
||||
for (uint64_t i = 1; i < n_middle; ++i)
|
||||
{
|
||||
C.push_back (B[i]);
|
||||
for (size_t k = 0; k < step; ++k)
|
||||
C.push_back (A[pos + k]);
|
||||
for (uint64_t k = 0 ; k < step; ++k)
|
||||
A [pos_write ++] = A [pos_read ++];
|
||||
A [pos_write ++] = aux [i];
|
||||
};
|
||||
while (pos < A.size ())
|
||||
C.push_back (A[pos++]);
|
||||
A = C;
|
||||
Test<uint64_t, std::less<uint64_t>> (A);
|
||||
}
|
||||
;
|
||||
aux.clear ();
|
||||
aux.reserve (0);
|
||||
Test (A);
|
||||
};
|
||||
void Generator_reverse_sorted (void)
|
||||
{
|
||||
vector<uint64_t> A;
|
||||
|
||||
A.reserve (NELEM);
|
||||
A.clear ();
|
||||
for (size_t i = NELEM; i > 0; --i)
|
||||
for (uint64_t i = NELEM; i > 0; --i)
|
||||
A.push_back (i);
|
||||
Test<uint64_t, std::less<uint64_t>> (A);
|
||||
}
|
||||
void Generator_reverse_sorted_end (size_t n_last)
|
||||
Test (A);
|
||||
};
|
||||
void Generator_reverse_sorted_end (uint64_t n_last)
|
||||
{
|
||||
vector<uint64_t> A;
|
||||
vector <uint64_t> A;
|
||||
A.reserve (NELEM);
|
||||
A.clear ();
|
||||
if (fill_vector_uint64 ("input.bin", A, NELEM + n_last) != 0)
|
||||
{
|
||||
std::cout << "Error in the input file\n";
|
||||
return;
|
||||
std::exit (EXIT_FAILURE);
|
||||
};
|
||||
std::sort (A.begin (), A.begin () + NELEM);
|
||||
for (size_t i = 0; i < (NELEM >> 1); ++i)
|
||||
std::swap (A[i], A[NELEM - 1 - i]);
|
||||
for (uint64_t i = 0; i < (NELEM >> 1); ++i)
|
||||
std::swap (A [i], A [NELEM - 1 - i]);
|
||||
|
||||
Test<uint64_t, std::less<uint64_t>> (A);
|
||||
Test (A);
|
||||
}
|
||||
void Generator_reverse_sorted_middle (size_t n_last)
|
||||
void Generator_reverse_sorted_middle (uint64_t n_middle)
|
||||
{
|
||||
vector<uint64_t> A, B, C;
|
||||
A.reserve (NELEM);
|
||||
A.clear ();
|
||||
if (fill_vector_uint64 ("input.bin", A, NELEM + n_last) != 0)
|
||||
assert (n_middle > 1 && NELEM >= (n_middle -1));
|
||||
vector <uint64_t> A, aux;
|
||||
A.reserve (NELEM + n_middle);
|
||||
aux.reserve (n_middle);
|
||||
|
||||
if (fill_vector_uint64 ("input.bin", A, NELEM + n_middle) != 0)
|
||||
{
|
||||
std::cout << "Error in the input file\n";
|
||||
return;
|
||||
std::exit (EXIT_FAILURE);
|
||||
};
|
||||
for (size_t i = NELEM; i < A.size (); ++i)
|
||||
B.push_back (std::move (A[i]));
|
||||
A.resize ( NELEM);
|
||||
for (size_t i = 0; i < (NELEM >> 1); ++i)
|
||||
std::swap (A[i], A[NELEM - 1 - i]);
|
||||
for (uint64_t i = 0; i < n_middle; ++i) aux.push_back (A [i]);
|
||||
|
||||
std::sort (A.begin (), A.end ());
|
||||
size_t step = NELEM / n_last + 1;
|
||||
size_t pos = 0;
|
||||
std::sort (A.begin () + n_middle, A.end ());
|
||||
uint64_t pos1 = n_middle, pos2 = A.size () - 1;
|
||||
for (uint64_t i = 0; i < (NELEM >> 1); ++i)
|
||||
std::swap (A [pos1 ++], A [pos2 --]);
|
||||
//------------------------------------------------------------------------
|
||||
// To insert n_middle elements, must have (n_middle - 1) intervals between
|
||||
// them. The size of the interval is step
|
||||
// The elements after the last element of aux don't need to be moved
|
||||
//-------------------------------------------------------------------------
|
||||
uint64_t step = NELEM / (n_middle - 1);
|
||||
A [0] = aux [0];
|
||||
uint64_t pos_read = n_middle, pos_write = 1;
|
||||
|
||||
for (size_t i = 0; i < B.size (); ++i, pos += step)
|
||||
for (uint64_t i = 1; i < n_middle; ++i)
|
||||
{
|
||||
C.push_back (B[i]);
|
||||
for (size_t k = 0; k < step; ++k)
|
||||
C.push_back (A[pos + k]);
|
||||
for (uint64_t k = 0 ; k < step; ++k)
|
||||
A [pos_write ++] = A [pos_read ++];
|
||||
A [pos_write ++] = aux [i];
|
||||
};
|
||||
while (pos < A.size ())
|
||||
C.push_back (A[pos++]);
|
||||
A = C;
|
||||
Test<uint64_t, std::less<uint64_t>> (A);
|
||||
aux.clear ();
|
||||
aux.reserve (0);
|
||||
Test (A);
|
||||
};
|
||||
|
||||
|
||||
template<class IA, class compare>
|
||||
int Test (std::vector<IA> &B, compare comp)
|
||||
{ //---------------------------- begin --------------------------------
|
||||
void Test (const std::vector <uint64_t> &B)
|
||||
{
|
||||
//---------------------------- begin --------------------------------
|
||||
std::less <uint64_t> comp ;
|
||||
double duration;
|
||||
time_point start, finish;
|
||||
std::vector<IA> A (B);
|
||||
std::vector<double> V;
|
||||
std::vector <uint64_t> A (B);
|
||||
std::vector <double> V;
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
A = B;
|
||||
@@ -307,7 +303,6 @@ int Test (std::vector<IA> &B, compare comp)
|
||||
duration = subtract_time (finish, start);
|
||||
V.push_back (duration);
|
||||
|
||||
|
||||
A = B;
|
||||
start = now ();
|
||||
spreadsort (A.begin (), A.end ());
|
||||
@@ -318,11 +313,10 @@ int Test (std::vector<IA> &B, compare comp)
|
||||
//-----------------------------------------------------------------------
|
||||
// printing the vector
|
||||
//-----------------------------------------------------------------------
|
||||
std::cout<<std::setprecision(2)<<std::fixed;
|
||||
for ( uint32_t i =0 ; i < V.size() ; ++i)
|
||||
{ std::cout<<std::right<<std::setw(5)<<V[i]<<" |";
|
||||
std::cout<<std::setprecision (2) <<std::fixed;
|
||||
for ( uint32_t i =0 ; i < V.size () ; ++i)
|
||||
{
|
||||
std::cout<<std::right<<std::setw (5)<<V [i]<<" |";
|
||||
};
|
||||
std::cout<<std::endl;
|
||||
return 0;
|
||||
};
|
||||
|
||||
|
||||
@@ -26,13 +26,8 @@
|
||||
#include <boost/sort/common/time_measure.hpp>
|
||||
#include <boost/sort/common/file_vector.hpp>
|
||||
#include "boost/sort/common/int_array.hpp"
|
||||
|
||||
#include <boost/sort/sort.hpp>
|
||||
|
||||
|
||||
#define NELEM 100000000
|
||||
#define NMAXSTRING 10000000
|
||||
|
||||
using namespace std;
|
||||
namespace bsort = boost::sort;
|
||||
namespace bsc = bsort::common;
|
||||
@@ -54,49 +49,55 @@ using bsort::pdqsort;
|
||||
|
||||
|
||||
template <class IA>
|
||||
void Generator_random(uint64_t N);
|
||||
void Generator_random (uint64_t N);
|
||||
|
||||
template <class IA>
|
||||
void Generator_sorted(uint64_t N);
|
||||
void Generator_sorted (uint64_t N);
|
||||
template <class IA>
|
||||
void Generator_sorted_end(uint64_t N, size_t n_last );
|
||||
void Generator_sorted_end (uint64_t N, size_t n_last );
|
||||
|
||||
template <class IA>
|
||||
void Generator_sorted_middle(uint64_t N, size_t n_last );
|
||||
void Generator_sorted_middle (uint64_t N, size_t n_middle );
|
||||
|
||||
template <class IA>
|
||||
void Generator_reverse_sorted(uint64_t N);
|
||||
void Generator_reverse_sorted (uint64_t N);
|
||||
|
||||
template <class IA>
|
||||
void Generator_reverse_sorted_end(uint64_t N, size_t n_last );
|
||||
void Generator_reverse_sorted_end (uint64_t N, size_t n_last );
|
||||
|
||||
template <class IA>
|
||||
void Generator_reverse_sorted_middle(uint64_t N, size_t n_last );
|
||||
void Generator_reverse_sorted_middle (uint64_t N, size_t n_midlle );
|
||||
|
||||
template < class IA >
|
||||
struct H_rightshift {
|
||||
inline uint64_t operator()(const IA& A1, unsigned offset) {
|
||||
return A1.counter() >> offset;
|
||||
}
|
||||
template <class IA>
|
||||
struct H_rightshift
|
||||
{
|
||||
inline uint64_t operator () (const IA& A1, unsigned offset)
|
||||
{
|
||||
return A1.counter () >> offset;
|
||||
};
|
||||
};
|
||||
|
||||
template < class IA >
|
||||
struct L_rightshift {
|
||||
inline uint64_t operator()(const IA& A1, unsigned offset) {
|
||||
return A1.M[0] >> offset;
|
||||
}
|
||||
template <class IA>
|
||||
struct L_rightshift
|
||||
{
|
||||
inline uint64_t operator () (const IA& A1, unsigned offset)
|
||||
{
|
||||
return A1.M[0] >> offset;
|
||||
};
|
||||
};
|
||||
|
||||
template <class IA, class rightshift, class compare>
|
||||
int Test(std::vector<IA> &B, rightshift shift, compare comp, std::vector<double> & V );
|
||||
int Test (std::vector< IA> &B, rightshift shift,
|
||||
compare comp, std::vector <double> & V );
|
||||
|
||||
template <class IA>
|
||||
void Test_size ( uint64_t N);
|
||||
void Test_size (uint64_t N);
|
||||
|
||||
void Print_vectors ( std::vector<double> & V1, std::vector<double> & V2);
|
||||
void Print_vectors ( std::vector <double> &V1, std::vector <double> &V2);
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
int main(int argc, char *argv [])
|
||||
{
|
||||
const uint64_t NELEM = 100000000;
|
||||
cout << "\n\n";
|
||||
cout << "************************************************************\n";
|
||||
cout << "** **\n";
|
||||
@@ -130,7 +131,7 @@ int main(int argc, char *argv[])
|
||||
cout << "** **\n";
|
||||
cout << "************************************************************\n";
|
||||
|
||||
Test_size<int_array<1> >(NELEM);
|
||||
Test_size <int_array <1> >(NELEM);
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
// I N T _ A R R A Y < 4 >
|
||||
@@ -140,7 +141,7 @@ int main(int argc, char *argv[])
|
||||
cout << " "<<(NELEM >>2)<<" OBJECTS UINT64_T [4]\n";
|
||||
cout << "** **\n";
|
||||
cout << "************************************************************\n";
|
||||
Test_size<int_array<4> >(NELEM >> 2);
|
||||
Test_size <int_array <4> >(NELEM >> 2);
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
// I N T _ A R R A Y < 8 >
|
||||
@@ -150,7 +151,7 @@ int main(int argc, char *argv[])
|
||||
cout << " "<<(NELEM >>3)<<" OBJECTS UINT64_T [8]\n";
|
||||
cout << "** **\n";
|
||||
cout << "************************************************************\n";
|
||||
Test_size<int_array<8> >(NELEM >> 3);
|
||||
Test_size <int_array <8> >(NELEM >> 3);
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
// I N T _ A R R A Y < 1 6 >
|
||||
@@ -160,7 +161,7 @@ int main(int argc, char *argv[])
|
||||
cout << " "<<(NELEM >>4)<<" OBJECTS UINT64_T [16]\n";
|
||||
cout << "** **\n";
|
||||
cout << "************************************************************\n";
|
||||
Test_size<int_array<16> >(NELEM >> 4);
|
||||
Test_size <int_array <16> >(NELEM >> 4);
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
// I N T _ A R R A Y < 6 4 >
|
||||
@@ -170,13 +171,13 @@ int main(int argc, char *argv[])
|
||||
cout << " "<< (NELEM >>6)<<" OBJECTS UINT64_T [64]\n";
|
||||
cout << "** **\n";
|
||||
cout << "************************************************************\n";
|
||||
Test_size<int_array<64> >(NELEM >> 6);
|
||||
Test_size <int_array <64> >(NELEM >> 6);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
template <class IA>
|
||||
void Test_size ( uint64_t N)
|
||||
void Test_size (uint64_t N)
|
||||
{
|
||||
cout<<"\n";
|
||||
cout<<"[ 1 ] std::sort [ 2 ] pdqsort [ 3 ] std::stable_sort \n";
|
||||
@@ -197,317 +198,349 @@ void Test_size ( uint64_t N)
|
||||
" | | | |\n";
|
||||
|
||||
cout<<"random |";
|
||||
Generator_random<IA>(N);
|
||||
Generator_random <IA> (N);
|
||||
|
||||
cout<<empty_line;
|
||||
cout<<"sorted |";
|
||||
Generator_sorted<IA>(N);
|
||||
Generator_sorted <IA> (N);
|
||||
|
||||
cout<<"sorted + 0.1% end |";
|
||||
Generator_sorted_end<IA>(N, N / 1000);
|
||||
Generator_sorted_end <IA> (N, N / 1000);
|
||||
|
||||
cout<<"sorted + 1% end |";
|
||||
Generator_sorted_end<IA>(N, N / 100);
|
||||
Generator_sorted_end <IA> (N, N / 100);
|
||||
|
||||
cout<<"sorted + 10% end |";
|
||||
Generator_sorted_end<IA>(N, N / 10);
|
||||
Generator_sorted_end <IA> (N, N / 10);
|
||||
|
||||
cout<<empty_line;
|
||||
cout<<"sorted + 0.1% mid |";
|
||||
Generator_sorted_middle<IA>(N, N / 1000);
|
||||
Generator_sorted_middle <IA> (N, N / 1000);
|
||||
|
||||
cout<<"sorted + 1% mid |";
|
||||
Generator_sorted_middle<IA>(N, N / 100);
|
||||
Generator_sorted_middle <IA> (N, N / 100);
|
||||
|
||||
cout<<"sorted + 10% mid |";
|
||||
Generator_sorted_middle<IA>(N, N / 10);
|
||||
Generator_sorted_middle <IA> (N, N / 10);
|
||||
|
||||
cout<<empty_line;
|
||||
cout<<"reverse sorted |";
|
||||
Generator_reverse_sorted<IA>(N);
|
||||
Generator_reverse_sorted <IA> (N);
|
||||
|
||||
cout<<"rv sorted + 0.1% end|";
|
||||
Generator_reverse_sorted_end<IA>(N, N / 1000);
|
||||
Generator_reverse_sorted_end <IA> (N, N / 1000);
|
||||
|
||||
cout<<"rv sorted + 1% end|";
|
||||
Generator_reverse_sorted_end<IA>(N, N / 100);
|
||||
Generator_reverse_sorted_end <IA> (N, N / 100);
|
||||
|
||||
cout<<"rv sorted + 10% end|";
|
||||
Generator_reverse_sorted_end<IA>(N, N / 10);
|
||||
Generator_reverse_sorted_end <IA> (N, N / 10);
|
||||
|
||||
cout<<empty_line;
|
||||
cout<<"rv sorted + 0.1% mid|";
|
||||
Generator_reverse_sorted_middle<IA>(N, N / 1000);
|
||||
Generator_reverse_sorted_middle <IA> (N, N / 1000);
|
||||
|
||||
cout<<"rv sorted + 1% mid|";
|
||||
Generator_reverse_sorted_middle<IA>(N, N / 100);
|
||||
Generator_reverse_sorted_middle <IA> (N, N / 100);
|
||||
|
||||
cout<<"rv sorted + 10% mid|";
|
||||
Generator_reverse_sorted_middle<IA>(N, N / 10);
|
||||
cout<< "--------------------+-----------+-----------+-----------+";
|
||||
Generator_reverse_sorted_middle <IA> (N, N / 10);
|
||||
cout << "--------------------+-----------+-----------+-----------+";
|
||||
cout << "-----------+-----------+-----------+\n";
|
||||
cout<<endl<<endl<<endl;
|
||||
}
|
||||
void Print_vectors ( std::vector<double> & V1, std::vector<double> & V2)
|
||||
{
|
||||
assert ( V1.size() == V2.size());
|
||||
std::cout<<std::setprecision(2)<<std::fixed;
|
||||
for ( uint32_t i =0 ; i < V1.size() ; ++i)
|
||||
{ std::cout<<std::right<<std::setw(5)<<V1[i]<<" ";
|
||||
std::cout<<std::right<<std::setw(5)<<V2[i]<<"|";
|
||||
assert ( V1.size () == V2.size ());
|
||||
std::cout << std::setprecision (2) << std::fixed;
|
||||
|
||||
for ( uint32_t i =0 ; i < V1.size () ; ++i)
|
||||
{
|
||||
std::cout << std::right << std::setw (5) << V1 [i] << " ";
|
||||
std::cout << std::right << std::setw (5) << V2 [i] <<"|";
|
||||
};
|
||||
std::cout<<std::endl;
|
||||
}
|
||||
|
||||
template <class IA>
|
||||
void Generator_random(uint64_t N)
|
||||
void Generator_random (uint64_t N)
|
||||
{
|
||||
bsc::uint64_file_generator gen("input.bin");
|
||||
vector<IA> A;
|
||||
A.reserve(N);
|
||||
std::vector<double> V1, V2 ;
|
||||
bsc::uint64_file_generator gen ("input.bin");
|
||||
vector <IA> A;
|
||||
A.reserve (N);
|
||||
std::vector <double> V1, V2 ;
|
||||
|
||||
gen.reset();
|
||||
A.clear();
|
||||
for (uint32_t i = 0; i < N; i++) A.emplace_back(IA::generate(gen));
|
||||
gen.reset ();
|
||||
A.clear ();
|
||||
for (uint32_t i = 0; i < N; i++) A.emplace_back (IA::generate(gen));
|
||||
|
||||
Test(A, H_rightshift<IA>(), H_comp<IA>(), V1);
|
||||
|
||||
Test(A, L_rightshift<IA>(), L_comp<IA>(), V2);
|
||||
Print_vectors ( V1, V2 ) ;
|
||||
Test(A, H_rightshift <IA> (), H_comp <IA> (), V1);
|
||||
Test(A, L_rightshift <IA> (), L_comp <IA> (), V2);
|
||||
Print_vectors (V1, V2) ;
|
||||
};
|
||||
|
||||
template <class IA>
|
||||
void Generator_sorted(uint64_t N)
|
||||
{
|
||||
bsc::uint64_file_generator gen("input.bin");
|
||||
vector<IA> A;
|
||||
A.reserve(N);
|
||||
std::vector<double> V1, V2 ;
|
||||
bsc::uint64_file_generator gen ("input.bin");
|
||||
vector <IA> A;
|
||||
A.reserve (N);
|
||||
std::vector <double> V1, V2 ;
|
||||
|
||||
gen.reset();
|
||||
A.clear();
|
||||
for (uint32_t i = 0; i < N; i++) A.emplace_back(IA::generate(gen));
|
||||
gen.reset ();
|
||||
A.clear ();
|
||||
for (uint32_t i = 0; i < N; i++) A.emplace_back (IA::generate (gen));
|
||||
|
||||
std::sort( A.begin() , A.end(),H_comp<IA>() );
|
||||
Test(A, H_rightshift<IA>(), H_comp<IA>(), V1);
|
||||
std::sort (A.begin (), A.end (), H_comp <IA> ());
|
||||
Test (A, H_rightshift <IA> (), H_comp <IA> (), V1);
|
||||
|
||||
std::sort( A.begin() , A.end(),L_comp<IA>() );
|
||||
Test(A, L_rightshift<IA>(), L_comp<IA>(), V2);
|
||||
Print_vectors ( V1, V2 ) ;
|
||||
std::sort (A.begin (), A.end (), L_comp <IA> ());
|
||||
Test (A, L_rightshift <IA> (), L_comp <IA> (), V2);
|
||||
Print_vectors (V1, V2) ;
|
||||
};
|
||||
|
||||
template <class IA>
|
||||
void Generator_sorted_end(uint64_t N, size_t n_last )
|
||||
void Generator_sorted_end (uint64_t N, size_t n_last )
|
||||
{
|
||||
bsc::uint64_file_generator gen("input.bin");
|
||||
vector<IA> A;
|
||||
A.reserve(N);
|
||||
std::vector<double> V1, V2 ;
|
||||
bsc::uint64_file_generator gen ("input.bin");
|
||||
vector <IA> A;
|
||||
A.reserve (N);
|
||||
std::vector <double> V1, V2 ;
|
||||
|
||||
gen.reset();
|
||||
A.clear();
|
||||
gen.reset ();
|
||||
A.clear ();
|
||||
for (uint32_t i = 0; i < (N + n_last); i++)
|
||||
A.emplace_back(IA::generate(gen));
|
||||
std::sort ( A.begin() , A.begin() + N ,H_comp<IA>());
|
||||
A.emplace_back (IA::generate (gen));
|
||||
|
||||
std::sort (A.begin (), A.begin () + N, H_comp <IA> ());
|
||||
|
||||
Test(A, H_rightshift<IA>(), H_comp<IA>(),V1);
|
||||
std::sort ( A.begin() , A.begin() + N ,L_comp<IA>());
|
||||
Test (A, H_rightshift <IA> (), H_comp <IA> (), V1);
|
||||
std::sort (A.begin (), A.begin () + N, L_comp <IA> ());
|
||||
|
||||
Test(A, L_rightshift<IA>(), L_comp<IA>(), V2);
|
||||
Print_vectors ( V1, V2 ) ;
|
||||
Test (A, L_rightshift <IA> (), L_comp <IA> (), V2);
|
||||
Print_vectors (V1, V2) ;
|
||||
};
|
||||
template <class IA>
|
||||
void Generator_sorted_middle(uint64_t N, size_t n_last )
|
||||
void Generator_sorted_middle (uint64_t N, size_t n_middle )
|
||||
{
|
||||
bsc::uint64_file_generator gen("input.bin");
|
||||
std::vector<double> V1, V2 ;
|
||||
vector<IA> A;
|
||||
A.reserve(N + n_last);
|
||||
assert (n_middle > 1 && N >= (n_middle -1));
|
||||
bsc::uint64_file_generator gen ("input.bin");
|
||||
|
||||
std::vector <double> V1, V2; // vector with the times used
|
||||
vector <IA> A, aux;
|
||||
A.reserve (N + n_middle);
|
||||
aux.reserve (n_middle);
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
// H _ C O M P
|
||||
//-----------------------------------------------------------------------
|
||||
for (uint32_t i = 0; i < (N + n_middle); i++)
|
||||
A.emplace_back (IA::generate (gen));
|
||||
|
||||
for (size_t i = 0; i < n_middle; ++i)
|
||||
aux.push_back (std::move (A [i]));
|
||||
|
||||
std::sort (A.begin () + n_middle, A.end (), H_comp <IA> ());
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
// To insert n_middle elements, must have (n_middle - 1) intervals between
|
||||
// them. The size of the interval is step
|
||||
// The elements after the last element of aux don't need to be moved
|
||||
//-------------------------------------------------------------------------
|
||||
size_t step = N / (n_middle - 1);
|
||||
A [0] = std::move (aux [0]);
|
||||
size_t pos_read = n_middle, pos_write = 1;
|
||||
|
||||
{ A.clear() ;
|
||||
gen.reset();
|
||||
vector<IA> B, C;
|
||||
C.reserve(N + n_last);
|
||||
B.reserve ( n_last);
|
||||
for (uint32_t i = 0; i < (N + n_last); i++)
|
||||
C.emplace_back(IA::generate(gen));
|
||||
|
||||
for ( size_t i = N ; i < C.size() ; ++i)
|
||||
B.push_back ( std::move ( C[i]));
|
||||
|
||||
C.resize ( N);
|
||||
|
||||
std::sort ( C.begin() , C.end() ,H_comp<IA>());
|
||||
size_t step = N /n_last ;
|
||||
size_t pos = 0 ;
|
||||
|
||||
for ( size_t i =0 ; i < B.size() ; ++i)
|
||||
{ A.push_back ( B[i]);
|
||||
for ( size_t k = 0 ; k < step ; ++k )
|
||||
A.push_back ( C[pos++] );
|
||||
};
|
||||
while ( pos < C.size() )
|
||||
A.push_back ( C[pos++]);
|
||||
for (size_t i = 1; i < n_middle; ++i)
|
||||
{
|
||||
for (size_t k = 0 ; k < step; ++k)
|
||||
A [pos_write ++] = std::move (A [pos_read ++]);
|
||||
A [pos_write ++] = std::move (aux [i]);
|
||||
};
|
||||
|
||||
Test(A, H_rightshift<IA>(), H_comp<IA>(), V1);
|
||||
Test (A, H_rightshift <IA> (), H_comp <IA> (), V1);
|
||||
|
||||
{ A.clear() ;
|
||||
gen.reset();
|
||||
vector<IA> B,C;
|
||||
C.reserve(N + n_last);
|
||||
B.reserve ( n_last);
|
||||
for (uint32_t i = 0; i < (N + n_last); i++)
|
||||
C.emplace_back(IA::generate(gen));
|
||||
//----------------------------------------------------------------------
|
||||
// L _ C O M P
|
||||
//-----------------------------------------------------------------------
|
||||
gen.reset ();
|
||||
A.clear ();
|
||||
A.reserve (N + n_middle);
|
||||
aux.clear ();
|
||||
aux.reserve (n_middle);
|
||||
|
||||
for (uint32_t i = 0; i < (N + n_middle); i++)
|
||||
A.emplace_back (IA::generate (gen));
|
||||
|
||||
for (size_t i = 0; i < n_middle; ++i)
|
||||
aux.push_back (std::move (A [i]));
|
||||
|
||||
std::sort (A.begin () + n_middle, A.end (), L_comp <IA> ());
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
// To insert n_middle elements, must have (n_middle - 1) intervals between
|
||||
// them. The size of the interval is step
|
||||
// The elements after the last element of aux don't need to be moved
|
||||
//-------------------------------------------------------------------------
|
||||
step = N / (n_middle - 1);
|
||||
A [0] = std::move (aux [0]);
|
||||
pos_read = n_middle;
|
||||
pos_write = 1;
|
||||
|
||||
for ( size_t i = N ; i < C.size() ; ++i)
|
||||
B.push_back ( std::move ( C[i]));
|
||||
|
||||
C.resize ( N);
|
||||
|
||||
std::sort ( C.begin() , C.end() ,L_comp<IA>());
|
||||
size_t step = N /n_last ;
|
||||
size_t pos = 0 ;
|
||||
|
||||
for ( size_t i =0 ; i < B.size() ; ++i)
|
||||
{ A.push_back ( B[i]);
|
||||
for ( size_t k = 0 ; k < step ; ++k )
|
||||
A.push_back ( C[pos++] );
|
||||
};
|
||||
while ( pos < C.size() )
|
||||
A.push_back ( C[pos++]);
|
||||
for (size_t i = 1; i < n_middle; ++i)
|
||||
{
|
||||
for (size_t k = 0 ; k < step; ++k)
|
||||
A [pos_write ++] = std::move (A [pos_read ++]);
|
||||
A [pos_write ++] = std::move (aux [i]);
|
||||
};
|
||||
Test(A, L_rightshift<IA>(), L_comp<IA>(), V2);
|
||||
Print_vectors ( V1, V2 ) ;
|
||||
|
||||
Test (A, L_rightshift <IA> (), L_comp <IA> (), V2);
|
||||
Print_vectors (V1, V2) ;
|
||||
};
|
||||
template <class IA>
|
||||
void Generator_reverse_sorted(uint64_t N)
|
||||
void Generator_reverse_sorted (uint64_t N)
|
||||
{
|
||||
bsc::uint64_file_generator gen("input.bin");
|
||||
vector<IA> A;
|
||||
A.reserve(N);
|
||||
std::vector<double> V1, V2 ;
|
||||
bsc::uint64_file_generator gen ("input.bin");
|
||||
vector <IA> A;
|
||||
A.reserve (N);
|
||||
std::vector <double> V1, V2 ;
|
||||
|
||||
gen.reset();
|
||||
A.clear();
|
||||
for (uint32_t i = 0; i < N; i++) A.emplace_back(IA::generate(gen));
|
||||
gen.reset ();
|
||||
A.clear ();
|
||||
for (uint32_t i = 0; i < N; i++) A.emplace_back (IA::generate (gen));
|
||||
|
||||
std::sort( A.begin() , A.end(),H_comp<IA>() );
|
||||
for ( size_t i = 0; i < (A.size() >>1) ; ++i)
|
||||
std::swap ( A[i], A[A.size() - i -1 ]);
|
||||
std::sort (A.begin (), A.end (), H_comp <IA> ());
|
||||
for (size_t i = 0; i < (A.size () >>1); ++i)
|
||||
std::swap (A [i], A [A.size () - i - 1]);
|
||||
|
||||
Test(A, H_rightshift<IA>(), H_comp<IA>(), V1);
|
||||
Test (A, H_rightshift <IA> (), H_comp <IA> (), V1);
|
||||
|
||||
std::sort( A.begin() , A.end(),L_comp<IA>() );
|
||||
for ( size_t i = 0; i < (A.size() >>1) ; ++i)
|
||||
std::swap ( A[i], A[A.size() - i -1 ]);
|
||||
Test(A, L_rightshift<IA>(), L_comp<IA>(), V2);
|
||||
Print_vectors ( V1, V2 ) ;
|
||||
std::sort (A.begin (), A.end (), L_comp <IA> ());
|
||||
for (size_t i = 0; i < (A.size () >> 1); ++i)
|
||||
std::swap (A [i], A [A.size() - i - 1]);
|
||||
|
||||
Test (A, L_rightshift <IA> (), L_comp <IA> (), V2);
|
||||
Print_vectors (V1, V2) ;
|
||||
};
|
||||
template <class IA>
|
||||
void Generator_reverse_sorted_end(uint64_t N, size_t n_last )
|
||||
{
|
||||
bsc::uint64_file_generator gen("input.bin");
|
||||
vector<IA> A;
|
||||
A.reserve(N);
|
||||
std::vector<double> V1, V2 ;
|
||||
|
||||
gen.reset();
|
||||
A.clear();
|
||||
template <class IA>
|
||||
void Generator_reverse_sorted_end (uint64_t N, size_t n_last )
|
||||
{
|
||||
bsc::uint64_file_generator gen ("input.bin");
|
||||
vector <IA> A;
|
||||
A.reserve (N);
|
||||
std::vector <double> V1, V2 ;
|
||||
|
||||
gen.reset ();
|
||||
A.clear ();
|
||||
for (uint32_t i = 0; i < (N + n_last); i++)
|
||||
A.emplace_back(IA::generate(gen));
|
||||
std::sort ( A.begin() , A.begin() + N ,H_comp<IA>());
|
||||
for ( size_t i =0 ; i < (N>>1); ++i)
|
||||
std::swap ( A[i], A[N-1-i]);
|
||||
A.emplace_back (IA::generate (gen));
|
||||
|
||||
std::sort (A.begin (), A.begin () + N , H_comp <IA> ());
|
||||
for (size_t i =0 ; i < (N >> 1); ++i)
|
||||
std::swap (A [i], A [N - 1 - i]);
|
||||
|
||||
Test(A, H_rightshift<IA>(), H_comp<IA>(), V1);
|
||||
std::sort ( A.begin() , A.begin() + N ,L_comp<IA>());
|
||||
for ( size_t i =0 ; i < (N>>1); ++i)
|
||||
std::swap ( A[i], A[N-1-i]);
|
||||
Test (A, H_rightshift <IA> (), H_comp <IA> (), V1);
|
||||
std::sort (A.begin (), A.begin () + N, L_comp <IA> ());
|
||||
for (size_t i = 0; i < (N >> 1); ++i)
|
||||
std::swap (A [i], A [N - 1 - i]);
|
||||
|
||||
Test(A, L_rightshift<IA>(), L_comp<IA>(), V2);
|
||||
Print_vectors ( V1, V2 ) ;
|
||||
Test (A, L_rightshift <IA> (), L_comp <IA> (), V2);
|
||||
Print_vectors (V1, V2) ;
|
||||
};
|
||||
|
||||
template <class IA>
|
||||
void Generator_reverse_sorted_middle(uint64_t N, size_t n_last )
|
||||
void Generator_reverse_sorted_middle (uint64_t N, size_t n_middle )
|
||||
{
|
||||
bsc::uint64_file_generator gen("input.bin");
|
||||
std::vector<double> V1, V2 ;
|
||||
vector<IA> A;
|
||||
A.reserve(N + n_last);
|
||||
assert (n_middle > 1 && N >= (n_middle -1));
|
||||
bsc::uint64_file_generator gen ("input.bin");
|
||||
|
||||
std::vector <double> V1, V2; // vector with the times used
|
||||
vector <IA> A, aux;
|
||||
A.reserve (N + n_middle);
|
||||
aux.reserve (n_middle);
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
// H _ C O M P
|
||||
//-----------------------------------------------------------------------
|
||||
for (uint32_t i = 0; i < (N + n_middle); i++)
|
||||
A.emplace_back (IA::generate (gen));
|
||||
|
||||
for (size_t i = 0; i < n_middle; ++i)
|
||||
aux.push_back (std::move (A [i]));
|
||||
|
||||
std::sort (A.begin () + n_middle, A.end (), H_comp <IA> ());
|
||||
uint64_t pos1 = n_middle, pos2 = A.size () - 1;
|
||||
for (uint64_t i = 0; i < (N >> 1); ++i)
|
||||
std::swap (A [pos1 ++], A [pos2 --]);
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
// To insert n_middle elements, must have (n_middle - 1) intervals between
|
||||
// them. The size of the interval is step
|
||||
// The elements after the last element of aux don't need to be moved
|
||||
//-------------------------------------------------------------------------
|
||||
size_t step = N / (n_middle - 1);
|
||||
A [0] = std::move (aux [0]);
|
||||
size_t pos_read = n_middle, pos_write = 1;
|
||||
|
||||
{ A.clear() ;
|
||||
gen.reset();
|
||||
vector<IA> B,C;
|
||||
C.reserve(N + n_last);
|
||||
B.reserve ( n_last);
|
||||
for (uint32_t i = 0; i < (N + n_last); i++)
|
||||
C.emplace_back(IA::generate(gen));
|
||||
|
||||
for ( size_t i = N ; i < C.size() ; ++i)
|
||||
B.push_back ( std::move ( C[i]));
|
||||
|
||||
C.resize ( N);
|
||||
|
||||
std::sort ( C.begin() , C.end() ,H_comp<IA>());
|
||||
|
||||
for ( size_t i =0 ; i < (N>>1); ++i)
|
||||
std::swap ( C[i], C[N-1-i]);
|
||||
|
||||
size_t step = N /n_last ;
|
||||
size_t pos = 0 ;
|
||||
|
||||
for ( size_t i =0 ; i < B.size() ; ++i)
|
||||
{ A.push_back ( B[i]);
|
||||
for ( size_t k = 0 ; k < step ; ++k )
|
||||
A.push_back ( C[pos++ ] );
|
||||
};
|
||||
while ( pos < C.size() )
|
||||
A.push_back ( C[pos++]);
|
||||
for (size_t i = 1; i < n_middle; ++i)
|
||||
{
|
||||
for (size_t k = 0 ; k < step; ++k)
|
||||
A [pos_write ++] = std::move (A [pos_read ++]);
|
||||
A [pos_write ++] = std::move (aux [i]);
|
||||
};
|
||||
|
||||
Test(A, H_rightshift<IA>(), H_comp<IA>(), V1);
|
||||
Test (A, H_rightshift <IA> (), H_comp <IA> (), V1);
|
||||
|
||||
{ A.clear() ;
|
||||
gen.reset();
|
||||
vector<IA> B,C;
|
||||
C.reserve(N + n_last);
|
||||
B.reserve ( n_last);
|
||||
for (uint32_t i = 0; i < (N + n_last); i++)
|
||||
C.emplace_back(IA::generate(gen));
|
||||
//----------------------------------------------------------------------
|
||||
// L _ C O M P
|
||||
//-----------------------------------------------------------------------
|
||||
gen.reset ();
|
||||
A.clear ();
|
||||
A.reserve (N + n_middle);
|
||||
aux.clear ();
|
||||
aux.reserve (n_middle);
|
||||
|
||||
for (uint32_t i = 0; i < (N + n_middle); i++)
|
||||
A.emplace_back (IA::generate (gen));
|
||||
|
||||
for (size_t i = 0; i < n_middle; ++i)
|
||||
aux.push_back (std::move (A [i]));
|
||||
|
||||
std::sort (A.begin () + n_middle, A.end (), L_comp <IA> ());
|
||||
pos1 = n_middle;
|
||||
pos2 = A.size () - 1;
|
||||
for (uint64_t i = 0; i < (N >> 1); ++i)
|
||||
std::swap (A [pos1 ++], A [pos2 --]);
|
||||
//------------------------------------------------------------------------
|
||||
// To insert n_middle elements, must have (n_middle - 1) intervals between
|
||||
// them. The size of the interval is step
|
||||
// The elements after the last element of aux don't need to be moved
|
||||
//-------------------------------------------------------------------------
|
||||
step = N / (n_middle - 1);
|
||||
A [0] = std::move (aux [0]);
|
||||
pos_read = n_middle;
|
||||
pos_write = 1;
|
||||
|
||||
for ( size_t i = N ; i < C.size() ; ++i)
|
||||
B.push_back ( std::move ( C[i]));
|
||||
|
||||
C.resize ( N);
|
||||
|
||||
std::sort ( C.begin() , C.end() ,L_comp<IA>());
|
||||
|
||||
for ( size_t i =0 ; i < (N>>1); ++i)
|
||||
std::swap ( C[i], C[N-1-i]);
|
||||
size_t step = N /n_last ;
|
||||
size_t pos = 0 ;
|
||||
|
||||
for ( size_t i =0 ; i < B.size() ; ++i)
|
||||
{ A.push_back ( B[i]);
|
||||
for ( size_t k = 0 ; k < step ; ++k )
|
||||
A.push_back ( C[pos++ ] );
|
||||
};
|
||||
while ( pos < C.size() )
|
||||
A.push_back ( C[pos++]);
|
||||
for (size_t i = 1; i < n_middle; ++i)
|
||||
{
|
||||
for (size_t k = 0 ; k < step; ++k)
|
||||
A [pos_write ++] = std::move (A [pos_read ++]);
|
||||
A [pos_write ++] = std::move (aux [i]);
|
||||
};
|
||||
|
||||
Test(A, L_rightshift<IA>(), L_comp<IA>(), V2);
|
||||
Print_vectors ( V1, V2 ) ;
|
||||
Test (A, L_rightshift <IA> (), L_comp <IA> (), V2);
|
||||
Print_vectors (V1, V2) ;
|
||||
};
|
||||
|
||||
template<class IA, class rightshift, class compare>
|
||||
int Test (std::vector<IA> &B, rightshift shift, compare comp,std::vector<double> &V)
|
||||
template <class IA, class rightshift, class compare>
|
||||
int Test (std::vector <IA> &B, rightshift shift,
|
||||
compare comp, std::vector <double> &V)
|
||||
{ //---------------------------- begin --------------------------------
|
||||
double duration;
|
||||
time_point start, finish;
|
||||
std::vector<IA> A (B);
|
||||
V.clear() ;
|
||||
std::vector <IA> A (B);
|
||||
V.clear () ;
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
A = B;
|
||||
|
||||
@@ -47,18 +47,17 @@ using bsort::spreadsort::spreadsort;
|
||||
using bsort::pdqsort;
|
||||
|
||||
void Generator_random (void);
|
||||
void Generator_sorted(void);
|
||||
void Generator_sorted_end(size_t n_last);
|
||||
void Generator_sorted (void);
|
||||
void Generator_sorted_end (size_t n_last);
|
||||
void Generator_sorted_middle (size_t n_last);
|
||||
void Generator_reverse_sorted(void);
|
||||
void Generator_reverse_sorted_end(size_t n_last);
|
||||
void Generator_reverse_sorted_middle(size_t n_last);
|
||||
void Generator_reverse_sorted (void);
|
||||
void Generator_reverse_sorted_end (size_t n_last);
|
||||
void Generator_reverse_sorted_middle (size_t n_last);
|
||||
|
||||
template <class IA, class compare>
|
||||
int Test(std::vector<IA> &B, compare comp = compare());
|
||||
int Test (std::vector <std::string> &B);
|
||||
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
int main (int argc, char *argv [])
|
||||
{
|
||||
cout << "\n\n";
|
||||
cout << "************************************************************\n";
|
||||
@@ -72,232 +71,224 @@ int main(int argc, char *argv[])
|
||||
cout << "************************************************************\n";
|
||||
cout << std::endl;
|
||||
|
||||
cout<<"[ 1 ] std::sort [ 2 ] pdqsort [ 3 ] std::stable_sort \n";
|
||||
cout<<"[ 4 ] spinsort [ 5 ] flat_stable_sort [ 6 ] spreadsort\n\n";
|
||||
cout<<" | | | | | | |\n";
|
||||
cout<<" | [ 1 ]| [ 2 ]| [ 3 ]| [ 4 ]| [ 5 ]| [ 6 ]|\n";
|
||||
cout<<"--------------------+------+------+------+------+------+------+\n";
|
||||
cout << "[ 1 ] std::sort [ 2 ] pdqsort [ 3 ] std::stable_sort\n";
|
||||
cout << "[ 4 ] spinsort [ 5 ] flat_stable_sort [ 6 ] spreadsort\n\n";
|
||||
cout << " | | | | | | |\n";
|
||||
cout << " | [ 1 ]| [ 2 ]| [ 3 ]| [ 4 ]| [ 5 ]| [ 6 ]|\n";
|
||||
cout << "--------------------+------+------+------+------+------+------+\n";
|
||||
std::string empty_line =
|
||||
" | | | | | | |\n";
|
||||
|
||||
cout<<"random |";
|
||||
cout << "random |";
|
||||
Generator_random ();
|
||||
|
||||
cout<<empty_line;
|
||||
cout<<"sorted |";
|
||||
Generator_sorted();
|
||||
cout << empty_line;
|
||||
cout << "sorted |";
|
||||
Generator_sorted ();
|
||||
|
||||
cout<<"sorted + 0.1% end |";
|
||||
Generator_sorted_end(NMAXSTRING / 1000);
|
||||
cout << "sorted + 0.1% end |";
|
||||
Generator_sorted_end (NMAXSTRING / 1000);
|
||||
|
||||
cout<<"sorted + 1% end |";
|
||||
Generator_sorted_end(NMAXSTRING / 100);
|
||||
cout << "sorted + 1% end |";
|
||||
Generator_sorted_end (NMAXSTRING / 100);
|
||||
|
||||
cout<<"sorted + 10% end |";
|
||||
Generator_sorted_end(NMAXSTRING / 10);
|
||||
cout << "sorted + 10% end |";
|
||||
Generator_sorted_end (NMAXSTRING / 10);
|
||||
|
||||
cout<<empty_line;
|
||||
cout<<"sorted + 0.1% mid |";
|
||||
cout <<empty_line;
|
||||
cout << "sorted + 0.1% mid |";
|
||||
Generator_sorted_middle (NMAXSTRING / 1000);
|
||||
|
||||
cout<<"sorted + 1% mid |";
|
||||
cout << "sorted + 1% mid |";
|
||||
Generator_sorted_middle (NMAXSTRING / 100);
|
||||
|
||||
cout<<"sorted + 10% mid |";
|
||||
cout << "sorted + 10% mid |";
|
||||
Generator_sorted_middle (NMAXSTRING / 10 );
|
||||
|
||||
cout<<empty_line;
|
||||
cout<<"reverse sorted |";
|
||||
Generator_reverse_sorted();
|
||||
cout <<empty_line;
|
||||
cout << "reverse sorted |";
|
||||
Generator_reverse_sorted ();
|
||||
|
||||
cout<<"rv sorted + 0.1% end|";
|
||||
Generator_reverse_sorted_end(NMAXSTRING / 1000);
|
||||
cout << "rv sorted + 0.1% end|";
|
||||
Generator_reverse_sorted_end (NMAXSTRING / 1000);
|
||||
|
||||
cout<<"rv sorted + 1% end|";
|
||||
Generator_reverse_sorted_end(NMAXSTRING / 100);
|
||||
cout << "rv sorted + 1% end|";
|
||||
Generator_reverse_sorted_end (NMAXSTRING / 100);
|
||||
|
||||
cout<<"rv sorted + 10% end|";
|
||||
Generator_reverse_sorted_end(NMAXSTRING / 10);
|
||||
cout << "rv sorted + 10% end|";
|
||||
Generator_reverse_sorted_end (NMAXSTRING / 10);
|
||||
|
||||
cout<<empty_line;
|
||||
cout<<"rv sorted + 0.1% mid|";
|
||||
Generator_reverse_sorted_middle(NMAXSTRING / 1000);
|
||||
cout <<empty_line;
|
||||
cout << "rv sorted + 0.1% mid|";
|
||||
Generator_reverse_sorted_middle (NMAXSTRING / 1000);
|
||||
|
||||
cout<<"rv sorted + 1% mid|";
|
||||
Generator_reverse_sorted_middle(NMAXSTRING / 100);
|
||||
cout << "rv sorted + 1% mid|";
|
||||
Generator_reverse_sorted_middle (NMAXSTRING / 100);
|
||||
|
||||
cout<<"rv sorted + 10% mid|";
|
||||
Generator_reverse_sorted_middle(NMAXSTRING / 10);
|
||||
cout << "rv sorted + 10% mid|";
|
||||
Generator_reverse_sorted_middle (NMAXSTRING / 10);
|
||||
|
||||
cout<<"--------------------+------+------+------+------+------+------+\n";
|
||||
cout<<endl<<endl ;
|
||||
cout << "--------------------+------+------+------+------+------+------+\n";
|
||||
cout << endl<<endl ;
|
||||
return 0;
|
||||
}
|
||||
|
||||
void Generator_random(void)
|
||||
{
|
||||
std::vector<std::string> A;
|
||||
A.reserve(NMAXSTRING);
|
||||
A.clear();
|
||||
if (bsc::fill_vector_string("input.bin", A, NMAXSTRING) != 0)
|
||||
std::vector <std::string> A;
|
||||
A.reserve (NMAXSTRING);
|
||||
A.clear ();
|
||||
if (bsc::fill_vector_string ("input.bin", A, NMAXSTRING) != 0)
|
||||
{
|
||||
std::cout << "Error in the input file\n";
|
||||
return;
|
||||
std::exit (EXIT_FAILURE);
|
||||
};
|
||||
Test<std::string, std::less<std::string>>(A);
|
||||
|
||||
Test (A);
|
||||
};
|
||||
void Generator_sorted(void)
|
||||
void Generator_sorted (void)
|
||||
{
|
||||
std::vector<std::string> A;
|
||||
A.reserve(NMAXSTRING);
|
||||
A.clear();
|
||||
if (bsc::fill_vector_string("input.bin", A, NMAXSTRING) != 0)
|
||||
std::vector <std::string> A;
|
||||
A.reserve (NMAXSTRING);
|
||||
A.clear ();
|
||||
if (bsc::fill_vector_string ("input.bin", A, NMAXSTRING) != 0)
|
||||
{
|
||||
std::cout << "Error in the input file\n";
|
||||
return;
|
||||
std::exit (EXIT_FAILURE);
|
||||
};
|
||||
std::sort( A.begin() , A.end() );
|
||||
Test<std::string, std::less<std::string>>(A);
|
||||
std::sort (A.begin (), A.end ());
|
||||
Test (A);
|
||||
};
|
||||
|
||||
void Generator_sorted_end(size_t n_last)
|
||||
void Generator_sorted_end (size_t n_last)
|
||||
{
|
||||
std::vector<std::string> A;
|
||||
A.reserve(NMAXSTRING);
|
||||
A.clear();
|
||||
if (bsc::fill_vector_string("input.bin", A, NMAXSTRING+ n_last) != 0)
|
||||
std::vector <std::string> A;
|
||||
A.reserve (NMAXSTRING);
|
||||
A.clear ();
|
||||
if (bsc::fill_vector_string ("input.bin", A, NMAXSTRING+ n_last) != 0)
|
||||
{
|
||||
std::cout << "Error in the input file\n";
|
||||
return;
|
||||
std::exit (EXIT_FAILURE);
|
||||
};
|
||||
std::sort (A.begin() , A.begin() + NMAXSTRING );
|
||||
Test<std::string, std::less<std::string>>(A);
|
||||
std::sort (A.begin (), A.begin () + NMAXSTRING );
|
||||
Test (A);
|
||||
};
|
||||
void Generator_sorted_middle(size_t n_last)
|
||||
void Generator_sorted_middle (size_t n_middle)
|
||||
{
|
||||
std::vector<std::string> A,B,C;
|
||||
A.reserve(NMAXSTRING);
|
||||
A.clear();
|
||||
if (bsc::fill_vector_string("input.bin", A, NMAXSTRING + n_last) != 0)
|
||||
assert (n_middle > 1 && NMAXSTRING >= (n_middle -1));
|
||||
vector <std::string> A, aux;
|
||||
A.reserve (NMAXSTRING + n_middle);
|
||||
aux.reserve (n_middle);
|
||||
|
||||
if (bsc::fill_vector_string ("input.bin", A, NMAXSTRING + n_middle) != 0)
|
||||
{
|
||||
std::cout << "Error in the input file\n";
|
||||
return;
|
||||
std::exit (EXIT_FAILURE);
|
||||
};
|
||||
for ( size_t i = NMAXSTRING ; i < A.size() ; ++i)
|
||||
B.push_back ( std::move ( A[i]));
|
||||
A.resize ( NMAXSTRING);
|
||||
std::sort (A.begin() , A.end() );
|
||||
size_t step = NMAXSTRING /n_last +1 ;
|
||||
size_t pos = 0 ;
|
||||
for (size_t i = 0; i < n_middle; ++i) aux.push_back (std::move (A [i]));
|
||||
|
||||
for ( size_t i =0 ; i < B.size() ; ++i, pos += step)
|
||||
{ C.push_back ( B[i]);
|
||||
for ( size_t k = 0 ; k < step ; ++k )
|
||||
C.push_back ( A[pos + k] );
|
||||
};
|
||||
while ( pos < A.size() ) C.push_back ( A[pos++]);
|
||||
A = C ;
|
||||
std::sort (A.begin () + n_middle, A.end ());
|
||||
//------------------------------------------------------------------------
|
||||
// To insert n_middle elements, must have (n_middle - 1) intervals between
|
||||
// them. The size of the interval is step
|
||||
// The elements after the last element of aux don't need to be moved
|
||||
//-------------------------------------------------------------------------
|
||||
size_t step = NMAXSTRING / (n_middle - 1);
|
||||
A [0] = std::move (aux [0]);
|
||||
size_t pos_read = n_middle, pos_write = 1;
|
||||
|
||||
Test<std::string, std::less<std::string>>(A);
|
||||
};
|
||||
|
||||
void Generator_reverse_sorted(void)
|
||||
{
|
||||
|
||||
std::vector<std::string> A;
|
||||
A.reserve(NMAXSTRING);
|
||||
for (size_t i = 1; i < n_middle; ++i)
|
||||
{
|
||||
std::vector<std::string> B;
|
||||
B.reserve(NMAXSTRING);
|
||||
if (bsc::fill_vector_string("input.bin", B, NMAXSTRING) != 0)
|
||||
for (size_t k = 0 ; k < step; ++k)
|
||||
A [pos_write ++] = std::move (A [pos_read ++]);
|
||||
A [pos_write ++] = std::move (aux [i]);
|
||||
};
|
||||
aux.clear ();
|
||||
aux.reserve (0);
|
||||
Test (A);
|
||||
};
|
||||
void Generator_reverse_sorted (void)
|
||||
{
|
||||
std::vector <std::string> A;
|
||||
A.reserve (NMAXSTRING);
|
||||
{
|
||||
std::vector <std::string> B;
|
||||
B.reserve (NMAXSTRING);
|
||||
if (bsc::fill_vector_string ("input.bin", B, NMAXSTRING) != 0)
|
||||
{
|
||||
std::cout << "Error in the input file\n";
|
||||
return;
|
||||
std::exit (EXIT_FAILURE);
|
||||
};
|
||||
std::sort(B.begin(), B.end());
|
||||
A.clear();
|
||||
std::sort (B.begin(), B.end());
|
||||
A.clear ();
|
||||
for (size_t i = 0; i < NMAXSTRING; ++i)
|
||||
A.push_back(B[NMAXSTRING - 1 - i]);
|
||||
A.push_back (B [NMAXSTRING - 1 - i]);
|
||||
};
|
||||
Test<std::string, std::less<std::string>>(A);
|
||||
|
||||
/*
|
||||
std::vector<std::string> A;
|
||||
A.reserve(NMAXSTRING);
|
||||
A.clear();
|
||||
if (bsc::fill_vector_string("input.bin", A, NMAXSTRING) != 0)
|
||||
{
|
||||
std::cout << "Error in the input file\n";
|
||||
return;
|
||||
};
|
||||
std::sort( A.begin() , A.end());
|
||||
size_t nmid = (A.size() >>1), nlast = A.size() -1 ;
|
||||
for (size_t i = 0 ; i < nmid ;++i)
|
||||
std::swap ( A[i], A [nlast -i]);
|
||||
|
||||
Test<std::string, std::less<std::string>>(A);
|
||||
*/
|
||||
Test (A);
|
||||
};
|
||||
void Generator_reverse_sorted_end(size_t n_last)
|
||||
void Generator_reverse_sorted_end (size_t n_last)
|
||||
{
|
||||
std::vector<std::string> A;
|
||||
A.reserve(NMAXSTRING);
|
||||
A.clear();
|
||||
if (bsc::fill_vector_string("input.bin", A, NMAXSTRING+ n_last) != 0)
|
||||
std::vector <std::string> A;
|
||||
A.reserve (NMAXSTRING);
|
||||
A.clear ();
|
||||
if (bsc::fill_vector_string ("input.bin", A, NMAXSTRING + n_last) != 0)
|
||||
{
|
||||
std::cout << "Error in the input file\n";
|
||||
return;
|
||||
std::exit (EXIT_FAILURE);
|
||||
};
|
||||
std::sort (A.begin() , A.begin() + NMAXSTRING );
|
||||
for ( size_t i =0 ; i< (NMAXSTRING >>1); ++i)
|
||||
std::swap ( A[i], A[NMAXSTRING - 1 - i]);
|
||||
|
||||
Test<std::string, std::less<std::string>>(A);
|
||||
std::sort (A.begin (), A.begin () + NMAXSTRING);
|
||||
for (size_t i = 0; i < (NMAXSTRING >> 1); ++i)
|
||||
std::swap (A [i], A [NMAXSTRING - 1 - i]);
|
||||
|
||||
Test (A);
|
||||
};
|
||||
void Generator_reverse_sorted_middle(size_t n_last)
|
||||
void Generator_reverse_sorted_middle (size_t n_middle)
|
||||
{
|
||||
std::vector<std::string> A,B,C;
|
||||
A.reserve(NMAXSTRING);
|
||||
A.clear();
|
||||
if (bsc::fill_vector_string("input.bin", A, NMAXSTRING + n_last) != 0)
|
||||
assert (n_middle > 1 && NMAXSTRING >= (n_middle -1));
|
||||
vector <std::string> A, aux;
|
||||
A.reserve (NMAXSTRING + n_middle);
|
||||
aux.reserve (n_middle);
|
||||
|
||||
if (bsc::fill_vector_string ("input.bin", A, NMAXSTRING + n_middle) != 0)
|
||||
{
|
||||
std::cout << "Error in the input file\n";
|
||||
return;
|
||||
std::exit (EXIT_FAILURE);
|
||||
};
|
||||
for ( size_t i = NMAXSTRING ; i < A.size() ; ++i)
|
||||
B.push_back ( std::move ( A[i]));
|
||||
A.resize ( NMAXSTRING);
|
||||
for (size_t i = 0; i < n_middle; ++i) aux.push_back (std::move (A [i]));
|
||||
|
||||
std::sort (A.begin() , A.end() );
|
||||
for ( size_t i =0 ; i< (NMAXSTRING >>1); ++i)
|
||||
std::swap ( A[i], A[NMAXSTRING - 1 - i]);
|
||||
std::sort (A.begin () + n_middle, A.end ());
|
||||
|
||||
size_t pos1 = n_middle, pos2 = A.size () - 1;
|
||||
for (size_t i = 0; i < (NMAXSTRING >> 1); ++i)
|
||||
std::swap (A [pos1 ++], A [pos2 --]);
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
// To insert n_middle elements, must have (n_middle - 1) intervals between
|
||||
// them. The size of the interval is step
|
||||
// The elements after the last element of aux don't need to be moved
|
||||
//-------------------------------------------------------------------------
|
||||
size_t step = NMAXSTRING / (n_middle - 1);
|
||||
A [0] = std::move (aux [0]);
|
||||
size_t pos_read = n_middle, pos_write = 1;
|
||||
|
||||
size_t step = NMAXSTRING /n_last +1 ;
|
||||
size_t pos = 0 ;
|
||||
|
||||
for ( size_t i =0 ; i < B.size() ; ++i, pos += step)
|
||||
{ C.push_back ( B[i]);
|
||||
for ( size_t k = 0 ; k < step ; ++k )
|
||||
C.push_back ( A[pos + k] );
|
||||
for (size_t i = 1; i < n_middle; ++i)
|
||||
{
|
||||
for (size_t k = 0 ; k < step; ++k)
|
||||
A [pos_write ++] = std::move (A [pos_read ++]);
|
||||
A [pos_write ++] = std::move (aux [i]);
|
||||
};
|
||||
while ( pos < A.size() )
|
||||
C.push_back ( A[pos++]);
|
||||
A = C ;
|
||||
|
||||
Test<std::string, std::less<std::string>>(A);
|
||||
aux.clear ();
|
||||
aux.reserve (0);
|
||||
Test (A);
|
||||
};
|
||||
|
||||
|
||||
template<class IA, class compare>
|
||||
int Test (std::vector<IA> &B, compare comp)
|
||||
{ //---------------------------- begin -----------------------------
|
||||
int Test (std::vector <std::string> &B)
|
||||
{
|
||||
//---------------------------- begin -----------------------------
|
||||
std::less <std::string> comp;
|
||||
double duration;
|
||||
time_point start, finish;
|
||||
std::vector<IA> A (B);
|
||||
std::vector<double> V;
|
||||
|
||||
std::vector <std::string> A (B);
|
||||
std::vector <double> V;
|
||||
|
||||
A = B;
|
||||
start = now ();
|
||||
@@ -344,11 +335,12 @@ int Test (std::vector<IA> &B, compare comp)
|
||||
//-----------------------------------------------------------------------
|
||||
// printing the vector
|
||||
//-----------------------------------------------------------------------
|
||||
std::cout<<std::setprecision(2)<<std::fixed;
|
||||
for ( uint32_t i =0 ; i < V.size() ; ++i)
|
||||
{ std::cout<<std::right<<std::setw(5)<<V[i]<<" |";
|
||||
std::cout << std::setprecision (2) << std::fixed;
|
||||
for (uint32_t i = 0; i < V.size () ; ++i)
|
||||
{
|
||||
std::cout << std::right << std::setw (5) << V [i] << " |";
|
||||
};
|
||||
std::cout<<std::endl;
|
||||
std::cout <<std::endl;
|
||||
return 0;
|
||||
};
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@ namespace bsc = boost::sort::common;
|
||||
|
||||
void print_banner();
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
int main(int argc, char *argv [])
|
||||
{ //---------------------------- begin--------------------------------------
|
||||
std::string name;
|
||||
size_t number;
|
||||
@@ -37,8 +37,8 @@ int main(int argc, char *argv[])
|
||||
cout << " file_generator file_name number_elements\n\n";
|
||||
return 0;
|
||||
};
|
||||
name = argv[1];
|
||||
number = atoi(argv[2]);
|
||||
name = argv [1];
|
||||
number = atoi (argv [2]);
|
||||
if (number == 0) {
|
||||
cout << "error, the number can't be zero\n";
|
||||
return 0;
|
||||
|
||||
@@ -7,9 +7,9 @@ echo "=================================================================="
|
||||
echo "."
|
||||
echo "C O M P I L I N G . . . . . . . . . . ."
|
||||
echo "."
|
||||
clang++ ./file_generator.cpp -std=c++11 -march=native -w -fexceptions -O3 -I../../include -s -o file_generator
|
||||
clang++ ./file_generator.cpp -std=c++11 -march=native -w -fno-exceptions -fno-operator-names -O3 -I../../include -s -o file_generator
|
||||
|
||||
clang++ ./benchmark_numbers.cpp -std=c++11 -march=native -w -fexceptions -O3 -I../../include -s -o benchmark_numbers
|
||||
clang++ ./benchmark_numbers.cpp -std=c++11 -march=native -w -fno-exceptions -fno-operator-names -O3 -I../../include -s -o benchmark_numbers
|
||||
|
||||
echo "R U N N I N G . . . . . . . . . . ."
|
||||
echo "( The time needed is around 10 minutes depending of your machine )"
|
||||
|
||||
@@ -7,9 +7,9 @@ echo "=================================================================="
|
||||
echo "."
|
||||
echo "C O M P I L I N G . . . . . . . . . . ."
|
||||
|
||||
clang++ ./file_generator.cpp -std=c++11 -march=native -w -fexceptions -O3 -I../../include -s -o file_generator
|
||||
clang++ ./file_generator.cpp -std=c++11 -march=native -w -fno-exceptions -fno-operator-names -O3 -I../../include -s -o file_generator
|
||||
|
||||
clang++ ./benchmark_objects.cpp -std=c++11 -march=native -w -fexceptions -O3 -I../../include -s -o benchmark_objects
|
||||
clang++ ./benchmark_objects.cpp -std=c++11 -march=native -w -fno-exceptions -fno-operator-names -O3 -I../../include -s -o benchmark_objects
|
||||
echo "."
|
||||
echo "R U N N I N G . . . . . . . . . . ."
|
||||
echo "( The time needed is around 45 minutes depending of your machine )"
|
||||
|
||||
@@ -7,9 +7,9 @@ echo "=================================================================="
|
||||
echo "."
|
||||
echo "C O M P I L I N G . . . . . . . . . . ."
|
||||
echo "."
|
||||
clang++ ./file_generator.cpp -std=c++11 -march=native -w -fexceptions -O3 -I../../include -s -o file_generator
|
||||
clang++ ./file_generator.cpp -std=c++11 -march=native -w -fno-exceptions -fno-operator-names -O3 -I../../include -s -o file_generator
|
||||
|
||||
clang++ ./benchmark_strings.cpp -std=c++11 -march=native -w -fexceptions -O3 -I../../include -s -o benchmark_strings
|
||||
clang++ ./benchmark_strings.cpp -std=c++11 -march=native -w -fno-exceptions -fno-operator-names -O3 -I../../include -s -o benchmark_strings
|
||||
|
||||
echo "R U N N I N G . . . . . . . . . . ."
|
||||
echo "( The time needed is around 10 minutes depending of your machine )"
|
||||
|
||||
@@ -7,9 +7,9 @@ echo "=================================================================="
|
||||
echo "."
|
||||
echo "C O M P I L I N G . . . . . . . . . . ."
|
||||
echo "."
|
||||
g++ ./file_generator.cpp -std=c++11 -march=native -w -fexceptions -O3 -I../../include -s -o file_generator
|
||||
g++ ./file_generator.cpp -std=c++11 -march=native -w -fno-exceptions -fno-operator-names -O3 -I../../include -s -o file_generator
|
||||
|
||||
g++ ./benchmark_numbers.cpp -std=c++11 -march=native -w -fexceptions -O3 -I../../include -s -o benchmark_numbers
|
||||
g++ ./benchmark_numbers.cpp -std=c++11 -march=native -w -fno-exceptions -fno-operator-names -O3 -I../../include -s -o benchmark_numbers
|
||||
|
||||
echo "R U N N I N G . . . . . . . . . . ."
|
||||
echo "( The time needed is around 10 minutes depending of your machine )"
|
||||
|
||||
@@ -7,9 +7,9 @@ echo "=================================================================="
|
||||
echo "."
|
||||
echo "C O M P I L I N G . . . . . . . . . . ."
|
||||
|
||||
g++ ./file_generator.cpp -std=c++11 -march=native -w -fexceptions -O3 -I../../include -s -o file_generator
|
||||
g++ ./file_generator.cpp -std=c++11 -march=native -w -fno-exceptions -fno-operator-names -O3 -I../../include -s -o file_generator
|
||||
|
||||
g++ ./benchmark_objects.cpp -std=c++11 -march=native -w -fexceptions -O3 -I../../include -s -o benchmark_objects
|
||||
g++ ./benchmark_objects.cpp -std=c++11 -march=native -w -fno-exceptions -fno-operator-names -O3 -I../../include -s -o benchmark_objects
|
||||
echo "."
|
||||
echo "R U N N I N G . . . . . . . . . . ."
|
||||
echo "( The time needed is around 45 minutes depending of your machine )"
|
||||
|
||||
@@ -7,9 +7,9 @@ echo "=================================================================="
|
||||
echo "."
|
||||
echo "C O M P I L I N G . . . . . . . . . . ."
|
||||
echo "."
|
||||
g++ ./file_generator.cpp -std=c++11 -march=native -w -fexceptions -O3 -I../../include -s -o file_generator
|
||||
g++ ./file_generator.cpp -std=c++11 -march=native -w -fno-exceptions -fno-operator-names -O3 -I../../include -s -o file_generator
|
||||
|
||||
g++ ./benchmark_strings.cpp -std=c++11 -march=native -w -fexceptions -O3 -I../../include -s -o benchmark_strings
|
||||
g++ ./benchmark_strings.cpp -std=c++11 -march=native -w -fno-exceptions -fno-operator-names -O3 -I../../include -s -o benchmark_strings
|
||||
|
||||
echo "R U N N I N G . . . . . . . . . . ."
|
||||
echo "( The time needed is around 10 minutes depending of your machine )"
|
||||
|
||||
28
build.jam
Normal file
28
build.jam
Normal file
@@ -0,0 +1,28 @@
|
||||
# Copyright René Ferdinand Rivera Morell 2023-2024
|
||||
# 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)
|
||||
|
||||
require-b2 5.2 ;
|
||||
|
||||
constant boost_dependencies :
|
||||
/boost/config//boost_config
|
||||
/boost/core//boost_core
|
||||
/boost/range//boost_range
|
||||
/boost/static_assert//boost_static_assert
|
||||
/boost/type_traits//boost_type_traits ;
|
||||
|
||||
project /boost/sort
|
||||
: common-requirements
|
||||
<include>include
|
||||
;
|
||||
|
||||
explicit
|
||||
[ alias boost_sort : : : : <library>$(boost_dependencies) ]
|
||||
[ alias all : boost_sort example test ]
|
||||
;
|
||||
|
||||
call-if
|
||||
: boost-library sort
|
||||
;
|
||||
|
||||
@@ -11,7 +11,10 @@ if --tune in [ modules.peek : ARGV ]
|
||||
properties = <location>. <variant>release ;
|
||||
}
|
||||
|
||||
project spreadsort : source-location example : requirements <include>../.. <include>../../.. $(properties) ;
|
||||
project : requirements $(properties)
|
||||
<library>/boost/algorithm//boost_algorithm
|
||||
<library>/boost/random//boost_random
|
||||
;
|
||||
|
||||
exe spreadsort : sample.cpp ;
|
||||
exe alreadysorted : alreadysorted.cpp ;
|
||||
@@ -107,7 +107,7 @@ struct backbone
|
||||
block_t get_block (size_t pos) const
|
||||
{
|
||||
return block_t (global_range.first + (pos * Block_size));
|
||||
};
|
||||
}
|
||||
//-------------------------------------------------------------------------
|
||||
// function : get_range
|
||||
/// @brief obtain the range in the position pos
|
||||
@@ -120,7 +120,7 @@ struct backbone
|
||||
Iter_t it2 =
|
||||
(pos == (nblock - 1)) ? global_range.last : it1 + Block_size;
|
||||
return range_it (it1, it2);
|
||||
};
|
||||
}
|
||||
//-------------------------------------------------------------------------
|
||||
// function : get_range_buf
|
||||
/// @brief obtain the auxiliary buffer of the thread
|
||||
@@ -128,7 +128,7 @@ struct backbone
|
||||
range_buf get_range_buf ( ) const
|
||||
{
|
||||
return range_buf (buf, buf + Block_size);
|
||||
};
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
// function : exec
|
||||
@@ -144,7 +144,7 @@ struct backbone
|
||||
{
|
||||
buf = ptr_buf;
|
||||
exec (counter);
|
||||
};
|
||||
}
|
||||
|
||||
void exec (atomic_t &counter);
|
||||
|
||||
@@ -192,7 +192,7 @@ backbone< Block_size, Iter_t, Compare >
|
||||
range_tail.first =
|
||||
(ntail == 0) ? last : (first + ((nblock - 1) * Block_size));
|
||||
range_tail.last = last;
|
||||
};
|
||||
}
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
// function : exec
|
||||
@@ -208,12 +208,12 @@ void backbone< Block_size, Iter_t, Compare >::exec (atomic_t &counter)
|
||||
{
|
||||
if (works.pop_move_back (func_exec)) func_exec ( );
|
||||
else std::this_thread::yield ( );
|
||||
};
|
||||
};
|
||||
}
|
||||
}
|
||||
//
|
||||
//****************************************************************************
|
||||
}; // End namespace blk_detail
|
||||
}; // End namespace sort
|
||||
}; // End namespace boost
|
||||
} // End namespace blk_detail
|
||||
} // End namespace sort
|
||||
} // End namespace boost
|
||||
//****************************************************************************
|
||||
#endif
|
||||
|
||||
@@ -44,7 +44,7 @@ class block_pos
|
||||
|
||||
public:
|
||||
//----------------------------- FUNCTIONS ------------------------------
|
||||
block_pos (void) : num (0){};
|
||||
block_pos (void) : num (0){}
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
// function : block_pos
|
||||
@@ -55,35 +55,35 @@ class block_pos
|
||||
block_pos (size_t position, bool side = false)
|
||||
{
|
||||
num = (position << 1) + ((side) ? 1 : 0);
|
||||
};
|
||||
}
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
// function : pos
|
||||
/// @brief obtain the position stored inside the block_pos
|
||||
/// @return position
|
||||
//-------------------------------------------------------------------------
|
||||
size_t pos (void) const { return (num >> 1); };
|
||||
size_t pos (void) const { return (num >> 1); }
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
// function : pos
|
||||
/// @brief store a position inside the block_pos
|
||||
/// @param position : value to store
|
||||
//-------------------------------------------------------------------------
|
||||
void set_pos (size_t position) { num = (position << 1) + (num & 1); };
|
||||
void set_pos (size_t position) { num = (position << 1) + (num & 1); }
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
// function : side
|
||||
/// @brief obtain the side stored inside the block_pos
|
||||
/// @return bool value
|
||||
//-------------------------------------------------------------------------
|
||||
bool side (void) const { return ((num & 1) != 0); };
|
||||
bool side (void) const { return ((num & 1) != 0); }
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
// function : side
|
||||
/// @brief store a bool value the block_pos
|
||||
/// @param sd : bool value to store
|
||||
//-------------------------------------------------------------------------
|
||||
void set_side (bool sd) { num = (num & ~1) + ((sd) ? 1 : 0); };
|
||||
void set_side (bool sd) { num = (num & ~1) + ((sd) ? 1 : 0); }
|
||||
}; // end struct block_pos
|
||||
|
||||
//
|
||||
@@ -105,7 +105,7 @@ struct block
|
||||
/// @brief constructor from an iterator to the first element of the block
|
||||
/// @param it : iterator to the first element of the block
|
||||
//-------------------------------------------------------------------------
|
||||
block (Iter_t it) : first (it){};
|
||||
block (Iter_t it) : first (it){}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
// function : get_range
|
||||
@@ -115,7 +115,7 @@ struct block
|
||||
range< Iter_t > get_range (void)
|
||||
{
|
||||
return range_it (first, first + Block_size);
|
||||
};
|
||||
}
|
||||
|
||||
}; // end struct block
|
||||
|
||||
@@ -133,7 +133,7 @@ bool compare_block (block< Block_size, Iter_t > block1,
|
||||
Compare cmp = Compare ( ))
|
||||
{
|
||||
return cmp (*block1.first, *block2.first);
|
||||
};
|
||||
}
|
||||
//
|
||||
///---------------------------------------------------------------------------
|
||||
/// @struct compare_block_pos
|
||||
@@ -155,7 +155,7 @@ struct compare_block_pos
|
||||
/// @param cmp : comparison operator
|
||||
//-------------------------------------------------------------------------
|
||||
compare_block_pos (Iter_t g_first, Compare cmp)
|
||||
: global_first (g_first), comp (cmp){};
|
||||
: global_first (g_first), comp (cmp){}
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
// function : operator ()
|
||||
@@ -168,14 +168,14 @@ struct compare_block_pos
|
||||
{
|
||||
return comp (*(global_first + (block_pos1.pos ( ) * Block_size)),
|
||||
*(global_first + (block_pos2.pos ( ) * Block_size)));
|
||||
};
|
||||
}
|
||||
|
||||
}; // end struct compare_block_pos
|
||||
|
||||
//****************************************************************************
|
||||
}; // End namespace blk_detail
|
||||
}; // End namespace sort
|
||||
}; // End namespace boost
|
||||
} // End namespace blk_detail
|
||||
} // End namespace sort
|
||||
} // End namespace boost
|
||||
//****************************************************************************
|
||||
//
|
||||
#endif
|
||||
|
||||
@@ -108,7 +108,7 @@ struct merge_blocks
|
||||
catch (std::bad_alloc &)
|
||||
{
|
||||
error = true;
|
||||
};
|
||||
}
|
||||
}
|
||||
bscu::atomic_sub (counter, 1);
|
||||
};
|
||||
@@ -143,7 +143,7 @@ struct merge_blocks
|
||||
catch (std::bad_alloc &)
|
||||
{
|
||||
error = true;
|
||||
};
|
||||
}
|
||||
}
|
||||
bscu::atomic_sub (counter, 1);
|
||||
};
|
||||
@@ -195,12 +195,12 @@ merge_blocks<Block_size, Group_size, Iter_t, Compare>
|
||||
for (size_t i = pos_index1; i < pos_index2; ++i)
|
||||
{
|
||||
vpos1.emplace_back(bk.index[i].pos(), true);
|
||||
};
|
||||
}
|
||||
|
||||
for (size_t i = pos_index2; i < pos_index3; ++i)
|
||||
{
|
||||
vpos2.emplace_back(bk.index[i].pos(), false);
|
||||
};
|
||||
}
|
||||
//-------------------------------------------------------------------
|
||||
// tail process
|
||||
//-------------------------------------------------------------------
|
||||
@@ -210,7 +210,7 @@ merge_blocks<Block_size, Group_size, Iter_t, Compare>
|
||||
tail_process(vpos1, vpos2);
|
||||
nblock1 = vpos1.size();
|
||||
nblock2 = vpos2.size();
|
||||
};
|
||||
}
|
||||
|
||||
compare_block_pos_t cmp_blk(bk.global_range.first, bk.cmp);
|
||||
if (bk.error) return;
|
||||
@@ -256,9 +256,9 @@ void merge_blocks<Block_size, Group_size, Iter_t, Compare>
|
||||
{
|
||||
vblkpos2.emplace_back(posback1, false);
|
||||
vblkpos1.pop_back();
|
||||
};
|
||||
};
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
@@ -278,7 +278,7 @@ void merge_blocks<Block_size, Group_size, Iter_t, Compare>
|
||||
{
|
||||
merge_range_pos(rng_input);
|
||||
return;
|
||||
};
|
||||
}
|
||||
|
||||
atomic_t counter(0);
|
||||
size_t npart = (rng_input.size() + Group_size - 1) / Group_size;
|
||||
@@ -294,7 +294,7 @@ void merge_blocks<Block_size, Group_size, Iter_t, Compare>
|
||||
and bk.index[pos - 1].side() == bk.index[pos].side())
|
||||
{
|
||||
++pos;
|
||||
};
|
||||
}
|
||||
if (pos < pos_last)
|
||||
{
|
||||
merge_uncontiguous(bk.get_range(bk.index[pos - 1].pos()),
|
||||
@@ -306,9 +306,9 @@ void merge_blocks<Block_size, Group_size, Iter_t, Compare>
|
||||
{
|
||||
range_pos rng_aux(pos_ini, pos);
|
||||
function_merge_range_pos(rng_aux, counter, bk.error);
|
||||
};
|
||||
}
|
||||
pos_ini = pos;
|
||||
};
|
||||
}
|
||||
bk.exec(counter); // wait until finish all the ranges
|
||||
}
|
||||
|
||||
@@ -337,7 +337,7 @@ void merge_blocks<Block_size, Group_size, Iter_t, Compare>
|
||||
bsc::merge_flow(rng_prev, rbuf, rng_posx, bk.cmp);
|
||||
rng_prev = rng_posx;
|
||||
|
||||
};
|
||||
}
|
||||
move_forward(rng_posx, rbuf);
|
||||
}
|
||||
//
|
||||
@@ -384,7 +384,7 @@ void merge_blocks<Block_size, Group_size, Iter_t, Compare>
|
||||
side_posx = bp_posx.side();
|
||||
mergeable = (side_max != side_posx
|
||||
and is_mergeable(rng_max, rng_posx, bk.cmp));
|
||||
};
|
||||
}
|
||||
if (bk.error) return;
|
||||
if (final or not mergeable)
|
||||
{
|
||||
@@ -398,14 +398,14 @@ void merge_blocks<Block_size, Group_size, Iter_t, Compare>
|
||||
else
|
||||
{
|
||||
function_merge_range_pos(rp_final, counter, bk.error);
|
||||
};
|
||||
};
|
||||
}
|
||||
}
|
||||
posx_ini = posx;
|
||||
if (not final)
|
||||
{
|
||||
rng_max = rng_posx;
|
||||
side_max = side_posx;
|
||||
};
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -413,16 +413,16 @@ void merge_blocks<Block_size, Group_size, Iter_t, Compare>
|
||||
{
|
||||
rng_max = rng_posx;
|
||||
side_max = side_posx;
|
||||
};
|
||||
};
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
bk.exec(counter);
|
||||
}
|
||||
//
|
||||
//****************************************************************************
|
||||
}; // End namespace blk_detail
|
||||
}; // End namespace sort
|
||||
}; // End namespace boost
|
||||
} // End namespace blk_detail
|
||||
} // End namespace sort
|
||||
} // End namespace boost
|
||||
//****************************************************************************
|
||||
//
|
||||
#endif
|
||||
|
||||
@@ -95,7 +95,7 @@ struct move_blocks
|
||||
catch (std::bad_alloc &)
|
||||
{
|
||||
error = true;
|
||||
};
|
||||
}
|
||||
}
|
||||
bscu::atomic_sub (counter, 1);
|
||||
};
|
||||
@@ -130,13 +130,13 @@ struct move_blocks
|
||||
catch (std::bad_alloc &)
|
||||
{
|
||||
error = true;
|
||||
};
|
||||
}
|
||||
}
|
||||
bscu::atomic_sub (counter, 1);
|
||||
};
|
||||
bk.works.emplace_back(f1);
|
||||
}
|
||||
;
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
}; // end of struct move_blocks
|
||||
//---------------------------------------------------------------------------
|
||||
@@ -172,7 +172,7 @@ move_blocks<Block_size, Group_size, Iter_t, Compare>
|
||||
and bk.index[pos_index_ini].pos() == pos_index_ini)
|
||||
{
|
||||
++pos_index_ini;
|
||||
};
|
||||
}
|
||||
|
||||
if (pos_index_ini == bk.index.size()) break;
|
||||
|
||||
@@ -187,7 +187,7 @@ move_blocks<Block_size, Group_size, Iter_t, Compare>
|
||||
|
||||
bk.index[pos_index_dest].set_pos(pos_index_dest);
|
||||
pos_index_dest = pos_index_src;
|
||||
};
|
||||
}
|
||||
|
||||
bk.index[pos_index_dest].set_pos(pos_index_dest);
|
||||
vsequence.push_back(sequence);
|
||||
@@ -199,11 +199,11 @@ move_blocks<Block_size, Group_size, Iter_t, Compare>
|
||||
else
|
||||
{
|
||||
function_move_long_sequence(vsequence.back(), counter, bk.error);
|
||||
};
|
||||
};
|
||||
}
|
||||
}
|
||||
bk.exec(counter);
|
||||
}
|
||||
;
|
||||
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
// function : move_sequence
|
||||
@@ -228,9 +228,9 @@ void move_blocks<Block_size, Group_size, Iter_t, Compare>
|
||||
range_it range1(range2);
|
||||
range2 = bk.get_range(pos_range2);
|
||||
move_forward(range1, range2);
|
||||
};
|
||||
}
|
||||
move_forward(range2, rbuf);
|
||||
};
|
||||
}
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
// function : move_long_sequence
|
||||
@@ -264,7 +264,7 @@ void move_blocks<Block_size, Group_size, Iter_t, Compare>
|
||||
sequence.assign(it_pos, it_pos + size_part);
|
||||
index_seq.emplace_back(*(it_pos + size_part - 1));
|
||||
function_move_sequence(sequence, son_counter, bk.error);
|
||||
};
|
||||
}
|
||||
|
||||
sequence.assign(it_pos, init_sequence.end());
|
||||
index_seq.emplace_back(init_sequence.back());
|
||||
@@ -277,9 +277,9 @@ void move_blocks<Block_size, Group_size, Iter_t, Compare>
|
||||
|
||||
//
|
||||
//****************************************************************************
|
||||
}; // End namespace blk_detail
|
||||
}; // End namespace sort
|
||||
}; // End namespace boost
|
||||
} // End namespace blk_detail
|
||||
} // End namespace sort
|
||||
} // End namespace boost
|
||||
//****************************************************************************
|
||||
//
|
||||
#endif
|
||||
|
||||
@@ -103,12 +103,12 @@ struct parallel_sort
|
||||
catch (std::bad_alloc &)
|
||||
{
|
||||
error = true;
|
||||
};
|
||||
};
|
||||
}
|
||||
}
|
||||
bscu::atomic_sub (counter, 1);
|
||||
};
|
||||
bk.works.emplace_back(f1);
|
||||
};
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
};// end struct parallel_sort
|
||||
@@ -156,7 +156,7 @@ parallel_sort<Block_size, Iter_t, Compare>
|
||||
for (size_t i = 0; i < nelem2; ++i)
|
||||
swap(*(it1++), *(it2--));
|
||||
return;
|
||||
};
|
||||
}
|
||||
|
||||
//-------------------max_per_thread ---------------------------
|
||||
uint32_t nbits_size = (nbits64(sizeof(value_t))) >> 1;
|
||||
@@ -170,12 +170,12 @@ parallel_sort<Block_size, Iter_t, Compare>
|
||||
{
|
||||
pdqsort(first, last, bk.cmp);
|
||||
return;
|
||||
};
|
||||
}
|
||||
if (not bk.error) divide_sort(first, last, level);
|
||||
|
||||
// wait until all the parts are finished
|
||||
bk.exec(counter);
|
||||
};
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
// function : divide_sort
|
||||
@@ -201,7 +201,7 @@ void parallel_sort<Block_size, Iter_t, Compare>
|
||||
if (level == 0 or nelem < (max_per_thread))
|
||||
{
|
||||
return pdqsort(first, last, bk.cmp);
|
||||
};
|
||||
}
|
||||
|
||||
//-------------------- pivoting ----------------------------------
|
||||
pivot9(first, last, bk.cmp);
|
||||
@@ -218,7 +218,7 @@ void parallel_sort<Block_size, Iter_t, Compare>
|
||||
++c_first;
|
||||
while (bk.cmp(val, *c_last))
|
||||
--c_last;
|
||||
};
|
||||
}
|
||||
|
||||
swap(*first, *c_last);
|
||||
|
||||
@@ -228,12 +228,12 @@ void parallel_sort<Block_size, Iter_t, Compare>
|
||||
|
||||
// The first half is done by the same thread
|
||||
function_divide_sort(first, c_last, level - 1, counter, bk.error);
|
||||
};
|
||||
}
|
||||
//
|
||||
//****************************************************************************
|
||||
};// End namespace blk_detail
|
||||
};// End namespace sort
|
||||
};// End namespace boost
|
||||
} // End namespace blk_detail
|
||||
} // End namespace sort
|
||||
} // End namespace boost
|
||||
//****************************************************************************
|
||||
//
|
||||
#endif
|
||||
|
||||
@@ -144,10 +144,10 @@ struct block_indirect_sort
|
||||
{
|
||||
destroy(rglobal_buf);
|
||||
construct = false;
|
||||
};
|
||||
}
|
||||
std::free (ptr);
|
||||
ptr = nullptr;
|
||||
};
|
||||
}
|
||||
}
|
||||
//
|
||||
//------------------------------------------------------------------------
|
||||
@@ -218,9 +218,9 @@ block_indirect_sort<Block_size, Group_size, Iter_t, Compare>
|
||||
{
|
||||
using std::swap;
|
||||
swap(*(it1++), *(it2--));
|
||||
};
|
||||
}
|
||||
return;
|
||||
};
|
||||
}
|
||||
|
||||
//---------------- check if only single thread -----------------------
|
||||
size_t nthreadmax = nelem / (Block_size * Group_size) + 1;
|
||||
@@ -235,7 +235,7 @@ block_indirect_sort<Block_size, Group_size, Iter_t, Compare>
|
||||
//intro_sort (first, last, bk.cmp);
|
||||
pdqsort(first, last, bk.cmp);
|
||||
return;
|
||||
};
|
||||
}
|
||||
|
||||
//----------- creation of the temporary buffer --------------------
|
||||
ptr = reinterpret_cast <value_t*>
|
||||
@@ -244,7 +244,7 @@ block_indirect_sort<Block_size, Group_size, Iter_t, Compare>
|
||||
{
|
||||
bk.error = true;
|
||||
throw std::bad_alloc();
|
||||
};
|
||||
}
|
||||
|
||||
rglobal_buf = range_buf(ptr, ptr + (Block_size * nthread));
|
||||
initialize(rglobal_buf, *first);
|
||||
@@ -255,7 +255,7 @@ block_indirect_sort<Block_size, Group_size, Iter_t, Compare>
|
||||
for (uint32_t i = 0; i < nthread; ++i)
|
||||
{
|
||||
vbuf[i] = ptr + (i * Block_size);
|
||||
};
|
||||
}
|
||||
|
||||
// Insert the first work in the stack
|
||||
bscu::atomic_write(counter, 1);
|
||||
@@ -280,7 +280,7 @@ block_indirect_sort<Block_size, Group_size, Iter_t, Compare>
|
||||
auto f1 = [&vbuf,i, this]( )
|
||||
{ bk.exec (vbuf[i], this->counter);};
|
||||
vfuture[i] = std::async(std::launch::async, f1);
|
||||
};
|
||||
}
|
||||
for (uint32_t i = 0; i < nthread; ++i)
|
||||
vfuture[i].get();
|
||||
if (bk.error) throw std::bad_alloc();
|
||||
@@ -290,7 +290,7 @@ block_indirect_sort<Block_size, Group_size, Iter_t, Compare>
|
||||
destroy_all();
|
||||
throw;
|
||||
}
|
||||
};
|
||||
}
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
// function : split_rage
|
||||
@@ -317,7 +317,7 @@ void block_indirect_sort<Block_size, Group_size, Iter_t, Compare>
|
||||
{
|
||||
pdqsort(first, last, bk.cmp);
|
||||
return;
|
||||
};
|
||||
}
|
||||
|
||||
size_t pos_index_mid = pos_index1 + (nblock >> 1);
|
||||
atomic_t son_counter(1);
|
||||
@@ -349,11 +349,11 @@ void block_indirect_sort<Block_size, Group_size, Iter_t, Compare>
|
||||
bk.works.emplace_back(f1);
|
||||
if (bk.error) return;
|
||||
parallel_sort_t(bk, first, mid);
|
||||
};
|
||||
}
|
||||
bk.exec(son_counter);
|
||||
if (bk.error) return;
|
||||
merge_blocks_t(bk, pos_index1, pos_index_mid, pos_index2);
|
||||
};
|
||||
}
|
||||
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
@@ -375,8 +375,8 @@ void block_indirect_sort<Block_size, Group_size, Iter_t, Compare>
|
||||
split_range(0, bk.nblock, level_thread - 1);
|
||||
if (bk.error) return;
|
||||
move_blocks_t k(bk);
|
||||
};
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
///---------------------------------------------------------------------------
|
||||
// function block_indirect_sort_call
|
||||
@@ -390,7 +390,7 @@ inline void block_indirect_sort_call(Iter_t first, Iter_t last, Compare cmp,
|
||||
uint32_t nthr)
|
||||
{
|
||||
block_indirect_sort<128, 128, Iter_t, Compare>(first, last, cmp, nthr);
|
||||
};
|
||||
}
|
||||
|
||||
template<size_t Size>
|
||||
struct block_size
|
||||
@@ -415,11 +415,11 @@ inline void block_indirect_sort_call (Iter_t first, Iter_t last, Compare cmp,
|
||||
{
|
||||
block_indirect_sort<block_size<sizeof (value_iter<Iter_t> )>::data, 64,
|
||||
Iter_t, Compare> (first, last, cmp, nthr);
|
||||
};
|
||||
}
|
||||
|
||||
//
|
||||
//****************************************************************************
|
||||
}; // End namespace blk_detail
|
||||
} // End namespace blk_detail
|
||||
//****************************************************************************
|
||||
//
|
||||
namespace bscu = boost::sort::common::util;
|
||||
@@ -503,8 +503,8 @@ void block_indirect_sort (Iter_t first, Iter_t last, Compare comp,
|
||||
}
|
||||
//
|
||||
//****************************************************************************
|
||||
}; // End namespace sort
|
||||
}; // End namespace boost
|
||||
} // End namespace sort
|
||||
} // End namespace boost
|
||||
//****************************************************************************
|
||||
//
|
||||
#endif
|
||||
|
||||
@@ -79,7 +79,8 @@ void create_index(Iter_t first, Iter_t last, std::vector<Iter_t> &index)
|
||||
index.clear();
|
||||
index.reserve(nelem);
|
||||
for (; first != last; ++first) index.push_back(first);
|
||||
};
|
||||
}
|
||||
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
// function : sort_index
|
||||
@@ -102,11 +103,11 @@ void sort_index(Iter_t global_first, std::vector<Iter_t> &index)
|
||||
|
||||
while (pos_in_vector < nelem)
|
||||
{
|
||||
while (pos_in_vector < nelem and
|
||||
while (pos_in_vector < nelem &&
|
||||
(size_t(index[pos_in_vector] - global_first)) == pos_in_vector)
|
||||
{
|
||||
++pos_in_vector;
|
||||
};
|
||||
}
|
||||
|
||||
if (pos_in_vector == nelem) return;
|
||||
pos_dest = pos_src = pos_in_vector;
|
||||
@@ -121,13 +122,13 @@ void sort_index(Iter_t global_first, std::vector<Iter_t> &index)
|
||||
*it_dest = std::move(*it_src);
|
||||
it_dest = it_src;
|
||||
pos_dest = pos_src;
|
||||
};
|
||||
}
|
||||
|
||||
*it_dest = std::move(Aux);
|
||||
index[pos_dest] = it_dest;
|
||||
++pos_in_vector;
|
||||
};
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
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)
|
||||
@@ -141,13 +142,13 @@ void indirect_sort(func method, Iter_t first, Iter_t last, Compare comp)
|
||||
less_ptr_no_null<Iter_t, Compare> index_comp(comp);
|
||||
method(index.begin(), index.end(), index_comp);
|
||||
sort_index(first, index);
|
||||
};
|
||||
}
|
||||
|
||||
//
|
||||
//****************************************************************************
|
||||
};// End namespace common
|
||||
};// End namespace sort
|
||||
};// End namespace boost
|
||||
}// End namespace common
|
||||
}// End namespace sort
|
||||
}// End namespace boost
|
||||
//****************************************************************************
|
||||
//
|
||||
#endif
|
||||
|
||||
@@ -14,7 +14,6 @@
|
||||
#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>
|
||||
@@ -126,7 +125,7 @@ struct merge_block
|
||||
|
||||
~ merge_block()
|
||||
{
|
||||
if (ptr_circ != nullptr and owned)
|
||||
if (ptr_circ != nullptr && owned)
|
||||
{
|
||||
delete ptr_circ;
|
||||
ptr_circ = nullptr;
|
||||
@@ -171,7 +170,7 @@ struct merge_block
|
||||
//-------------------------------------------------------------------------
|
||||
bool is_tail(size_t pos) const
|
||||
{
|
||||
return (pos == (nblock - 1) and ntail != 0);
|
||||
return (pos == (nblock - 1) && ntail != 0);
|
||||
};
|
||||
//-------------------------------------------------------------------------
|
||||
// function :
|
||||
@@ -223,10 +222,10 @@ template<class Iter_t, class Compare, uint32_t Power2>
|
||||
void merge_block<Iter_t, Compare, Power2>
|
||||
::merge_range_pos(it_index itx_first, it_index itx_mid,it_index itx_last)
|
||||
{
|
||||
assert((itx_last - itx_mid) >= 0 and (itx_mid - itx_first) >= 0);
|
||||
assert((itx_last - itx_mid) >= 0 && (itx_mid - itx_first) >= 0);
|
||||
|
||||
size_t nelemA = (itx_mid - itx_first), nelemB = (itx_last - itx_mid);
|
||||
if (nelemA == 0 or nelemB == 0) return;
|
||||
if (nelemA == 0 || nelemB == 0) return;
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Create two index with the position of the blocks to merge
|
||||
@@ -244,17 +243,17 @@ void merge_block<Iter_t, Compare, Power2>
|
||||
Iter_t itA = global_range.first, itB = global_range.first;
|
||||
bool validA = false, validB = false;
|
||||
|
||||
while (itxA != indexA.end() and itxB != indexB.end())
|
||||
while (itxA != indexA.end() && itxB != indexB.end())
|
||||
{ //----------------------------------------------------------------
|
||||
// Load valid ranges from the itxA and ItxB positions
|
||||
//----------------------------------------------------------------
|
||||
if (not validA)
|
||||
if (! validA)
|
||||
{
|
||||
rngA = get_range(*itxA);
|
||||
itA = rngA.first;
|
||||
validA = true;
|
||||
};
|
||||
if (not validB)
|
||||
if (! validB)
|
||||
{
|
||||
rngB = get_range(*itxB);
|
||||
itB = rngB.first;
|
||||
@@ -266,7 +265,7 @@ void merge_block<Iter_t, Compare, Power2>
|
||||
//----------------------------------------------------------------
|
||||
if (ptr_circ->size() == 0)
|
||||
{
|
||||
if (not cmp(*rngB.front(), *rngA.back()))
|
||||
if (! cmp(*rngB.front(), *rngA.back()))
|
||||
{
|
||||
*(itx_out++) = *(itxA++);
|
||||
validA = false;
|
||||
@@ -274,7 +273,7 @@ void merge_block<Iter_t, Compare, Power2>
|
||||
};
|
||||
if (cmp(*rngB.back(), *rngA.front()))
|
||||
{
|
||||
if (not is_tail(*itxB))
|
||||
if (! is_tail(*itxB))
|
||||
*(itx_out++) = *itxB;
|
||||
else ptr_circ->push_move_back(rngB.first, rngB.size());
|
||||
++itxB;
|
||||
@@ -295,7 +294,7 @@ void merge_block<Iter_t, Compare, Power2>
|
||||
}
|
||||
else
|
||||
{ // rngB is finished
|
||||
if (not is_tail(*itxB))
|
||||
if (! is_tail(*itxB))
|
||||
{
|
||||
ptr_circ->pop_move_front(rngB.first, rngB.size());
|
||||
*(itx_out++) = *itxB;
|
||||
@@ -315,7 +314,7 @@ void merge_block<Iter_t, Compare, Power2>
|
||||
else
|
||||
{ // The list B is finished
|
||||
rngA = get_range(*itxA);
|
||||
if (ntail != 0 and indexB.back() == (nblock - 1)) // exist tail
|
||||
if (ntail != 0 && indexB.back() == (nblock - 1)) // exist tail
|
||||
{ // add the tail block to indexA, and shift the element
|
||||
indexA.push_back(indexB.back());
|
||||
size_t numA = size_t(itA - rngA.first);
|
||||
@@ -327,7 +326,7 @@ void merge_block<Iter_t, Compare, Power2>
|
||||
while (itxA != indexA.end())
|
||||
*(itx_out++) = *(itxA++);
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
// function : move_range_pos_backward
|
||||
@@ -341,7 +340,7 @@ template<class Iter_t, class Compare, uint32_t Power2>
|
||||
void merge_block<Iter_t, Compare, Power2>
|
||||
::move_range_pos_backward(it_index itx_first, it_index itx_last, size_t npos)
|
||||
{
|
||||
assert((itx_last - itx_first) >= 0 and npos <= BLOCK_SIZE);
|
||||
assert((itx_last - itx_first) >= 0 && npos <= BLOCK_SIZE);
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
// Processing the last block. Must be ready fore to accept npos
|
||||
@@ -366,7 +365,7 @@ void merge_block<Iter_t, Compare, Power2>
|
||||
util::move_backward(it_mid2, it_mid1, rng1.last);
|
||||
util::move_backward(rng1.last, rng1.first, it_mid1);
|
||||
};
|
||||
};
|
||||
}
|
||||
//-------------------------------------------------------------------------
|
||||
// function : rearrange_with_index
|
||||
/// @brief rearrange the blocks with the relative positions of the index
|
||||
@@ -391,7 +390,7 @@ void merge_block<Iter_t, Compare, Power2>
|
||||
pos_ini = 0;
|
||||
while (pos_ini < nelem)
|
||||
{
|
||||
while (pos_ini < nelem and index[pos_ini] == pos_ini)
|
||||
while (pos_ini < nelem && index[pos_ini] == pos_ini)
|
||||
++pos_ini;
|
||||
if (pos_ini == nelem) return;
|
||||
pos_dest = pos_src = pos_ini;
|
||||
@@ -409,11 +408,11 @@ void merge_block<Iter_t, Compare, Power2>
|
||||
index[pos_dest] = pos_dest;
|
||||
++pos_ini;
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
//****************************************************************************
|
||||
};// End namespace common
|
||||
};// End namespace sort
|
||||
};// End namespace boost
|
||||
}// End namespace common
|
||||
}// End namespace sort
|
||||
}// End namespace boost
|
||||
//****************************************************************************
|
||||
#endif
|
||||
|
||||
@@ -57,7 +57,7 @@ inline bool less_range(Iter_t it1, uint32_t pos1, Iter_t it2, uint32_t pos2,
|
||||
{
|
||||
return (comp(*it1, *it2)) ? true :
|
||||
(pos2 < pos1) ? false : not (comp(*it2, *it1));
|
||||
};
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// function : full_merge4
|
||||
@@ -96,17 +96,17 @@ range<Iter1_t> full_merge4(const range<Iter1_t> &rdest,
|
||||
for (uint32_t k = i + 1; k < nrange_input; ++k)
|
||||
{
|
||||
vrange_input[k - 1] = vrange_input[k];
|
||||
};
|
||||
}
|
||||
--nrange_input;
|
||||
};
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
if (nrange_input == 0) return range1_t(rdest.first, rdest.first);
|
||||
if (nrange_input == 1) return move_forward(rdest, vrange_input[0]);
|
||||
if (nrange_input == 2)
|
||||
{
|
||||
return merge(rdest, vrange_input[0], vrange_input[1], comp);
|
||||
};
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
// Initial sort
|
||||
@@ -122,12 +122,12 @@ range<Iter1_t> full_merge4(const range<Iter1_t> &rdest,
|
||||
vrange_input[pos[0]].first, pos[0], comp))
|
||||
{
|
||||
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))
|
||||
{
|
||||
swap(pos[3], pos[2]);
|
||||
};
|
||||
}
|
||||
if (less_range (vrange_input[pos[2]].first, pos[2],
|
||||
vrange_input[pos[0]].first, pos[0], comp))
|
||||
{
|
||||
@@ -138,12 +138,12 @@ range<Iter1_t> full_merge4(const range<Iter1_t> &rdest,
|
||||
vrange_input[pos[1]].first, pos[1], comp))
|
||||
{
|
||||
swap(pos[1], pos[3]);
|
||||
};
|
||||
}
|
||||
if (less_range (vrange_input[pos[2]].first, pos[2],
|
||||
vrange_input[pos[1]].first, pos[1], comp))
|
||||
{
|
||||
swap(pos[1], pos[2]);
|
||||
};
|
||||
}
|
||||
|
||||
Iter1_t it_dest = rdest.first;
|
||||
while (npos > 2)
|
||||
@@ -173,11 +173,11 @@ range<Iter1_t> full_merge4(const range<Iter1_t> &rdest,
|
||||
pos[2], comp))
|
||||
{
|
||||
swap(pos[2], pos[3]);
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
range1_t raux1(rdest.first, it_dest), raux2(it_dest, rdest.last);
|
||||
if (pos[0] < pos[1])
|
||||
@@ -189,8 +189,8 @@ range<Iter1_t> full_merge4(const range<Iter1_t> &rdest,
|
||||
{
|
||||
return concat(raux1, merge (raux2, vrange_input[pos[1]],
|
||||
vrange_input[pos[0]], comp));
|
||||
};
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// function : uninit_full_merge4
|
||||
@@ -236,7 +236,7 @@ range<Value_t *> uninit_full_merge4(const range<Value_t *> &dest,
|
||||
if (nrange_input == 2)
|
||||
{
|
||||
return merge_construct(dest, vrange_input[0], vrange_input[1], comp);
|
||||
};
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
// Initial sort
|
||||
@@ -319,13 +319,13 @@ range<Value_t *> uninit_full_merge4(const range<Value_t *> &dest,
|
||||
return concat(raux1,
|
||||
merge_construct(raux2, vrange_input[pos[1]],
|
||||
vrange_input[pos[0]], comp));
|
||||
};
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
//****************************************************************************
|
||||
};// End namespace common
|
||||
};// End namespace sort
|
||||
};// End namespace boost
|
||||
}// End namespace common
|
||||
}// End namespace sort
|
||||
}// End namespace boost
|
||||
//****************************************************************************
|
||||
//
|
||||
#endif
|
||||
|
||||
@@ -67,7 +67,7 @@ void merge_level4(range<Iter1_t> dest, std::vector<range<Iter2_t> > &v_input,
|
||||
{
|
||||
v_output.emplace_back(move_forward(dest, v_input[0]));
|
||||
return;
|
||||
};
|
||||
}
|
||||
|
||||
uint32_t nrange = v_input.size();
|
||||
uint32_t pos_ini = 0;
|
||||
@@ -80,9 +80,9 @@ void merge_level4(range<Iter1_t> dest, std::vector<range<Iter2_t> > &v_input,
|
||||
dest.first = rz.last;
|
||||
pos_ini += nelem;
|
||||
nrange -= nelem;
|
||||
};
|
||||
}
|
||||
return;
|
||||
};
|
||||
}
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
// function : uninit_merge_level4
|
||||
@@ -129,7 +129,7 @@ void uninit_merge_level4(range<Value_t *> dest,
|
||||
nrange -= nelem;
|
||||
};
|
||||
return;
|
||||
};
|
||||
}
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
// function : merge_vector4
|
||||
@@ -187,12 +187,12 @@ range<Iter2_t> merge_vector4(range<Iter1_t> range_input,
|
||||
};
|
||||
};
|
||||
return (sw) ? v_output[0] : move_forward(range_output, v_input[0]);
|
||||
};
|
||||
}
|
||||
|
||||
//****************************************************************************
|
||||
};// End namespace common
|
||||
};// End namespace sort
|
||||
};// End namespace boost
|
||||
}// End namespace common
|
||||
}// End namespace sort
|
||||
}// End namespace boost
|
||||
//****************************************************************************
|
||||
//
|
||||
#endif
|
||||
|
||||
@@ -50,7 +50,7 @@ inline Iter_t mid3 (Iter_t iter_1, Iter_t iter_2, Iter_t iter_3, Compare comp)
|
||||
if (comp (*iter_2, *iter_1)) swap ( *iter_2, *iter_1);
|
||||
};
|
||||
return iter_2;
|
||||
};
|
||||
}
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
// function : pivot3
|
||||
@@ -69,7 +69,7 @@ inline void pivot3 (Iter_t first, Iter_t last, Compare comp)
|
||||
auto N2 = (last - first) >> 1;
|
||||
Iter_t it_val = mid3 (first + 1, first + N2, last - 1, comp);
|
||||
swap (*first, *it_val);
|
||||
};
|
||||
}
|
||||
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
@@ -96,7 +96,7 @@ inline Iter_t mid9 (Iter_t iter_1, Iter_t iter_2, Iter_t iter_3, Iter_t iter_4,
|
||||
return mid3 (mid3 (iter_1, iter_2, iter_3, comp),
|
||||
mid3 (iter_4, iter_5, iter_6, comp),
|
||||
mid3 (iter_7, iter_8, iter_9, comp), comp);
|
||||
};
|
||||
}
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
// function : pivot9
|
||||
@@ -118,10 +118,10 @@ inline void pivot9 (Iter_t first, Iter_t last, Compare comp)
|
||||
first + 3 * cupo, first + 4 * cupo, first + 5 * cupo,
|
||||
first + 6 * cupo, first + 7 * cupo, last - 1, comp);
|
||||
swap (*first, *itaux);
|
||||
};
|
||||
}
|
||||
//****************************************************************************
|
||||
};// End namespace common
|
||||
};// End namespace sort
|
||||
};// End namespace boost
|
||||
}// End namespace common
|
||||
}// End namespace sort
|
||||
}// End namespace boost
|
||||
//****************************************************************************
|
||||
#endif
|
||||
|
||||
@@ -13,7 +13,6 @@
|
||||
#ifndef __BOOST_SORT_PARALLEL_DETAIL_UTIL_RANGE_HPP
|
||||
#define __BOOST_SORT_PARALLEL_DETAIL_UTIL_RANGE_HPP
|
||||
|
||||
#include <ciso646>
|
||||
#include <cassert>
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
@@ -110,7 +109,7 @@ inline range<Iter_t> concat(const range<Iter_t> &it1, const range<Iter_t> &it2)
|
||||
{
|
||||
return range<Iter_t>(it1.first, it2.last);
|
||||
}
|
||||
;
|
||||
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
// function : move_forward
|
||||
@@ -126,7 +125,8 @@ inline range<Iter2_t> move_forward(const range<Iter2_t> &dest,
|
||||
assert(dest.size() >= src.size());
|
||||
Iter2_t it_aux = util::move_forward(dest.first, src.first, src.last);
|
||||
return range<Iter2_t>(dest.first, it_aux);
|
||||
};
|
||||
}
|
||||
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
// function : move_backward
|
||||
@@ -143,7 +143,7 @@ inline range<Iter2_t> move_backward(const range<Iter2_t> &dest,
|
||||
Iter2_t it_aux = util::move_backward(dest.first + src.size(), src.first,
|
||||
src.last);
|
||||
return range<Iter2_t>(dest.first, dest.src.size());
|
||||
};
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// function : uninit_move
|
||||
@@ -159,7 +159,8 @@ inline range<Value_t*> move_construct(const range<Value_t*> &dest,
|
||||
{
|
||||
Value_t *ptr_aux = util::move_construct(dest.first, src.first, src.last);
|
||||
return range<Value_t*>(dest.first, ptr_aux);
|
||||
};
|
||||
}
|
||||
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
// function : destroy
|
||||
@@ -170,7 +171,8 @@ template<class Iter_t>
|
||||
inline void destroy(range<Iter_t> rng)
|
||||
{
|
||||
util::destroy(rng.first, rng.last);
|
||||
};
|
||||
}
|
||||
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
// function : initialize
|
||||
@@ -184,7 +186,8 @@ inline range<Iter_t> initialize(const range<Iter_t> &rng, Value_t &val)
|
||||
{
|
||||
util::initialize(rng.first, rng.last, val);
|
||||
return rng;
|
||||
};
|
||||
}
|
||||
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
// function : is_mergeable
|
||||
@@ -210,7 +213,8 @@ inline bool is_mergeable(const range<Iter1_t> &src1, const range<Iter2_t> &src2,
|
||||
// Code
|
||||
//------------------------------------------------------------------------
|
||||
return comp(*(src2.front()), *(src1.back()));
|
||||
};
|
||||
}
|
||||
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
// function : is_mergeable_stable
|
||||
@@ -235,8 +239,9 @@ inline bool is_mergeable_stable(const range<Iter1_t> &src1,
|
||||
//------------------------------------------------------------------------
|
||||
// Code
|
||||
//------------------------------------------------------------------------
|
||||
return not comp(*(src1.back()), *(src2.front()));
|
||||
};
|
||||
return ! comp(*(src1.back()), *(src2.front()));
|
||||
}
|
||||
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
// function : merge
|
||||
@@ -259,7 +264,7 @@ inline range<Iter3_t> merge(const range<Iter3_t> &dest,
|
||||
Iter3_t it_aux = util::merge(src1.first, src1.last, src2.first, src2.last,
|
||||
dest.first, comp);
|
||||
return range<Iter3_t>(dest.first, it_aux);
|
||||
};
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// function : merge_construct
|
||||
@@ -284,7 +289,8 @@ inline range<Value_t *> merge_construct(const range<Value_t *> &dest,
|
||||
Value_t * ptr_aux = util::merge_construct(src1.first, src1.last, src2.first,
|
||||
src2.last, dest.first, comp);
|
||||
return range<Value_t*>(dest.first, ptr_aux);
|
||||
};
|
||||
}
|
||||
|
||||
//
|
||||
//---------------------------------------------------------------------------
|
||||
// function : half_merge
|
||||
@@ -307,7 +313,8 @@ inline range<Iter2_t> merge_half(const range<Iter2_t> &dest,
|
||||
Iter2_t it_aux = util::merge_half(src1.first, src1.last, src2.first,
|
||||
src2.last, dest.first, comp);
|
||||
return range<Iter2_t>(dest.first, it_aux);
|
||||
};
|
||||
}
|
||||
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
// function : merge_uncontiguous
|
||||
@@ -327,7 +334,8 @@ inline bool merge_uncontiguous(const range<Iter1_t> &src1,
|
||||
{
|
||||
return util::merge_uncontiguous(src1.first, src1.last, src2.first,
|
||||
src2.last, aux.first, comp);
|
||||
};
|
||||
}
|
||||
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
// function : merge_contiguous
|
||||
@@ -346,7 +354,8 @@ inline range<Iter1_t> merge_contiguous(const range<Iter1_t> &src1,
|
||||
{
|
||||
util::merge_contiguous(src1.first, src1.last, src2.last, buf.first, comp);
|
||||
return concat(src1, src2);
|
||||
};
|
||||
}
|
||||
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
// function : merge_flow
|
||||
@@ -380,7 +389,7 @@ static void merge_flow(range<Iter1_t> rng1, range<Iter2_t> rbuf,
|
||||
//-------------------------------------------------------------------------
|
||||
range<Iter2_t> rbx(rbuf);
|
||||
range<Iter1_t> rx1(rng1), rx2(rng2);
|
||||
assert(rbx.size() == rx1.size() and rx1.size() == rx2.size());
|
||||
assert(rbx.size() == rx1.size() && rx1.size() == rx2.size());
|
||||
while (rx1.first != rx1.last)
|
||||
{
|
||||
*(rx1.first++) = (cmp(*rbx.first, *rx2.first)) ?
|
||||
@@ -390,12 +399,12 @@ static void merge_flow(range<Iter1_t> rng1, range<Iter2_t> rbuf,
|
||||
if (rx2.first == rx2.last) return;
|
||||
if (rbx.first == rbx.last) move_forward(rbuf, rng2);
|
||||
else merge_half(rbuf, rx2, rbx, cmp);
|
||||
};
|
||||
}
|
||||
|
||||
//****************************************************************************
|
||||
};// End namespace common
|
||||
};// End namespace sort
|
||||
};// End namespace boost
|
||||
}// End namespace common
|
||||
}// End namespace sort
|
||||
}// End namespace boost
|
||||
//****************************************************************************
|
||||
//
|
||||
#endif
|
||||
|
||||
@@ -13,7 +13,6 @@
|
||||
#ifndef __BOOST_SORT_COMMON_REARRANGE_HPP
|
||||
#define __BOOST_SORT_COMMON_REARRANGE_HPP
|
||||
|
||||
#include <ciso646>
|
||||
#include <functional>
|
||||
#include <iterator>
|
||||
#include <type_traits>
|
||||
@@ -83,7 +82,7 @@ void rearrange(Iter_data global_first, Iter_index itx_first,
|
||||
pos_ini = 0;
|
||||
while (pos_ini < nelem)
|
||||
{
|
||||
while (pos_ini < nelem and pos(index[pos_ini]) == pos_ini)
|
||||
while (pos_ini < nelem && pos(index[pos_ini]) == pos_ini)
|
||||
++pos_ini;
|
||||
if (pos_ini == nelem) return;
|
||||
pos_dest = pos_src = pos_ini;
|
||||
@@ -102,7 +101,7 @@ void rearrange(Iter_data global_first, Iter_index itx_first,
|
||||
index[pos_ini] = std::move(itx_src);
|
||||
++pos_ini;
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
/*
|
||||
//
|
||||
@@ -162,9 +161,9 @@ void rearrange(Iter_data global_first, Iter_index itx_first,
|
||||
*/
|
||||
//
|
||||
//****************************************************************************
|
||||
};// End namespace common
|
||||
};// End namespace sort
|
||||
};// End namespace boost
|
||||
}// End namespace common
|
||||
}// End namespace sort
|
||||
}// End namespace boost
|
||||
//****************************************************************************
|
||||
//
|
||||
#endif
|
||||
|
||||
@@ -13,7 +13,6 @@
|
||||
#ifndef __BOOST_SORT_COMMON_SORT_BASIC_HPP
|
||||
#define __BOOST_SORT_COMMON_SORT_BASIC_HPP
|
||||
|
||||
#include <ciso646>
|
||||
#include <cstdlib>
|
||||
#include <functional>
|
||||
#include <iterator>
|
||||
@@ -56,7 +55,7 @@ inline Iter_t is_stable_sorted_forward (Iter_t first, Iter_t last,
|
||||
#endif
|
||||
if ((last - first) < 2) return first;
|
||||
Iter_t it2 = first + 1;
|
||||
for (Iter_t it1 = first; it2 != last and not comp(*it2, *it1); it1 = it2++);
|
||||
for (Iter_t it1 = first; it2 != last && ! comp(*it2, *it1); it1 = it2++);
|
||||
return it2;
|
||||
}
|
||||
//-----------------------------------------------------------------------------
|
||||
@@ -79,9 +78,9 @@ inline Iter_t is_reverse_stable_sorted_forward(Iter_t first, Iter_t last,
|
||||
#endif
|
||||
if ((last - first) < 2) return first;
|
||||
Iter_t it2 = first + 1;
|
||||
for (Iter_t it1 = first; it2 != last and comp(*it2, *it1); it1 = it2++);
|
||||
for (Iter_t it1 = first; it2 != last && comp(*it2, *it1); it1 = it2++);
|
||||
return it2;
|
||||
};
|
||||
}
|
||||
//-----------------------------------------------------------------------------
|
||||
// function : number_stable_sorted_forward
|
||||
/// @brief examine the elements in the range first, last if they are stable
|
||||
@@ -105,20 +104,20 @@ size_t number_stable_sorted_forward (Iter_t first, Iter_t last,
|
||||
|
||||
// sorted elements
|
||||
Iter_t it2 = first + 1;
|
||||
for (Iter_t it1 = first; it2 != last and not comp(*it2, *it1); it1 = it2++);
|
||||
for (Iter_t it1 = first; it2 != last && ! comp(*it2, *it1); it1 = it2++);
|
||||
size_t nsorted = size_t ( it2 - first);
|
||||
if ( nsorted != 1)
|
||||
return (nsorted >= min_process) ? nsorted: 0;
|
||||
|
||||
// reverse sorted elements
|
||||
it2 = first + 1;
|
||||
for (Iter_t it1 = first; it2 != last and comp(*it2, *it1); it1 = it2++);
|
||||
for (Iter_t it1 = first; it2 != last && comp(*it2, *it1); it1 = it2++);
|
||||
nsorted = size_t ( it2 - first);
|
||||
|
||||
if ( nsorted < min_process) return 0 ;
|
||||
util::reverse ( first , it2);
|
||||
return nsorted;
|
||||
};
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// function : is_stable_sorted_backward
|
||||
@@ -140,7 +139,7 @@ inline Iter_t is_stable_sorted_backward(Iter_t first, Iter_t last,
|
||||
#endif
|
||||
if ((last - first) < 2) return first;
|
||||
Iter_t itaux = last - 1;
|
||||
while (itaux != first and not comp(*itaux, *(itaux - 1))) {--itaux; };
|
||||
while (itaux != first && ! comp(*itaux, *(itaux - 1))) {--itaux; };
|
||||
return itaux;
|
||||
}
|
||||
//-----------------------------------------------------------------------------
|
||||
@@ -163,7 +162,7 @@ inline Iter_t is_reverse_stable_sorted_backward (Iter_t first, Iter_t last,
|
||||
#endif
|
||||
if ((last - first) < 2) return first;
|
||||
Iter_t itaux = last - 1;
|
||||
for (; itaux != first and comp(*itaux, *(itaux - 1)); --itaux);
|
||||
for (; itaux != first && comp(*itaux, *(itaux - 1)); --itaux);
|
||||
return itaux;
|
||||
}
|
||||
|
||||
@@ -188,13 +187,13 @@ size_t number_stable_sorted_backward (Iter_t first, Iter_t last,
|
||||
#endif
|
||||
if ((last - first) < 2) return 0;
|
||||
Iter_t itaux = last - 1;
|
||||
while (itaux != first and not comp(*itaux, *(itaux - 1))) {--itaux; };
|
||||
while (itaux != first && ! comp(*itaux, *(itaux - 1))) {--itaux; };
|
||||
size_t nsorted = size_t ( last - itaux);
|
||||
if ( nsorted != 1)
|
||||
return ( nsorted >= min_process)?nsorted: 0 ;
|
||||
|
||||
itaux = last - 1;
|
||||
for (; itaux != first and comp(*itaux, *(itaux - 1)); --itaux);
|
||||
for (; itaux != first && comp(*itaux, *(itaux - 1)); --itaux);
|
||||
nsorted = size_t ( last - itaux);
|
||||
if ( nsorted < min_process) return 0 ;
|
||||
util::reverse ( itaux, last );
|
||||
@@ -238,7 +237,7 @@ inline void internal_sort (const range<Iter1_t> &rng1,
|
||||
range<Iter2_t> rng2_left(rng2.first, rng2.first + nelem),
|
||||
rng2_right(rng2.first + nelem, rng2.last);
|
||||
|
||||
if (nelem <= 32 and (level & 1) == even)
|
||||
if (nelem <= 32 && (level & 1) == even)
|
||||
{
|
||||
insert_sort(rng1_left.first, rng1_left.last, comp);
|
||||
insert_sort(rng1_right.first, rng1_right.last, comp);
|
||||
@@ -249,7 +248,7 @@ inline void internal_sort (const range<Iter1_t> &rng1,
|
||||
internal_sort(rng2_right, rng1_right, comp, level + 1, even);
|
||||
};
|
||||
merge(rng2, rng1_left, rng1_right, comp);
|
||||
};
|
||||
}
|
||||
//-----------------------------------------------------------------------------
|
||||
// function : range_sort_data
|
||||
/// @brief this sort elements using the range_sort function and receiving a
|
||||
@@ -286,7 +285,7 @@ static void range_sort_data (const range<Iter1_t> & rng_data,
|
||||
};
|
||||
|
||||
internal_sort(rng_aux, rng_data, comp, 0, true);
|
||||
};
|
||||
}
|
||||
//-----------------------------------------------------------------------------
|
||||
// function : range_sort_buffer
|
||||
/// @brief this sort elements using the range_sort function and receiving a
|
||||
@@ -324,11 +323,11 @@ static void range_sort_buffer(const range<Iter1_t> & rng_data,
|
||||
};
|
||||
|
||||
internal_sort(rng_data, rng_aux, comp, 0, false);
|
||||
};
|
||||
}
|
||||
//****************************************************************************
|
||||
};// End namespace common
|
||||
};// End namespace sort
|
||||
};// End namepspace boost
|
||||
}// End namespace common
|
||||
}// End namespace sort
|
||||
}// End namepspace boost
|
||||
//****************************************************************************
|
||||
//
|
||||
#endif
|
||||
|
||||
@@ -48,7 +48,7 @@ class spinlock_t
|
||||
/// @brief class constructor
|
||||
/// @param [in]
|
||||
//-------------------------------------------------------------------------
|
||||
explicit spinlock_t ( ) noexcept { af.clear ( ); };
|
||||
explicit spinlock_t ( ) noexcept { af.clear ( ); }
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
// function : lock
|
||||
@@ -59,8 +59,8 @@ class spinlock_t
|
||||
while (af.test_and_set (std::memory_order_acquire))
|
||||
{
|
||||
std::this_thread::yield ( );
|
||||
};
|
||||
};
|
||||
}
|
||||
}
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
// function : try_lock
|
||||
@@ -71,19 +71,19 @@ class spinlock_t
|
||||
bool try_lock ( ) noexcept
|
||||
{
|
||||
return !af.test_and_set (std::memory_order_acquire);
|
||||
};
|
||||
}
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
// function : unlock
|
||||
/// @brief unlock the spinlock_t
|
||||
//-------------------------------------------------------------------------
|
||||
void unlock ( ) noexcept { af.clear (std::memory_order_release); };
|
||||
void unlock ( ) noexcept { af.clear (std::memory_order_release); }
|
||||
|
||||
}; // E N D C L A S S S P I N L O C K
|
||||
//
|
||||
//***************************************************************************
|
||||
}; // end namespace common
|
||||
}; // end namespace sort
|
||||
}; // end namespace boost
|
||||
} // end namespace common
|
||||
} // end namespace sort
|
||||
} // end namespace boost
|
||||
//***************************************************************************
|
||||
#endif
|
||||
|
||||
@@ -73,7 +73,7 @@ public:
|
||||
// function : stack_cnc
|
||||
/// @brief constructor
|
||||
//-------------------------------------------------------------------------
|
||||
explicit stack_cnc(void): v_t() { };
|
||||
explicit stack_cnc(void): v_t() { }
|
||||
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
@@ -86,7 +86,7 @@ public:
|
||||
// function : ~stack_cnc
|
||||
/// @brief Destructor
|
||||
//-------------------------------------------------------------------------
|
||||
virtual ~stack_cnc(void) { v_t.clear(); };
|
||||
virtual ~stack_cnc(void) { v_t.clear(); }
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
// function : emplace_back
|
||||
@@ -137,8 +137,8 @@ public:
|
||||
// end class stack_cnc
|
||||
|
||||
//***************************************************************************
|
||||
};// end namespace common
|
||||
};// end namespace sort
|
||||
};// end namespace boost
|
||||
} // end namespace common
|
||||
} // end namespace sort
|
||||
} // end namespace boost
|
||||
//***************************************************************************
|
||||
#endif
|
||||
|
||||
@@ -144,7 +144,7 @@ template <class Value_t, class ... Args>
|
||||
inline void construct_object (Value_t *ptr, Args &&... args)
|
||||
{
|
||||
(::new (static_cast<void *>(ptr)) Value_t(std::forward< Args > (args)...));
|
||||
};
|
||||
}
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
// function : destroy_object
|
||||
@@ -155,7 +155,7 @@ template<class Value_t>
|
||||
inline void destroy_object(Value_t *ptr)
|
||||
{
|
||||
ptr->~Value_t();
|
||||
};
|
||||
}
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
// function : initialize
|
||||
@@ -185,9 +185,9 @@ inline void initialize (Iter_t first, Iter_t last, Value_t & val)
|
||||
while (it2 != last)
|
||||
{
|
||||
construct_object(&(*(it2++)), std::move(*(it1++)));
|
||||
};
|
||||
}
|
||||
val = std::move(*(last - 1));
|
||||
};
|
||||
}
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
// function : move_forward
|
||||
@@ -216,8 +216,8 @@ inline Iter2_t move_forward (Iter2_t it_dest, Iter1_t first, Iter1_t last)
|
||||
{ *it_dest++ = std::move(*first++);
|
||||
}
|
||||
return it_dest;
|
||||
}
|
||||
|
||||
};
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
// function : move_backard
|
||||
@@ -244,7 +244,7 @@ inline Iter2_t move_backward(Iter2_t it_dest, Iter1_t first, Iter1_t last)
|
||||
{ *(--it_dest) = std::move (*(--last));
|
||||
}
|
||||
return it_dest;
|
||||
};
|
||||
}
|
||||
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
@@ -271,9 +271,9 @@ inline Value_t * move_construct(Value_t *ptr, Iter_t first, Iter_t last)
|
||||
while (first != last)
|
||||
{
|
||||
::new (static_cast<void *>(ptr++)) Value_t(std::move(*(first++)));
|
||||
};
|
||||
}
|
||||
return ptr;
|
||||
};
|
||||
}
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
// function : destroy
|
||||
@@ -286,7 +286,7 @@ inline void destroy(Iter_t first, const Iter_t last)
|
||||
{
|
||||
while (first != last)
|
||||
destroy_object(&(*(first++)));
|
||||
};
|
||||
}
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
// function : reverse
|
||||
@@ -298,13 +298,13 @@ template<class Iter_t>
|
||||
inline void reverse(Iter_t first, Iter_t last)
|
||||
{
|
||||
std::reverse ( first, last);
|
||||
};
|
||||
}
|
||||
//
|
||||
//****************************************************************************
|
||||
};// End namespace util
|
||||
};// End namespace common
|
||||
};// End namespace sort
|
||||
};// End namespace boost
|
||||
} // End namespace util
|
||||
} // End namespace common
|
||||
} // End namespace sort
|
||||
} // End namespace boost
|
||||
//****************************************************************************
|
||||
//
|
||||
#endif
|
||||
|
||||
@@ -35,7 +35,7 @@ template<typename T>
|
||||
inline T atomic_read(std::atomic<T> &at_var)
|
||||
{
|
||||
return std::atomic_load_explicit < T > (&at_var, std::memory_order_acquire);
|
||||
};
|
||||
}
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
// function : atomic_add
|
||||
@@ -50,7 +50,7 @@ inline T atomic_add(std::atomic<T> &at_var, T2 num)
|
||||
static_assert (std::is_integral< T2 >::value, "Bad parameter");
|
||||
return std::atomic_fetch_add_explicit <T>
|
||||
(&at_var, (T) num, std::memory_order_acq_rel);
|
||||
};
|
||||
}
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
// function : atomic_sub
|
||||
@@ -65,7 +65,7 @@ inline T atomic_sub(std::atomic<T> &at_var, T2 num)
|
||||
static_assert (std::is_integral< T2 >::value, "Bad parameter");
|
||||
return std::atomic_fetch_sub_explicit <T>
|
||||
(&at_var, (T) num, std::memory_order_acq_rel);
|
||||
};
|
||||
}
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
// function : atomic_write
|
||||
@@ -79,21 +79,21 @@ inline void atomic_write(std::atomic<T> &at_var, T2 num)
|
||||
static_assert (std::is_integral< T2 >::value, "Bad parameter");
|
||||
std::atomic_store_explicit <T>
|
||||
(&at_var, (T) num, std::memory_order_release);
|
||||
};
|
||||
}
|
||||
template<typename T>
|
||||
struct counter_guard
|
||||
{
|
||||
typedef std::atomic<T> atomic_t;
|
||||
atomic_t &count;
|
||||
|
||||
counter_guard(atomic_t & counter): count(counter) { };
|
||||
~counter_guard() {atomic_sub(count, 1); };
|
||||
counter_guard(atomic_t & counter): count(counter) { }
|
||||
~counter_guard() {atomic_sub(count, 1); }
|
||||
};
|
||||
//
|
||||
//****************************************************************************
|
||||
};// End namespace util
|
||||
};// End namespace common
|
||||
};// End namespace sort
|
||||
};// End namespace boost
|
||||
} // End namespace util
|
||||
} // End namespace common
|
||||
} // End namespace sort
|
||||
} // End namespace boost
|
||||
//****************************************************************************
|
||||
#endif
|
||||
|
||||
@@ -73,7 +73,7 @@ struct circular_buffer
|
||||
{
|
||||
ptr = static_cast <Value_t*> (std::malloc (NMAX * sizeof(Value_t)));
|
||||
if (ptr == nullptr) throw std::bad_alloc();
|
||||
};
|
||||
}
|
||||
//
|
||||
//------------------------------------------------------------------------
|
||||
// function : ~circular_buffer
|
||||
@@ -84,7 +84,7 @@ struct circular_buffer
|
||||
if (initialized)
|
||||
{ for (size_t i = 0; i < NMAX; ++i) (ptr + i)->~Value_t();
|
||||
initialized = false;
|
||||
};
|
||||
}
|
||||
std::free(static_cast <void*> (ptr));
|
||||
}
|
||||
;
|
||||
@@ -103,61 +103,61 @@ struct circular_buffer
|
||||
::new (static_cast<void*>(ptr + i)) Value_t(std::move(ptr[i - 1]));
|
||||
val = std::move(ptr[NMAX - 1]);
|
||||
initialized = true;
|
||||
};
|
||||
}
|
||||
//
|
||||
//------------------------------------------------------------------------
|
||||
// function : destroy_all
|
||||
/// @brief : destroy all the objects in the internal memory
|
||||
//-----------------------------------------------------------------------
|
||||
void destroy_all(void) { destroy(ptr, ptr + NMAX); };
|
||||
void destroy_all(void) { destroy(ptr, ptr + NMAX); }
|
||||
//
|
||||
//------------------------------------------------------------------------
|
||||
// function : get_buffer
|
||||
/// @brief return the internal memory of the circular buffer
|
||||
/// @return pointer to the internal memory of the buffer
|
||||
//-----------------------------------------------------------------------
|
||||
Value_t * get_buffer(void) { return ptr; };
|
||||
Value_t * get_buffer(void) { return ptr; }
|
||||
//
|
||||
//------------------------------------------------------------------------
|
||||
// function : empty
|
||||
/// @brief return if the buffer is empty
|
||||
/// @return true : empty
|
||||
//-----------------------------------------------------------------------
|
||||
bool empty(void) const {return (nelem == 0); };
|
||||
bool empty(void) const {return (nelem == 0); }
|
||||
//
|
||||
//------------------------------------------------------------------------
|
||||
// function : full
|
||||
/// @brief return if the buffer is full
|
||||
/// @return true : full
|
||||
//-----------------------------------------------------------------------
|
||||
bool full(void) const { return (nelem == NMAX); };
|
||||
bool full(void) const { return (nelem == NMAX); }
|
||||
//
|
||||
//------------------------------------------------------------------------
|
||||
// function : size
|
||||
/// @brief return the number of elements stored in the buffer
|
||||
/// @return number of elements stored
|
||||
//-----------------------------------------------------------------------
|
||||
size_t size(void) const { return nelem;};
|
||||
size_t size(void) const { return nelem;}
|
||||
//
|
||||
//------------------------------------------------------------------------
|
||||
// function : capacity
|
||||
/// @brief : return the maximun capacity of the buffer
|
||||
/// @return number of elements
|
||||
//-----------------------------------------------------------------------
|
||||
size_t capacity(void) const { return NMAX;};
|
||||
size_t capacity(void) const { return NMAX;}
|
||||
//
|
||||
//------------------------------------------------------------------------
|
||||
// function : free_size
|
||||
/// @brief return the free positions in the buffer
|
||||
/// @return number of elements
|
||||
//-----------------------------------------------------------------------
|
||||
size_t free_size(void) const { return (NMAX - nelem); };
|
||||
size_t free_size(void) const { return (NMAX - nelem); }
|
||||
//
|
||||
//------------------------------------------------------------------------
|
||||
// function : clear
|
||||
/// @brief clear the buffer
|
||||
//-----------------------------------------------------------------------
|
||||
void clear(void) { nelem = first_pos = 0; };
|
||||
void clear(void) { nelem = first_pos = 0; }
|
||||
//
|
||||
//------------------------------------------------------------------------
|
||||
// function : front
|
||||
@@ -170,7 +170,7 @@ struct circular_buffer
|
||||
assert (nelem > 0);
|
||||
#endif
|
||||
return (ptr[first_pos]);
|
||||
};
|
||||
}
|
||||
//
|
||||
//------------------------------------------------------------------------
|
||||
// function :front
|
||||
@@ -183,7 +183,7 @@ struct circular_buffer
|
||||
assert ( nelem > 0 );
|
||||
#endif
|
||||
return (ptr[first_pos]);
|
||||
};
|
||||
}
|
||||
//
|
||||
//------------------------------------------------------------------------
|
||||
// function : back
|
||||
@@ -196,7 +196,7 @@ struct circular_buffer
|
||||
assert ( nelem > 0 );
|
||||
#endif
|
||||
return (ptr[(first_pos + nelem - 1) & MASK]);
|
||||
};
|
||||
}
|
||||
//
|
||||
//------------------------------------------------------------------------
|
||||
// function : back
|
||||
@@ -209,7 +209,7 @@ struct circular_buffer
|
||||
assert ( nelem > 0 );
|
||||
#endif
|
||||
return (ptr[(first_pos + nelem - 1) & MASK]);
|
||||
};
|
||||
}
|
||||
//
|
||||
//------------------------------------------------------------------------
|
||||
// function : operator []
|
||||
@@ -223,7 +223,7 @@ struct circular_buffer
|
||||
assert ( nelem > 0 );
|
||||
#endif
|
||||
return ptr[(first_pos + pos) & MASK];
|
||||
};
|
||||
}
|
||||
//
|
||||
//------------------------------------------------------------------------
|
||||
// function : operator []
|
||||
@@ -238,7 +238,7 @@ struct circular_buffer
|
||||
assert ( nelem > 0 );
|
||||
#endif
|
||||
return ptr[(first_pos + pos) & MASK];
|
||||
};
|
||||
}
|
||||
//
|
||||
//------------------------------------------------------------------------
|
||||
// function : push_front
|
||||
@@ -254,7 +254,7 @@ struct circular_buffer
|
||||
first_pos = ((first_pos + MASK) & MASK);
|
||||
ptr[first_pos] = val;
|
||||
|
||||
};
|
||||
}
|
||||
//
|
||||
//------------------------------------------------------------------------
|
||||
// function : push_front
|
||||
@@ -269,7 +269,7 @@ struct circular_buffer
|
||||
++nelem;
|
||||
first_pos = ((first_pos + MASK) & MASK);
|
||||
ptr[first_pos] = val;
|
||||
};
|
||||
}
|
||||
//
|
||||
//------------------------------------------------------------------------
|
||||
// function : push_back
|
||||
@@ -282,7 +282,7 @@ struct circular_buffer
|
||||
assert ( nelem != NMAX);
|
||||
#endif
|
||||
ptr[(first_pos + (nelem++)) & MASK] = val;
|
||||
};
|
||||
}
|
||||
//
|
||||
//------------------------------------------------------------------------
|
||||
// function : push_back
|
||||
@@ -295,7 +295,7 @@ struct circular_buffer
|
||||
assert ( nelem != NMAX);
|
||||
#endif
|
||||
ptr[(first_pos + (nelem++)) & MASK] = std::move(val);
|
||||
};
|
||||
}
|
||||
//
|
||||
//------------------------------------------------------------------------
|
||||
// function : pop_front
|
||||
@@ -308,7 +308,7 @@ struct circular_buffer
|
||||
#endif
|
||||
--nelem;
|
||||
(++first_pos) &= MASK;
|
||||
};
|
||||
}
|
||||
//
|
||||
//------------------------------------------------------------------------
|
||||
// function : pop_back
|
||||
@@ -320,7 +320,7 @@ struct circular_buffer
|
||||
assert ( nelem > 0 );
|
||||
#endif
|
||||
--nelem;
|
||||
};
|
||||
}
|
||||
|
||||
template<class iter_t>
|
||||
void pop_copy_front(iter_t it_dest, size_t num);
|
||||
@@ -380,9 +380,9 @@ void circular_buffer<Value_t, Power2>
|
||||
for (size_t i = 0; i < num; ++i)
|
||||
{
|
||||
*(it_dest++) = ptr[pos++ & MASK];
|
||||
};
|
||||
}
|
||||
first_pos &= MASK;
|
||||
};
|
||||
}
|
||||
//
|
||||
//------------------------------------------------------------------------
|
||||
// function : pop_move_front
|
||||
@@ -408,9 +408,9 @@ void circular_buffer<Value_t, Power2>
|
||||
for (size_t i = 0; i < num; ++i)
|
||||
{
|
||||
*(it_dest++) = std::move(ptr[pos++ & MASK]);
|
||||
};
|
||||
}
|
||||
first_pos &= MASK;
|
||||
};
|
||||
}
|
||||
//
|
||||
//------------------------------------------------------------------------
|
||||
// function : pop_copy_back
|
||||
@@ -434,8 +434,8 @@ void circular_buffer<Value_t, Power2>
|
||||
for (size_t i = 0; i < num; ++i)
|
||||
{
|
||||
*(it_dest++) = ptr[pos++ & MASK];
|
||||
};
|
||||
};
|
||||
}
|
||||
}
|
||||
//
|
||||
//------------------------------------------------------------------------
|
||||
// function : pop_move_back
|
||||
@@ -459,8 +459,8 @@ void circular_buffer<Value_t, Power2>
|
||||
for (size_t i = 0; i < num; ++i)
|
||||
{
|
||||
*(it_dest++) = std::move(ptr[pos++ & MASK]);
|
||||
};
|
||||
};
|
||||
}
|
||||
}
|
||||
//
|
||||
//------------------------------------------------------------------------
|
||||
// function : push_copy_front
|
||||
@@ -486,8 +486,8 @@ void circular_buffer<Value_t, Power2>
|
||||
for (size_t i = 0; i < num; ++i)
|
||||
{
|
||||
ptr[(pos++) & MASK] = *(it_src++);
|
||||
};
|
||||
};
|
||||
}
|
||||
}
|
||||
//
|
||||
//------------------------------------------------------------------------
|
||||
// function : push_move_front
|
||||
@@ -511,8 +511,8 @@ void circular_buffer<Value_t, Power2>
|
||||
for (size_t i = 0; i < num; ++i)
|
||||
{
|
||||
ptr[(pos++) & MASK] = std::move(*(it_src++));
|
||||
};
|
||||
};
|
||||
}
|
||||
}
|
||||
//
|
||||
//------------------------------------------------------------------------
|
||||
// function : push_copy_back
|
||||
@@ -536,8 +536,8 @@ void circular_buffer<Value_t, Power2>
|
||||
for (size_t i = 0; i < num; ++i)
|
||||
{
|
||||
ptr[(pos++) & MASK] = *(it_src++);
|
||||
};
|
||||
};
|
||||
}
|
||||
}
|
||||
//
|
||||
//------------------------------------------------------------------------
|
||||
// function : push_move_back
|
||||
@@ -561,13 +561,13 @@ void circular_buffer<Value_t, Power2>
|
||||
for (size_t i = 0; i < num; ++i)
|
||||
{
|
||||
ptr[(pos++) & MASK] = std::move(*(it_src++));
|
||||
};
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
//****************************************************************************
|
||||
};// End namespace util
|
||||
};// End namespace common
|
||||
};// End namespace sort
|
||||
};// End namespace boost
|
||||
} // End namespace util
|
||||
} // End namespace common
|
||||
} // End namespace sort
|
||||
} // End namespace boost
|
||||
//****************************************************************************
|
||||
#endif
|
||||
|
||||
@@ -91,8 +91,8 @@ static void insert_sorted(Iter1_t first, Iter1_t mid, Iter1_t last,
|
||||
mv_first = std::upper_bound(first, mv_last, it_aux[i - 1], comp);
|
||||
Iter1_t it1 = here::move_backward(mv_last + i, mv_first, mv_last);
|
||||
*(it1 - 1) = std::move(it_aux[i - 1]);
|
||||
};
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
template<class Iter1_t, class Iter2_t, typename Compare>
|
||||
static void insert_sorted_backward(Iter1_t first, Iter1_t mid, Iter1_t last,
|
||||
@@ -128,15 +128,15 @@ static void insert_sorted_backward(Iter1_t first, Iter1_t mid, Iter1_t last,
|
||||
mv_last = std::lower_bound(mv_first, last, it_aux[i], comp);
|
||||
Iter1_t it1 = move_forward(mv_first - (ndata - i), mv_first, mv_last);
|
||||
*(it1) = std::move(it_aux[i]);
|
||||
};
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
//
|
||||
//****************************************************************************
|
||||
};// End namespace util
|
||||
};// End namepspace common
|
||||
};// End namespace sort
|
||||
};// End namepspace boost
|
||||
} // End namespace util
|
||||
} // End namepspace common
|
||||
} // End namespace sort
|
||||
} // End namepspace boost
|
||||
//****************************************************************************
|
||||
//
|
||||
#endif
|
||||
|
||||
@@ -13,7 +13,6 @@
|
||||
#ifndef __BOOST_SORT_COMMON_UTIL_MERGE_HPP
|
||||
#define __BOOST_SORT_COMMON_UTIL_MERGE_HPP
|
||||
|
||||
#include <ciso646>
|
||||
#include <algorithm>
|
||||
#include <functional>
|
||||
#include <iterator>
|
||||
@@ -107,29 +106,29 @@ static Iter3_t merge(Iter1_t buf1, const Iter1_t end_buf1, Iter2_t buf2,
|
||||
if (buf1 == end_buf1) return move_forward(buf_out, buf2, end_buf2);
|
||||
if (buf2 == end_buf2) return move_forward(buf_out, buf1, end_buf1);
|
||||
|
||||
if (not comp(*buf2, *(end_buf1 - 1)))
|
||||
if (! comp(*buf2, *(end_buf1 - 1)))
|
||||
{
|
||||
Iter3_t mid = move_forward(buf_out, buf1, end_buf1);
|
||||
return move_forward(mid, buf2, end_buf2);
|
||||
};
|
||||
}
|
||||
|
||||
if (comp(*(end_buf2 - 1), *buf1))
|
||||
{
|
||||
Iter3_t mid = move_forward(buf_out, buf2, end_buf2);
|
||||
return move_forward(mid, buf1, end_buf1);
|
||||
};
|
||||
};
|
||||
while ((buf1 != end_buf1) and (buf2 != end_buf2))
|
||||
}
|
||||
}
|
||||
while ((buf1 != end_buf1) && (buf2 != end_buf2))
|
||||
{
|
||||
*(buf_out++) = (not comp(*buf2, *buf1)) ?
|
||||
*(buf_out++) = (! comp(*buf2, *buf1)) ?
|
||||
std::move(*(buf1++)) : std::move(*(buf2++));
|
||||
};
|
||||
}
|
||||
|
||||
return (buf1 == end_buf1) ?
|
||||
move_forward(buf_out, buf2, end_buf2) :
|
||||
move_forward(buf_out, buf1, end_buf1);
|
||||
}
|
||||
;
|
||||
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
// function : merge_construct
|
||||
@@ -168,29 +167,29 @@ static Value_t *merge_construct(Iter1_t first1, const Iter1_t last1,
|
||||
if (first1 == last1) return move_construct(it_out, first2, last2);
|
||||
if (first2 == last2) return move_construct(it_out, first1, last1);
|
||||
|
||||
if (not comp(*first2, *(last1 - 1)))
|
||||
if (! comp(*first2, *(last1 - 1)))
|
||||
{
|
||||
Value_t* mid = move_construct(it_out, first1, last1);
|
||||
return move_construct(mid, first2, last2);
|
||||
};
|
||||
}
|
||||
|
||||
if (comp(*(last2 - 1), *first1))
|
||||
{
|
||||
Value_t* mid = move_construct(it_out, first2, last2);
|
||||
return move_construct(mid, first1, last1);
|
||||
};
|
||||
};
|
||||
while (first1 != last1 and first2 != last2)
|
||||
}
|
||||
}
|
||||
while (first1 != last1 && first2 != last2)
|
||||
{
|
||||
construct_object((it_out++),
|
||||
(not comp(*first2, *first1)) ?
|
||||
(! comp(*first2, *first1)) ?
|
||||
std::move(*(first1++)) :
|
||||
std::move(*(first2++)));
|
||||
};
|
||||
}
|
||||
return (first1 == last1) ?
|
||||
move_construct(it_out, first2, last2) :
|
||||
move_construct(it_out, first1, last1);
|
||||
};
|
||||
}
|
||||
//
|
||||
//---------------------------------------------------------------------------
|
||||
// function : merge_half
|
||||
@@ -232,25 +231,25 @@ static Iter2_t merge_half(Iter1_t buf1, const Iter1_t end_buf1, Iter2_t buf2,
|
||||
if (buf1 == end_buf1) return end_buf2;
|
||||
if (buf2 == end_buf2) return move_forward(buf_out, buf1, end_buf1);
|
||||
|
||||
if (not comp(*buf2, *(end_buf1 - 1)))
|
||||
if (! comp(*buf2, *(end_buf1 - 1)))
|
||||
{
|
||||
move_forward(buf_out, buf1, end_buf1);
|
||||
return end_buf2;
|
||||
};
|
||||
}
|
||||
|
||||
if (comp(*(end_buf2 - 1), *buf1))
|
||||
{
|
||||
Iter2_t mid = move_forward(buf_out, buf2, end_buf2);
|
||||
return move_forward(mid, buf1, end_buf1);
|
||||
};
|
||||
};
|
||||
while ((buf1 != end_buf1) and (buf2 != end_buf2))
|
||||
}
|
||||
}
|
||||
while ((buf1 != end_buf1) && (buf2 != end_buf2))
|
||||
{
|
||||
*(buf_out++) = (not comp(*buf2, *buf1)) ?
|
||||
*(buf_out++) = (! comp(*buf2, *buf1)) ?
|
||||
std::move(*(buf1++)) : std::move(*(buf2++));
|
||||
};
|
||||
}
|
||||
return (buf2 == end_buf2)? move_forward(buf_out, buf1, end_buf1) : end_buf2;
|
||||
};
|
||||
}
|
||||
|
||||
//
|
||||
//---------------------------------------------------------------------------
|
||||
@@ -295,28 +294,28 @@ static Iter2_t merge_half_backward(Iter1_t buf1, Iter1_t end_buf1, Iter2_t buf2,
|
||||
if (buf1 == end_buf1)
|
||||
return here::move_backward(end_buf_out, buf2, end_buf2);
|
||||
|
||||
if (not comp(*buf2, *(end_buf1 - 1)))
|
||||
if (! comp(*buf2, *(end_buf1 - 1)))
|
||||
{
|
||||
here::move_backward(end_buf_out, buf2, end_buf2);
|
||||
return buf1;
|
||||
};
|
||||
}
|
||||
|
||||
if (comp(*(end_buf2 - 1), *buf1))
|
||||
{
|
||||
Iter1_t mid = here::move_backward(end_buf_out, buf1, end_buf1);
|
||||
return here::move_backward(mid, buf2, end_buf2);
|
||||
};
|
||||
};
|
||||
while ((buf1 != end_buf1) and (buf2 != end_buf2))
|
||||
}
|
||||
}
|
||||
while ((buf1 != end_buf1) && (buf2 != end_buf2))
|
||||
{
|
||||
*(--end_buf_out) =
|
||||
(not comp(*(end_buf2 - 1), *(end_buf1 - 1))) ?
|
||||
(! comp(*(end_buf2 - 1), *(end_buf1 - 1))) ?
|
||||
std::move(*(--end_buf2)):
|
||||
std::move(*(--end_buf1));
|
||||
};
|
||||
}
|
||||
return (buf1 == end_buf1) ?
|
||||
here::move_backward(end_buf_out, buf2, end_buf2) : buf1;
|
||||
};
|
||||
}
|
||||
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
@@ -352,19 +351,19 @@ static bool merge_uncontiguous(Iter1_t src1, const Iter1_t end_src1,
|
||||
//-------------------------------------------------------------------------
|
||||
// Code
|
||||
//-------------------------------------------------------------------------
|
||||
if (src1 == end_src1 or src2 == end_src2
|
||||
or not comp(*src2, *(end_src1 - 1))) return true;
|
||||
if (src1 == end_src1 || src2 == end_src2
|
||||
|| ! comp(*src2, *(end_src1 - 1))) return true;
|
||||
|
||||
while (src1 != end_src1 and not comp(*src2, *src1))
|
||||
while (src1 != end_src1 && ! comp(*src2, *src1))
|
||||
++src1;
|
||||
|
||||
Iter3_t const end_aux = aux + (end_src1 - src1);
|
||||
Iter2_t src2_first = src2;
|
||||
move_forward(aux, src1, end_src1);
|
||||
|
||||
while ((src1 != end_src1) and (src2 != end_src2))
|
||||
while ((src1 != end_src1) && (src2 != end_src2))
|
||||
{
|
||||
*(src1++) = std::move((not comp(*src2, *aux)) ? *(aux++) : *(src2++));
|
||||
*(src1++) = std::move((! comp(*src2, *aux)) ? *(aux++) : *(src2++));
|
||||
}
|
||||
|
||||
if (src2 == end_src2)
|
||||
@@ -376,9 +375,9 @@ static bool merge_uncontiguous(Iter1_t src1, const Iter1_t end_src1,
|
||||
else
|
||||
{
|
||||
merge_half(aux, end_aux, src2, end_src2, src2_first, comp);
|
||||
};
|
||||
}
|
||||
return false;
|
||||
};
|
||||
}
|
||||
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
@@ -409,11 +408,11 @@ static bool merge_contiguous(Iter1_t src1, Iter1_t src2, Iter1_t end_src2,
|
||||
//-------------------------------------------------------------------------
|
||||
// Code
|
||||
//-------------------------------------------------------------------------
|
||||
if (src1 == src2 or src2 == end_src2 or not comp(*src2, *(src2 - 1)))
|
||||
if (src1 == src2 || src2 == end_src2 || ! comp(*src2, *(src2 - 1)))
|
||||
return true;
|
||||
|
||||
Iter1_t end_src1 = src2;
|
||||
while (src1 != end_src1 and not comp(*src2, *src1))
|
||||
while (src1 != end_src1 && ! comp(*src2, *src1))
|
||||
++src1;
|
||||
|
||||
if (src1 == end_src1) return false;
|
||||
@@ -422,7 +421,7 @@ static bool merge_contiguous(Iter1_t src1, Iter1_t src2, Iter1_t end_src2,
|
||||
move_forward(buf, src1, end_src1);
|
||||
merge_half(buf, buf + nx, src2, end_src2, src1, comp);
|
||||
return false;
|
||||
};
|
||||
}
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
// function : merge_circular
|
||||
@@ -460,13 +459,13 @@ static bool merge_circular(Iter1_t buf1, Iter1_t end_buf1, Iter2_t buf2,
|
||||
assert ( circ.free_size() >= size_t ((end_buf1-buf1) + (end_buf2-buf2)));
|
||||
#endif
|
||||
|
||||
if (not comp(*buf2, *(end_buf1 - 1)))
|
||||
if (! comp(*buf2, *(end_buf1 - 1)))
|
||||
{
|
||||
circ.push_move_back(buf1, (end_buf1 - buf1));
|
||||
it1_out = end_buf1;
|
||||
it2_out = buf2;
|
||||
return true;
|
||||
};
|
||||
}
|
||||
if (comp(*(end_buf2 - 1), *buf1))
|
||||
{
|
||||
circ.push_move_back(buf2, (end_buf2 - buf2));
|
||||
@@ -474,22 +473,22 @@ static bool merge_circular(Iter1_t buf1, Iter1_t end_buf1, Iter2_t buf2,
|
||||
it2_out = end_buf2;
|
||||
return false;
|
||||
}
|
||||
while (buf1 != end_buf1 and buf2 != end_buf2)
|
||||
while (buf1 != end_buf1 && buf2 != end_buf2)
|
||||
{
|
||||
circ.push_back(comp(*buf2, *buf1) ? std::move(*(buf2++))
|
||||
: std::move(*(buf1++)));
|
||||
};
|
||||
}
|
||||
it2_out = buf2;
|
||||
it1_out = buf1;
|
||||
bool ret = (buf1 == end_buf1);
|
||||
return ret;
|
||||
};
|
||||
}
|
||||
//
|
||||
//****************************************************************************
|
||||
};// End namespace util
|
||||
};// End namespace common
|
||||
};// End namespace sort
|
||||
};// End namespace boost
|
||||
} // End namespace util
|
||||
} // End namespace common
|
||||
} // End namespace sort
|
||||
} // End namespace boost
|
||||
//****************************************************************************
|
||||
//
|
||||
#endif
|
||||
|
||||
@@ -30,7 +30,7 @@ struct filter_pass
|
||||
const key & operator()(const T & val) const
|
||||
{
|
||||
return val;
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
//
|
||||
@@ -79,9 +79,9 @@ inline Iter_t internal_find_first(Iter_t first, Iter_t last,
|
||||
if (comp(flt(*it_out), val))
|
||||
LI = it_out + 1;
|
||||
else LS = it_out;
|
||||
};
|
||||
}
|
||||
return LS;
|
||||
};
|
||||
}
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
// function : internal_find_last
|
||||
@@ -112,9 +112,9 @@ inline Iter_t internal_find_last(Iter_t first, Iter_t last,
|
||||
it_out = LI + ((LS - LI + 1) >> 1);
|
||||
if (comp(val, flt(*it_out))) LS = it_out - 1;
|
||||
else LI = it_out;
|
||||
};
|
||||
}
|
||||
return LS;
|
||||
};
|
||||
}
|
||||
|
||||
//
|
||||
//###########################################################################
|
||||
@@ -149,7 +149,7 @@ inline Iter_t find_first(Iter_t first, Iter_t last,
|
||||
if (first == last) return last;
|
||||
Iter_t LS = internal_find_first(first, last, val, comp, flt);
|
||||
return (comp(flt(*LS), val) or comp(val, flt(*LS))) ? last : LS;
|
||||
};
|
||||
}
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
// function : find_last
|
||||
@@ -174,7 +174,7 @@ inline Iter_t find_last(Iter_t first, Iter_t last,
|
||||
if (last == first) return last;
|
||||
Iter_t LS = internal_find_last(first, last, val, comp, flt);
|
||||
return (comp(flt(*LS), val) or comp(val, flt(*LS))) ? last : LS;
|
||||
};
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
// function : lower_bound
|
||||
@@ -196,7 +196,7 @@ inline Iter_t lower_bound(Iter_t first, Iter_t last,
|
||||
if (last == first) return last;
|
||||
Iter_t itaux = internal_find_first(first, last, val, comp, flt);
|
||||
return (itaux == (last - 1) and comp(flt(*itaux), val)) ? last : itaux;
|
||||
};
|
||||
}
|
||||
//----------------------------------------------------------------------------
|
||||
// function :upper_bound
|
||||
/// @brief return the first element greather than val.If don't exist
|
||||
@@ -242,7 +242,7 @@ inline std::pair<Iter_t, Iter_t> equal_range(Iter_t first, Iter_t last,
|
||||
{
|
||||
return std::make_pair(lower_bound(first, last, val, comp, flt),
|
||||
upper_bound(first, last, val, comp, flt));
|
||||
};
|
||||
}
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
// function : insert_first
|
||||
@@ -263,7 +263,7 @@ inline Iter_t insert_first(Iter_t first, Iter_t last,
|
||||
Filter())
|
||||
{
|
||||
return lower_bound(first, last, val, comp, flt);
|
||||
};
|
||||
}
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
// function : insert_last
|
||||
@@ -285,7 +285,7 @@ inline Iter_t insert_last(Iter_t first, Iter_t last,
|
||||
Filter())
|
||||
{
|
||||
return upper_bound(first, last, val, comp, flt);
|
||||
};
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -330,9 +330,9 @@ inline Iter_t insert_last(Iter_t first, Iter_t last,
|
||||
while ( LI != LS)
|
||||
{ it_out = LI + ( (LS - LI) >> 1);
|
||||
if ( comp ( *it_out, val)) LI = it_out + 1 ; else LS = it_out ;
|
||||
};
|
||||
}
|
||||
return LS ;
|
||||
};
|
||||
}
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
// function : internal_find_last
|
||||
@@ -359,9 +359,9 @@ inline Iter_t insert_last(Iter_t first, Iter_t last,
|
||||
while ( LI != LS)
|
||||
{ it_out = LI + ( (LS - LI + 1) >> 1);
|
||||
if ( comp (val, *it_out)) LS = it_out - 1 ; else LI = it_out ;
|
||||
};
|
||||
}
|
||||
return LS ;
|
||||
};
|
||||
}
|
||||
|
||||
//
|
||||
//###########################################################################
|
||||
@@ -394,7 +394,7 @@ inline Iter_t insert_last(Iter_t first, Iter_t last,
|
||||
if ( first == last) return last ;
|
||||
Iter_t LS = internal_find_first ( first, last, val, comp);
|
||||
return (comp (*LS, val) or comp (val, *LS))?last:LS;
|
||||
};
|
||||
}
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
// function : find_last
|
||||
@@ -417,7 +417,7 @@ inline Iter_t insert_last(Iter_t first, Iter_t last,
|
||||
if ( last == first ) return last ;
|
||||
Iter_t LS = internal_find_last (first, last, val, comp);
|
||||
return (comp (*LS, val) or comp (val, *LS))?last:LS ;
|
||||
};
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
// function : lower_bound
|
||||
@@ -437,7 +437,7 @@ inline Iter_t insert_last(Iter_t first, Iter_t last,
|
||||
if ( last == first ) return last ;
|
||||
Iter_t itaux = internal_find_first( first, last, val,comp);
|
||||
return (itaux == (last - 1) and comp (*itaux, val))?last: itaux;
|
||||
};
|
||||
}
|
||||
//----------------------------------------------------------------------------
|
||||
// function :upper_bound
|
||||
/// @brief return the first element greather than val.If don't exist
|
||||
@@ -459,7 +459,7 @@ inline Iter_t insert_last(Iter_t first, Iter_t last,
|
||||
if ( last == first ) return last ;
|
||||
Iter_t itaux = internal_find_last( first, last, val,comp);
|
||||
return ( itaux == first and comp (val,*itaux))? itaux: itaux + 1;
|
||||
};
|
||||
}
|
||||
//----------------------------------------------------------------------------
|
||||
// function :equal_range
|
||||
/// @brief return a pair of lower_bound and upper_bound with the value val.If
|
||||
@@ -478,7 +478,7 @@ inline Iter_t insert_last(Iter_t first, Iter_t last,
|
||||
{
|
||||
return std::make_pair(lower_bound(first, last, val,comp),
|
||||
upper_bound(first, last, val,comp));
|
||||
};
|
||||
}
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
// function : insert_first
|
||||
@@ -497,7 +497,7 @@ inline Iter_t insert_last(Iter_t first, Iter_t last,
|
||||
Compare comp = Compare() )
|
||||
{
|
||||
return lower_bound (first, last, val, comp);
|
||||
};
|
||||
}
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
// function : insert_last
|
||||
@@ -517,15 +517,15 @@ inline Iter_t insert_last(Iter_t first, Iter_t last,
|
||||
Compare comp = Compare())
|
||||
{
|
||||
return upper_bound (first, last, val, comp);
|
||||
};
|
||||
}
|
||||
|
||||
*/
|
||||
//
|
||||
//****************************************************************************
|
||||
};// End namespace util
|
||||
};// End namespace common
|
||||
};// End namespace sort
|
||||
};// End namespace boost
|
||||
} // End namespace util
|
||||
} // End namespace common
|
||||
} // End namespace sort
|
||||
} // End namespace boost
|
||||
//****************************************************************************
|
||||
//
|
||||
#endif
|
||||
|
||||
@@ -116,9 +116,9 @@ struct constructor
|
||||
};
|
||||
//
|
||||
//****************************************************************************
|
||||
};// End namespace util
|
||||
};// End namespace common
|
||||
};// End namespace sort
|
||||
};// End namespace boost
|
||||
} // End namespace util
|
||||
} // End namespace common
|
||||
} // End namespace sort
|
||||
} // End namespace boost
|
||||
//****************************************************************************
|
||||
#endif
|
||||
|
||||
@@ -13,7 +13,6 @@
|
||||
#ifndef __BOOST_SORT_FLAT_STABLE_SORT_HPP
|
||||
#define __BOOST_SORT_FLAT_STABLE_SORT_HPP
|
||||
|
||||
#include <ciso646>
|
||||
#include <cstdlib>
|
||||
#include <functional>
|
||||
#include <iterator>
|
||||
@@ -110,9 +109,10 @@ public:
|
||||
//----------------------------------------------------------------------------
|
||||
//
|
||||
//------------------------------------------------------------------------
|
||||
// function :
|
||||
/// @brief :
|
||||
/// @param Pos :
|
||||
// @fn divide
|
||||
/// @brief Divide a big list of blocks in two parts to be sorted and merged
|
||||
/// @param itx_first iterator to the first element in the index
|
||||
/// @param itx_last itarator to to the after the last element in the index
|
||||
/// @return
|
||||
//------------------------------------------------------------------------
|
||||
template <class Iter_t, typename Compare, uint32_t Power2>
|
||||
@@ -132,21 +132,20 @@ void flat_stable_sort <Iter_t, Compare, Power2>
|
||||
divide(itx_first, itx_first + nblock1);
|
||||
divide(itx_first + nblock1, itx_last);
|
||||
merge_range_pos(itx_first, itx_first + nblock1, itx_last);
|
||||
};
|
||||
}
|
||||
//
|
||||
//------------------------------------------------------------------------
|
||||
// function : sort_small
|
||||
/// @brief :
|
||||
/// @param
|
||||
/// @param
|
||||
/// @param
|
||||
// @fn sort_small
|
||||
/// @brief sort an small number of blocks
|
||||
/// @param itx_first iterator to the first element in the index
|
||||
/// @param itx_last itarator to to the after the last element in the index
|
||||
//------------------------------------------------------------------------
|
||||
template <class Iter_t, typename Compare, uint32_t Power2>
|
||||
void flat_stable_sort <Iter_t, Compare, Power2>
|
||||
::sort_small(it_index itx_first, it_index itx_last)
|
||||
{
|
||||
size_t nblock = size_t(itx_last - itx_first);
|
||||
assert(nblock > 0 and nblock < 5);
|
||||
assert(nblock > 0 && nblock < 5);
|
||||
value_t *paux = ptr_circ->get_buffer();
|
||||
range_it rng_data = get_group_range(*itx_first, nblock);
|
||||
|
||||
@@ -169,10 +168,10 @@ void flat_stable_sort <Iter_t, Compare, Power2>
|
||||
range_sort_data(rng_data2, rng_aux2, cmp);
|
||||
range_sort_buffer(rng_data1, rng_aux1, cmp);
|
||||
merge_half(rng_data, rng_aux1, rng_data2, cmp);
|
||||
};
|
||||
}
|
||||
//
|
||||
//------------------------------------------------------------------------
|
||||
// function : is_sorted_forward
|
||||
// @fn is_sorted_forward
|
||||
/// @brief : return if the data are ordered,
|
||||
/// @param itx_first : iterator to the first block in the index
|
||||
/// @param itx_last : iterator to the last block in the index
|
||||
@@ -210,10 +209,10 @@ bool flat_stable_sort <Iter_t, Compare, Power2>
|
||||
merge_range_pos(itx_first, itx_first + nblock1, itx_last);
|
||||
};
|
||||
return true;
|
||||
};
|
||||
}
|
||||
//
|
||||
//------------------------------------------------------------------------
|
||||
// function : is_sorted_backward
|
||||
// @fn is_sorted_backward
|
||||
/// @brief : return if the data are ordered,
|
||||
/// @param itx_first : iterator to the first block in the index
|
||||
/// @param itx_last : iterator to the last block in the index
|
||||
@@ -251,16 +250,16 @@ bool flat_stable_sort <Iter_t, Compare, Power2>
|
||||
merge_range_pos(itx_first, itx_first + nblock1, itx_last);
|
||||
};
|
||||
return true;
|
||||
};
|
||||
}
|
||||
//****************************************************************************
|
||||
};// End namespace flat_internal
|
||||
}// End namespace flat_internal
|
||||
//****************************************************************************
|
||||
//
|
||||
namespace bscu = boost::sort::common::util;
|
||||
namespace flat = boost::sort::flat_internal;
|
||||
//
|
||||
///---------------------------------------------------------------------------
|
||||
// function flat_stable_sort
|
||||
// @fn flat_stable_sort
|
||||
/// @brief This class is select the block size in the block_indirect_sort
|
||||
/// algorithm depending of the type and size of the data to sort
|
||||
///
|
||||
@@ -271,7 +270,7 @@ inline void flat_stable_sort (Iter_t first, Iter_t last,
|
||||
Compare cmp = Compare())
|
||||
{
|
||||
flat::flat_stable_sort<Iter_t, Compare, 6> (first, last, cmp);
|
||||
};
|
||||
}
|
||||
|
||||
template<size_t Size>
|
||||
struct block_size_fss
|
||||
@@ -285,7 +284,7 @@ struct block_size_fss
|
||||
|
||||
//
|
||||
///---------------------------------------------------------------------------
|
||||
// function flat_stable_sort
|
||||
// @fn flat_stable_sort
|
||||
/// @brief This class is select the block size in the flat_stable_sort
|
||||
/// algorithm depending of the type and size of the data to sort
|
||||
///
|
||||
@@ -298,7 +297,7 @@ inline void flat_stable_sort (Iter_t first, Iter_t last,
|
||||
flat::flat_stable_sort<Iter_t, Compare,
|
||||
block_size_fss<sizeof(value_iter<Iter_t> )>::data>
|
||||
(first, last, cmp);
|
||||
};
|
||||
}
|
||||
|
||||
template<class Iter_t, class Compare = compare_iter<Iter_t> >
|
||||
inline void indirect_flat_stable_sort (Iter_t first, Iter_t last,
|
||||
@@ -308,11 +307,11 @@ inline void indirect_flat_stable_sort (Iter_t first, Iter_t last,
|
||||
typedef common::less_ptr_no_null <Iter_t, Compare> itx_comp;
|
||||
common::indirect_sort ( flat_stable_sort<itx_iter, itx_comp>,
|
||||
first, last, comp);
|
||||
};
|
||||
}
|
||||
|
||||
//****************************************************************************
|
||||
};// End namespace sort
|
||||
};// End namepspace boost
|
||||
}// End namespace sort
|
||||
}// End namepspace boost
|
||||
//****************************************************************************
|
||||
//
|
||||
#endif
|
||||
|
||||
@@ -13,7 +13,6 @@
|
||||
#ifndef __BOOST_SORT_INTROSORT_DETAIL_INSERT_SORT_HPP
|
||||
#define __BOOST_SORT_INTROSORT_DETAIL_INSERT_SORT_HPP
|
||||
|
||||
#include <ciso646>
|
||||
#include <functional>
|
||||
#include <iterator>
|
||||
#include <algorithm>
|
||||
@@ -51,19 +50,19 @@ static void insert_sort (Iter_t first, Iter_t last,
|
||||
value_t Aux = std::move (*it_examine);
|
||||
Iter_t it_insertion = it_examine;
|
||||
|
||||
while (it_insertion != first and comp (Aux, *(it_insertion - 1)))
|
||||
while (it_insertion != first && comp (Aux, *(it_insertion - 1)))
|
||||
{
|
||||
*it_insertion = std::move (*(it_insertion - 1));
|
||||
--it_insertion;
|
||||
};
|
||||
*it_insertion = std::move (Aux);
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
//
|
||||
//****************************************************************************
|
||||
}; // End namespace sort
|
||||
}; // End namespace boost
|
||||
} // End namespace sort
|
||||
} // End namespace boost
|
||||
//****************************************************************************
|
||||
//
|
||||
#endif
|
||||
|
||||
@@ -200,11 +200,11 @@ parallel_stable_sort <Iter_t, Compare>
|
||||
|
||||
|
||||
|
||||
}; // end of constructor
|
||||
} // end of constructor
|
||||
|
||||
//
|
||||
//****************************************************************************
|
||||
};// End namespace stable_detail
|
||||
}// End namespace stable_detail
|
||||
//****************************************************************************
|
||||
//
|
||||
|
||||
@@ -237,7 +237,7 @@ void parallel_stable_sort(Iter_t first, Iter_t last)
|
||||
{
|
||||
typedef bscu::compare_iter<Iter_t> Compare;
|
||||
stable_detail::parallel_stable_sort<Iter_t, Compare>(first, last);
|
||||
};
|
||||
}
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
// function : parallel_stable_sort
|
||||
@@ -254,7 +254,7 @@ void parallel_stable_sort(Iter_t first, Iter_t last, uint32_t nthread)
|
||||
{
|
||||
typedef bscu::compare_iter<Iter_t> Compare;
|
||||
stable_detail::parallel_stable_sort<Iter_t, Compare>(first, last, nthread);
|
||||
};
|
||||
}
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
// function : parallel_stable_sort
|
||||
@@ -271,7 +271,7 @@ template <class Iter_t, class Compare,
|
||||
void parallel_stable_sort(Iter_t first, Iter_t last, Compare comp)
|
||||
{
|
||||
stable_detail::parallel_stable_sort<Iter_t, Compare>(first, last, comp);
|
||||
};
|
||||
}
|
||||
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
@@ -294,8 +294,8 @@ void parallel_stable_sort (Iter_t first, Iter_t last, Compare comp,
|
||||
}
|
||||
//
|
||||
//****************************************************************************
|
||||
};// End namespace sort
|
||||
};// End namespace boost
|
||||
}// End namespace sort
|
||||
}// End namespace boost
|
||||
//****************************************************************************
|
||||
//
|
||||
#endif
|
||||
|
||||
@@ -124,22 +124,22 @@ struct sample_sort
|
||||
|
||||
sample_sort(Iter_t first, Iter_t last)
|
||||
: sample_sort (first, last, Compare(), std::thread::hardware_concurrency(),
|
||||
nullptr, 0) { };
|
||||
nullptr, 0) { }
|
||||
|
||||
sample_sort(Iter_t first, Iter_t last, Compare cmp)
|
||||
: sample_sort(first, last, cmp, std::thread::hardware_concurrency(),
|
||||
nullptr, 0) { };
|
||||
nullptr, 0) { }
|
||||
|
||||
sample_sort(Iter_t first, Iter_t last, uint32_t num_thread)
|
||||
: sample_sort(first, last, Compare(), num_thread, nullptr, 0) { };
|
||||
: sample_sort(first, last, Compare(), num_thread, nullptr, 0) { }
|
||||
|
||||
sample_sort(Iter_t first, Iter_t last, Compare cmp, uint32_t num_thread)
|
||||
: sample_sort(first, last, cmp, num_thread, nullptr, 0) { };
|
||||
: sample_sort(first, last, cmp, num_thread, nullptr, 0) { }
|
||||
|
||||
sample_sort(Iter_t first, Iter_t last, Compare cmp, uint32_t num_thread,
|
||||
range_buf range_buf_initial)
|
||||
: sample_sort(first, last, cmp, num_thread,
|
||||
range_buf_initial.first, range_buf_initial.size()) { };
|
||||
range_buf_initial.first, range_buf_initial.size()) { }
|
||||
|
||||
void destroy_all(void);
|
||||
//
|
||||
@@ -148,7 +148,7 @@ struct sample_sort
|
||||
/// @brief destructor of the class. The utility is to destroy the temporary
|
||||
/// buffer used in the sorting process
|
||||
//-----------------------------------------------------------------------------
|
||||
~sample_sort(void) { destroy_all(); };
|
||||
~sample_sort(void) { destroy_all(); }
|
||||
//
|
||||
//-----------------------------------------------------------------------
|
||||
// function : execute first
|
||||
@@ -161,8 +161,8 @@ struct sample_sort
|
||||
{
|
||||
uninit_merge_level4(vrange_buf_ini[job], vv_range_it[job],
|
||||
vv_range_buf[job], comp);
|
||||
};
|
||||
};
|
||||
}
|
||||
}
|
||||
//
|
||||
//-----------------------------------------------------------------------
|
||||
// function : execute
|
||||
@@ -175,8 +175,8 @@ struct sample_sort
|
||||
{
|
||||
merge_vector4(vrange_buf_ini[job], vrange_it_ini[job],
|
||||
vv_range_buf[job], vv_range_it[job], comp);
|
||||
};
|
||||
};
|
||||
}
|
||||
}
|
||||
//
|
||||
//-----------------------------------------------------------------------
|
||||
// function : first merge
|
||||
@@ -193,7 +193,7 @@ struct sample_sort
|
||||
};
|
||||
for (uint32_t i = 0; i < nthread; ++i)
|
||||
vfuture[i].get();
|
||||
};
|
||||
}
|
||||
//
|
||||
//-----------------------------------------------------------------------
|
||||
// function : final merge
|
||||
@@ -206,10 +206,10 @@ struct sample_sort
|
||||
for (uint32_t i = 0; i < nthread; ++i)
|
||||
{
|
||||
vfuture[i] = std::async(std::launch::async, &this_t::execute, this);
|
||||
};
|
||||
}
|
||||
for (uint32_t i = 0; i < nthread; ++i)
|
||||
vfuture[i].get();
|
||||
};
|
||||
}
|
||||
//----------------------------------------------------------------------------
|
||||
};
|
||||
// End class sample_sort
|
||||
@@ -259,7 +259,7 @@ sample_sort<Iter_t, Compare>
|
||||
{
|
||||
bss::spinsort<Iter_t, Compare>(first, last, comp);
|
||||
return;
|
||||
};
|
||||
}
|
||||
|
||||
//------------------- check if sort --------------------------------------
|
||||
bool sw = true;
|
||||
@@ -279,7 +279,7 @@ sample_sort<Iter_t, Compare>
|
||||
for (size_t i = 0; i < nelem2; ++i)
|
||||
swap(*(it1++), *(it2--));
|
||||
return;
|
||||
};
|
||||
}
|
||||
|
||||
if (paux != nullptr)
|
||||
{
|
||||
@@ -296,7 +296,7 @@ sample_sort<Iter_t, Compare>
|
||||
if (ptr == nullptr) throw std::bad_alloc();
|
||||
owner = true;
|
||||
global_buf = range_buf(ptr, ptr + nelem);
|
||||
};
|
||||
}
|
||||
//------------------------------------------------------------------------
|
||||
// PROCESS
|
||||
//------------------------------------------------------------------------
|
||||
@@ -306,20 +306,20 @@ sample_sort<Iter_t, Compare>
|
||||
} catch (std::bad_alloc &)
|
||||
{
|
||||
error = true;
|
||||
};
|
||||
}
|
||||
if (not error)
|
||||
{
|
||||
first_merge();
|
||||
construct = true;
|
||||
final_merge();
|
||||
};
|
||||
}
|
||||
if (error)
|
||||
{
|
||||
destroy_all();
|
||||
throw std::bad_alloc();
|
||||
};
|
||||
}
|
||||
}
|
||||
;
|
||||
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
// function : destroy_all
|
||||
@@ -464,22 +464,22 @@ void sample_sort<Iter_t, Compare>::initial_configuration(void)
|
||||
if (nelem_range != 0)
|
||||
{
|
||||
vv_range_it[k].push_back(vv_range_first[i][k]);
|
||||
};
|
||||
}
|
||||
nelem_interval += nelem_range;
|
||||
};
|
||||
}
|
||||
|
||||
vrange_it_ini.emplace_back(it, it + nelem_interval);
|
||||
vrange_buf_ini.emplace_back(it_buf, it_buf + nelem_interval);
|
||||
|
||||
it += nelem_interval;
|
||||
it_buf += nelem_interval;
|
||||
};
|
||||
}
|
||||
}
|
||||
;
|
||||
|
||||
//
|
||||
//****************************************************************************
|
||||
}
|
||||
;
|
||||
|
||||
// End namespace sample_detail
|
||||
//****************************************************************************
|
||||
//
|
||||
@@ -505,7 +505,7 @@ void sample_sort(Iter_t first, Iter_t last)
|
||||
{
|
||||
typedef compare_iter<Iter_t> Compare;
|
||||
sample_detail::sample_sort<Iter_t, Compare>(first, last);
|
||||
};
|
||||
}
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
// function : sample_sort
|
||||
@@ -521,7 +521,7 @@ void sample_sort(Iter_t first, Iter_t last, uint32_t nthread)
|
||||
{
|
||||
typedef compare_iter<Iter_t> Compare;
|
||||
sample_detail::sample_sort<Iter_t, Compare>(first, last, nthread);
|
||||
};
|
||||
}
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
// function : sample_sort
|
||||
@@ -537,7 +537,7 @@ template<class Iter_t, class Compare, bscu::enable_if_not_integral<Compare> * =
|
||||
void sample_sort(Iter_t first, Iter_t last, Compare comp)
|
||||
{
|
||||
sample_detail::sample_sort<Iter_t, Compare>(first, last, comp);
|
||||
};
|
||||
}
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
// function : sample_sort
|
||||
@@ -554,11 +554,11 @@ template<class Iter_t, class Compare>
|
||||
void sample_sort(Iter_t first, Iter_t last, Compare comp, uint32_t nthread)
|
||||
{
|
||||
sample_detail::sample_sort<Iter_t, Compare>(first, last, comp, nthread);
|
||||
};
|
||||
}
|
||||
//
|
||||
//****************************************************************************
|
||||
};// End namespace sort
|
||||
};// End namespace boost
|
||||
}// End namespace sort
|
||||
}// End namespace boost
|
||||
//****************************************************************************
|
||||
//
|
||||
#endif
|
||||
|
||||
@@ -134,7 +134,7 @@ static void insert_partial_sort (Iter1_t first, Iter1_t mid, Iter1_t last,
|
||||
*(viter[i - 1] + (i - 1)) = std::move(*(data + (i - 1)));
|
||||
};
|
||||
}
|
||||
;
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// function : check_stable_sort
|
||||
/// @brief check if the elements between first and last are osted or reverse
|
||||
@@ -222,7 +222,7 @@ static bool check_stable_sort(const range<Iter1_t> &rng_data,
|
||||
};
|
||||
return true;
|
||||
}
|
||||
;
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// function : range_sort
|
||||
/// @brief this function divide r_input in two parts, sort it,and merge moving
|
||||
@@ -297,7 +297,7 @@ static void range_sort(const range<Iter1_t> &range1,
|
||||
|
||||
merge(range2, range_input1, range_input2, comp);
|
||||
}
|
||||
;
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// function : sort_range_sort
|
||||
/// @brief this sort elements using the range_sort function and receiving a
|
||||
@@ -349,7 +349,7 @@ static void sort_range_sort(const range<Iter1_t> &rng_data,
|
||||
move_forward(rng_data, rng_buffer);
|
||||
};
|
||||
}
|
||||
;
|
||||
|
||||
//
|
||||
//############################################################################
|
||||
// ##
|
||||
@@ -423,6 +423,7 @@ public:
|
||||
if (owner and ptr != nullptr) std::free (ptr);
|
||||
};
|
||||
};
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
// End of class spinsort
|
||||
//----------------------------------------------------------------------------
|
||||
@@ -532,10 +533,10 @@ spinsort <Iter_t, Compare>
|
||||
range_sort(range_1, range_2, comp, nlevel);
|
||||
merge_half(range_input, range_aux, range_2, comp);
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
//****************************************************************************
|
||||
};// End namepspace spin_detail
|
||||
}// End namepspace spin_detail
|
||||
//****************************************************************************
|
||||
//
|
||||
namespace bsc = boost::sort::common;
|
||||
@@ -552,7 +553,7 @@ template <class Iter_t, class Compare = compare_iter<Iter_t>>
|
||||
inline void spinsort (Iter_t first, Iter_t last, Compare comp = Compare())
|
||||
{
|
||||
spin_detail::spinsort <Iter_t, Compare> (first, last, comp);
|
||||
};
|
||||
}
|
||||
|
||||
template <class Iter_t, class Compare = compare_iter<Iter_t>>
|
||||
inline void indirect_spinsort (Iter_t first, Iter_t last,
|
||||
@@ -561,11 +562,11 @@ inline void indirect_spinsort (Iter_t first, Iter_t last,
|
||||
typedef typename std::vector<Iter_t>::iterator itx_iter;
|
||||
typedef common::less_ptr_no_null <Iter_t, Compare> itx_comp;
|
||||
common::indirect_sort (spinsort<itx_iter, itx_comp>, first, last, comp);
|
||||
};
|
||||
}
|
||||
|
||||
//****************************************************************************
|
||||
};// End namespace sort
|
||||
};// End namepspace boost
|
||||
}// End namespace sort
|
||||
}// End namepspace boost
|
||||
//****************************************************************************
|
||||
//
|
||||
#endif
|
||||
|
||||
@@ -7,9 +7,14 @@
|
||||
#
|
||||
# See http://www.boost.org/libs/sort for library home page.
|
||||
|
||||
import ../../config/checks/config : requires ;
|
||||
import-search /boost/config/checks ;
|
||||
import config : requires ;
|
||||
import testing ;
|
||||
|
||||
project : requirements
|
||||
<library>/boost/test//boost_test_exec_monitor
|
||||
;
|
||||
|
||||
{
|
||||
test-suite "sort"
|
||||
: [ run integer_sort_test.cpp
|
||||
|
||||
Reference in New Issue
Block a user