Commit dd11951c authored by Mark Olesen's avatar Mark Olesen

ENH: add partial sorting to SortableList

parent 1d77aeb5
......@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2004-2010, 2017 OpenCFD Ltd.
\\ / A nd | Copyright (C) 2004-2010, 2017-2019 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
| Copyright (C) 2011 OpenFOAM Foundation
......@@ -67,6 +67,10 @@ int main(int argc, char *argv[])
Info<< "reverse ..." << nl;
printInfo(list1r);
list1r.partialSort(list1r.size()/2);
Info<< "partial sorted ..." << nl;
printInfo(list1r);
SortableList<label> list2(orig);
Info<< "unsorted: " << orig << nl;
printInfo(list2);
......
......@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2004-2010, 2017 OpenCFD Ltd.
\\ / A nd | Copyright (C) 2004-2010, 2017-2019 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
| Copyright (C) 2011-2016 OpenFOAM Foundation
......@@ -136,7 +136,7 @@ Foam::List<T>& Foam::SortableList<T>::shrink()
template<class T>
void Foam::SortableList<T>::sort()
{
Foam::sortedOrder(*this, indices_);
Foam::sortedOrder(*this, indices_, typename UList<T>::less(*this));
List<T> list(*this, indices_); // Copy with indices for mapping
List<T>::transfer(list);
......@@ -148,8 +148,48 @@ void Foam::SortableList<T>::reverseSort()
{
Foam::sortedOrder(*this, indices_, typename UList<T>::greater(*this));
List<T> lst(*this, indices_); // Copy with indices for mapping
List<T>::transfer(lst);
List<T> list(*this, indices_); // Copy with indices for mapping
List<T>::transfer(list);
}
template<class T>
void Foam::SortableList<T>::partialSort(label n, label start)
{
indices_.resize(this->size());
ListOps::identity(indices_);
// Forward partial sort of indices
std::partial_sort
(
indices_.begin() + start,
indices_.begin() + start + n,
indices_.end(),
typename UList<T>::less(*this)
);
List<T> list(*this, indices_); // Copy with indices for mapping
List<T>::transfer(list);
}
template<class T>
void Foam::SortableList<T>::partialReverseSort(label n, label start)
{
indices_.resize(this->size());
ListOps::identity(indices_);
// Reverse partial sort of indices
std::partial_sort
(
indices_.begin() + start,
indices_.begin() + start + n,
indices_.end(),
typename UList<T>::greater(*this)
);
List<T> list(*this, indices_); // Copy with indices for mapping
List<T>::transfer(list);
}
......
......@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2004-2010, 2017 OpenCFD Ltd.
\\ / A nd | Copyright (C) 2004-2010, 2017-2019 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
| Copyright (C) 2011-2016 OpenFOAM Foundation
......@@ -130,6 +130,12 @@ public:
// Resizes the indices as required
void reverseSort();
//- Forward partial sort the list until the middle point
void partialSort(label n, label start=0);
//- Reverse partial sort the list until the middle point
void partialReverseSort(label n, label start=0);
//- Swap content with another SortableList in constant time
inline void swap(SortableList<T>& lst);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment