mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
ENH: add partial sorting to SortableList
This commit is contained in:
committed by
Andrew Heather
parent
3a1a353483
commit
bf30779b64
@ -2,7 +2,7 @@
|
|||||||
========= |
|
========= |
|
||||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
\\ / O peration |
|
\\ / O peration |
|
||||||
\\ / A nd | Copyright (C) 2017 OpenCFD Ltd.
|
\\ / A nd | Copyright (C) 2017-2019 OpenCFD Ltd.
|
||||||
\\/ M anipulation |
|
\\/ M anipulation |
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
| Copyright (C) 2011 OpenFOAM Foundation
|
| Copyright (C) 2011 OpenFOAM Foundation
|
||||||
@ -67,6 +67,10 @@ int main(int argc, char *argv[])
|
|||||||
Info<< "reverse ..." << nl;
|
Info<< "reverse ..." << nl;
|
||||||
printInfo(list1r);
|
printInfo(list1r);
|
||||||
|
|
||||||
|
list1r.partialSort(list1r.size()/2);
|
||||||
|
Info<< "partial sorted ..." << nl;
|
||||||
|
printInfo(list1r);
|
||||||
|
|
||||||
SortableList<label> list2(orig);
|
SortableList<label> list2(orig);
|
||||||
Info<< "unsorted: " << orig << nl;
|
Info<< "unsorted: " << orig << nl;
|
||||||
printInfo(list2);
|
printInfo(list2);
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
========= |
|
========= |
|
||||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
\\ / O peration |
|
\\ / O peration |
|
||||||
\\ / A nd | Copyright (C) 2017 OpenCFD Ltd.
|
\\ / A nd | Copyright (C) 2017-2019 OpenCFD Ltd.
|
||||||
\\/ M anipulation |
|
\\/ M anipulation |
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
| Copyright (C) 2011-2016 OpenFOAM Foundation
|
| Copyright (C) 2011-2016 OpenFOAM Foundation
|
||||||
@ -136,7 +136,7 @@ Foam::List<T>& Foam::SortableList<T>::shrink()
|
|||||||
template<class T>
|
template<class T>
|
||||||
void Foam::SortableList<T>::sort()
|
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> list(*this, indices_); // Copy with indices for mapping
|
||||||
List<T>::transfer(list);
|
List<T>::transfer(list);
|
||||||
@ -148,8 +148,48 @@ void Foam::SortableList<T>::reverseSort()
|
|||||||
{
|
{
|
||||||
Foam::sortedOrder(*this, indices_, typename UList<T>::greater(*this));
|
Foam::sortedOrder(*this, indices_, typename UList<T>::greater(*this));
|
||||||
|
|
||||||
List<T> lst(*this, indices_); // Copy with indices for mapping
|
List<T> list(*this, indices_); // Copy with indices for mapping
|
||||||
List<T>::transfer(lst);
|
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
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
\\ / O peration |
|
\\ / O peration |
|
||||||
\\ / A nd | Copyright (C) 2017 OpenCFD Ltd.
|
\\ / A nd | Copyright (C) 2017-2019 OpenCFD Ltd.
|
||||||
\\/ M anipulation |
|
\\/ M anipulation |
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
| Copyright (C) 2011-2016 OpenFOAM Foundation
|
| Copyright (C) 2011-2016 OpenFOAM Foundation
|
||||||
@ -130,6 +130,12 @@ public:
|
|||||||
// Resizes the indices as required
|
// Resizes the indices as required
|
||||||
void reverseSort();
|
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
|
//- Swap content with another SortableList in constant time
|
||||||
inline void swap(SortableList<T>& lst);
|
inline void swap(SortableList<T>& lst);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user