spreadsort.hpp
Go to the documentation of this file.
// Templated generic hybrid sorting
// Copyright Steven J. Ross 2001 - 2009.
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
// See http://www.boost.org/libs/sort/ for library home page.
/*
Some improvements suggested by:
Phil Endecott and Frank Gennari
float_mem_cast fix provided by:
Scott McMurray
*/
#ifndef BOOST_SORT_SPREADSORT_HPP
#define BOOST_SORT_SPREADSORT_HPP
#include <algorithm>
#include <vector>
#include <cstring>
#include <string>
#include <limits>
#include <boost/type_traits.hpp>
#include <boost/sort/spreadsort/integer_sort.hpp>
#include <boost/sort/spreadsort/float_sort.hpp>
#include <boost/sort/spreadsort/string_sort.hpp>
namespace boost {
/*! Namespace for spreadsort sort variants for different data types.
\note Use hyperlinks (coloured) to get detailed information about functions.
*/
namespace sort {
/*!
\brief Generic @c spreadsort variant detecting integer-type elements so call to @c integer_sort.
\details If the data type provided is an integer, @c integer_sort is used.
\note Sorting other data types requires picking between @c integer_sort, @c float_sort and @c string_sort directly,
as @c spreadsort won't accept types that don't have the appropriate @c type_traits.
\tparam RandomAccessIter <a href="http://www.cplusplus.com/reference/iterator/RandomAccessIterator/">Random access iterator</a>
\param[in] first Iterator pointer to first element.
\param[in] last Iterator pointing to one beyond the end of data.
\pre [@c first, @c last) is a valid range.
\pre @c RandomAccessIter @c value_type is mutable.
\pre @c RandomAccessIter @c value_type is <a href="http://en.cppreference.com/w/cpp/concept/LessThanComparable">LessThanComparable</a>
\pre @c RandomAccessIter @c value_type supports the @c operator>>,
which returns an integer-type right-shifted a specified number of bits.
\post The elements in the range [@c first, @c last) are sorted in ascending order.
*/
template <class RandomAccessIter>
inline typename boost::enable_if_c< std::numeric_limits<
typename std::iterator_traits<RandomAccessIter>::value_type >::is_integer,
void >::type
spreadsort(RandomAccessIter first, RandomAccessIter last)
{
integer_sort(first, last);
}
/*!
\brief Generic @c spreadsort variant detecting float element type so call to @c float_sort.
\details If the data type provided is a float or castable-float, @c float_sort is used.
\note Sorting other data types requires picking between @c integer_sort, @c float_sort and @c string_sort directly,
as @c spreadsort won't accept types that don't have the appropriate @c type_traits.
\tparam RandomAccessIter <a href="http://www.cplusplus.com/reference/iterator/RandomAccessIterator/">Random access iterator</a>
\param[in] first Iterator pointer to first element.
\param[in] last Iterator pointing to one beyond the end of data.
\pre [@c first, @c last) is a valid range.
\pre @c RandomAccessIter @c value_type is mutable.
\pre @c RandomAccessIter @c value_type is <a href="http://en.cppreference.com/w/cpp/concept/LessThanComparable">LessThanComparable</a>
\pre @c RandomAccessIter @c value_type supports the @c operator>>,
which returns an integer-type right-shifted a specified number of bits.
\post The elements in the range [@c first, @c last) are sorted in ascending order.
*/
template <class RandomAccessIter>
inline typename boost::enable_if_c< !std::numeric_limits<
typename std::iterator_traits<RandomAccessIter>::value_type >::is_integer
&& std::numeric_limits<
typename std::iterator_traits<RandomAccessIter>::value_type >::is_iec559,
void >::type
spreadsort(RandomAccessIter first, RandomAccessIter last)
{
float_sort(first, last);
}
/*!
\brief Generic @c spreadsort variant detecting string element type so call to @c string_sort for @c std::strings and @c std::wstrings.
\details If the data type provided is a string or wstring, @c string_sort is used.
\note Sorting other data types requires picking between @c integer_sort, @c float_sort and @c string_sort directly,
as @c spreadsort won't accept types that don't have the appropriate @c type_traits.
\tparam RandomAccessIter <a href="http://www.cplusplus.com/reference/iterator/RandomAccessIterator/">Random access iterator</a>
\param[in] first Iterator pointer to first element.
\param[in] last Iterator pointing to one beyond the end of data.
\pre [@c first, @c last) is a valid range.
\pre @c RandomAccessIter @c value_type is mutable.
\pre @c RandomAccessIter @c value_type is <a href="http://en.cppreference.com/w/cpp/concept/LessThanComparable">LessThanComparable</a>
\pre @c RandomAccessIter @c value_type supports the @c operator>>,
which returns an integer-type right-shifted a specified number of bits.
\post The elements in the range [@c first, @c last) are sorted in ascending order.
*/
template <class RandomAccessIter>
inline typename boost::enable_if_c<
is_same<typename std::iterator_traits<RandomAccessIter>::value_type,
typename std::string>::value ||
is_same<typename std::iterator_traits<RandomAccessIter>::value_type,
typename std::wstring>::value, void >::type
spreadsort(RandomAccessIter first, RandomAccessIter last)
{
string_sort(first, last);
}
} // namespace sort
} // namespace boost
#endif
boost::sort::integer_sort
void integer_sort(RandomAccessIter first, RandomAccessIter last)
Integer sort algorithm using random access iterators. (All variants fall back to std::sort if the dat...
Definition: integer_sort.hpp:75
integer_sort.hpp
boost
Definition: float_sort.hpp:27
boost::sort::spreadsort
boost::enable_if_c< std::numeric_limits< typename std::iterator_traits< RandomAccessIter >::value_type >::is_integer, void >::type spreadsort(RandomAccessIter first, RandomAccessIter last)
Generic spreadsort variant detecting integer-type elements so call to integer_sort.
Definition: spreadsort.hpp:57
string_sort.hpp
boost::sort::string_sort
void string_sort(RandomAccessIter first, RandomAccessIter last, Unsigned_char_type unused)
String sort algorithm using random access iterators, allowing character-type overloads. (All variants fall back to std::sort if the data size is too small, < detail::min_sort_size).
Definition: string_sort.hpp:73
boost::sort::float_sort
void float_sort(RandomAccessIter first, RandomAccessIter last)
float_sort with casting to the appropriate size.
Definition: float_sort.hpp:86
float_sort.hpp