Merge remote-tracking branch 'origin/development'

# Conflicts:
#	include/etl/version.h
#	library.json
#	library.properties
#	support/Release notes.txt
This commit is contained in:
John Wellbelove 2020-01-14 12:46:17 +00:00
parent af5a760d5d
commit 8a99a2725c
6 changed files with 74 additions and 3 deletions

View File

@ -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.
//***************************************************************************

View File

@ -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)

View File

@ -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"

View File

@ -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

View File

@ -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.

View File

@ -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)
{