mirror of
https://github.com/ETLCPP/etl.git
synced 2026-10-28 18:07:10 +08:00
Merge remote-tracking branch 'origin/development'
# Conflicts: # include/etl/version.h # library.json # library.properties # support/Release notes.txt
This commit is contained in:
parent
af5a760d5d
commit
8a99a2725c
@ -2938,6 +2938,43 @@ namespace etl
|
||||
etl::insertion_sort(first, last, etl::less<typename etl::iterator_traits<TIterator>::value_type>());
|
||||
}
|
||||
|
||||
//***************************************************************************
|
||||
/// Sorts the elements using heap sort.
|
||||
/// Uses user defined comparison.
|
||||
///\ingroup algorithm
|
||||
//***************************************************************************
|
||||
template <typename TIterator, typename TCompare >
|
||||
void heap_sort(TIterator first, TIterator last, TCompare compare)
|
||||
{
|
||||
if (!etl::is_heap(first, last, compare))
|
||||
{
|
||||
etl::make_heap(first, last, compare);
|
||||
}
|
||||
|
||||
while (first != last)
|
||||
{
|
||||
etl::pop_heap(first, last--, compare);
|
||||
}
|
||||
}
|
||||
|
||||
//***************************************************************************
|
||||
/// Sorts the elements using heap sort.
|
||||
///\ingroup algorithm
|
||||
//***************************************************************************
|
||||
template <typename TIterator>
|
||||
void heap_sort(TIterator first, TIterator last)
|
||||
{
|
||||
if (!etl::is_heap(first, last))
|
||||
{
|
||||
etl::make_heap(first, last);
|
||||
}
|
||||
|
||||
while (first != last)
|
||||
{
|
||||
etl::pop_heap(first, last--);
|
||||
}
|
||||
}
|
||||
|
||||
//***************************************************************************
|
||||
/// Returns the maximum value.
|
||||
//***************************************************************************
|
||||
|
||||
@ -38,7 +38,7 @@ SOFTWARE.
|
||||
///\ingroup utilities
|
||||
|
||||
#define ETL_VERSION_MAJOR 16
|
||||
#define ETL_VERSION_MINOR 1
|
||||
#define ETL_VERSION_MINOR 2
|
||||
#define ETL_VERSION_PATCH 0
|
||||
|
||||
#define ETL_VERSION ETL_STRINGIFY(ETL_VERSION_MAJOR) "." ETL_STRINGIFY(ETL_VERSION_MINOR) "." ETL_STRINGIFY(ETL_VERSION_PATCH)
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "Embedded Template Library",
|
||||
"version": "16.1.0",
|
||||
"version": "16.2.0",
|
||||
"authors": {
|
||||
"name": "John Wellbelove",
|
||||
"email": "john.wellbelove@etlcpp.com"
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
name=Embedded Template Library
|
||||
version=16.1.0
|
||||
version=16.2.0
|
||||
author= John Wellbelove <john.wellbelove@etlcpp.com>
|
||||
maintainer=John Wellbelove <john.wellbelove@etlcpp.com>
|
||||
license=MIT
|
||||
|
||||
@ -1,3 +1,7 @@
|
||||
===============================================================================
|
||||
16.2.0
|
||||
Added etl::heap_sort to algorithms.
|
||||
|
||||
===============================================================================
|
||||
16.1.0
|
||||
Added compile time option to make string truncation an error.
|
||||
|
||||
@ -1856,6 +1856,36 @@ namespace
|
||||
CHECK(is_same);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(heap_sort_default)
|
||||
{
|
||||
std::vector<NDC> initial_data = { NDC(1, 1), NDC(2, 1), NDC(3, 1), NDC(2, 2), NDC(3, 2), NDC(4, 1), NDC(2, 3), NDC(3, 3), NDC(5, 1) };
|
||||
|
||||
std::vector<NDC> data1(initial_data);
|
||||
std::vector<NDC> data2(initial_data);
|
||||
|
||||
std::sort(data1.begin(), data1.end());
|
||||
etl::heap_sort(data2.begin(), data2.end());
|
||||
|
||||
bool is_same = std::equal(data1.begin(), data1.end(), data2.begin());
|
||||
CHECK(is_same);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(heap_sort_greater)
|
||||
{
|
||||
std::vector<NDC> initial_data = { NDC(1, 1), NDC(2, 1), NDC(3, 1), NDC(2, 2), NDC(3, 2), NDC(4, 1), NDC(2, 3), NDC(3, 3), NDC(5, 1) };
|
||||
|
||||
std::vector<NDC> data1(initial_data);
|
||||
std::vector<NDC> data2(initial_data);
|
||||
|
||||
std::sort(data1.begin(), data1.end(), std::greater<NDC>());
|
||||
etl::heap_sort(data2.begin(), data2.end(), std::greater<NDC>());
|
||||
|
||||
bool is_same = std::equal(data1.begin(), data1.end(), data2.begin());
|
||||
CHECK(is_same);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(multimax)
|
||||
{
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user