mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
ENH: ListOps - added uniqueSort function
This commit is contained in:
committed by
Andrew Heather
parent
053727d2d9
commit
ef14a415a9
@ -217,6 +217,10 @@ void uniqueOrder
|
|||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
|
//- Return sorted list with removal of duplicates
|
||||||
|
template<class T>
|
||||||
|
List<T> uniqueSort(const UList<T>& input);
|
||||||
|
|
||||||
//- Inplace sorting and removal of duplicates.
|
//- Inplace sorting and removal of duplicates.
|
||||||
// Do not use FixedList for the input list, since it doesn't resize.
|
// Do not use FixedList for the input list, since it doesn't resize.
|
||||||
template<class ListType>
|
template<class ListType>
|
||||||
|
|||||||
@ -424,6 +424,33 @@ void Foam::uniqueOrder
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template<class T>
|
||||||
|
Foam::List<T> Foam::uniqueSort(const UList<T>& input)
|
||||||
|
{
|
||||||
|
List<T> output(input);
|
||||||
|
|
||||||
|
const label len = output.size();
|
||||||
|
|
||||||
|
if (len > 1)
|
||||||
|
{
|
||||||
|
Foam::stableSort(output);
|
||||||
|
|
||||||
|
label count = 0;
|
||||||
|
for (label i = 1; i < len; ++i)
|
||||||
|
{
|
||||||
|
if (output[count] != output[i])
|
||||||
|
{
|
||||||
|
output[++count] = output[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
output.resize(count+1);
|
||||||
|
}
|
||||||
|
|
||||||
|
return output;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
template<class ListType>
|
template<class ListType>
|
||||||
void Foam::inplaceUniqueSort(ListType& input)
|
void Foam::inplaceUniqueSort(ListType& input)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user