mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
ListOps: added sortedOrder and changed template type (cosmetic)
- changed template<class List> to template<class ListType> for better distinction between List as class and as template type
This commit is contained in:
@ -28,7 +28,11 @@ License
|
||||
|
||||
// * * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * //
|
||||
|
||||
Foam::labelList Foam::invert(const label len, const UList<label>& map)
|
||||
Foam::labelList Foam::invert
|
||||
(
|
||||
const label len,
|
||||
const UList<label>& map
|
||||
)
|
||||
{
|
||||
labelList inverse(len, -1);
|
||||
|
||||
|
||||
@ -45,25 +45,25 @@ namespace Foam
|
||||
{
|
||||
|
||||
//- Renumber the values (not the indices) of a list.
|
||||
// List elements < 0 are left as is.
|
||||
template<class List>
|
||||
List renumber(const UList<label>& oldToNew, const List&);
|
||||
// Negative ListType elements are left as is.
|
||||
template<class ListType>
|
||||
ListType renumber(const UList<label>& oldToNew, const ListType&);
|
||||
|
||||
//- Inplace renumber the values of a list.
|
||||
// List elements < 0 are left as is.
|
||||
template<class List>
|
||||
void inplaceRenumber(const UList<label>& oldToNew, List&);
|
||||
// Negative ListType elements are left as is.
|
||||
template<class ListType>
|
||||
void inplaceRenumber(const UList<label>& oldToNew, ListType&);
|
||||
|
||||
|
||||
//- Reorder the elements (indices, not values) of a list.
|
||||
// List elements < 0 are left as is.
|
||||
template<class List>
|
||||
List reorder(const UList<label>& oldToNew, const List&);
|
||||
// Negative ListType elements are left as is.
|
||||
template<class ListType>
|
||||
ListType reorder(const UList<label>& oldToNew, const ListType&);
|
||||
|
||||
//- Inplace reorder the elements of a list.
|
||||
// List elements < 0 are left as is.
|
||||
template<class List>
|
||||
void inplaceReorder(const UList<label>& oldToNew, List&);
|
||||
// Negative ListType elements are left as is.
|
||||
template<class ListType>
|
||||
void inplaceReorder(const UList<label>& oldToNew, ListType&);
|
||||
|
||||
|
||||
// Variants to work with iterators and sparse tables.
|
||||
@ -72,22 +72,28 @@ void inplaceReorder(const UList<label>& oldToNew, List&);
|
||||
//- Map values. Do not map negative values.
|
||||
template<class Container>
|
||||
void inplaceMapValue(const UList<label>& oldToNew, Container&);
|
||||
|
||||
//- Recreate with mapped keys. Remove elements with negative key.
|
||||
template<class Container>
|
||||
void inplaceMapKey(const UList<label>& oldToNew, Container&);
|
||||
|
||||
|
||||
//- Generate the (stable) sort order for the list
|
||||
template<class T>
|
||||
void sortedOrder(const UList<T>&, labelList& order);
|
||||
|
||||
|
||||
//- Extract elements of List whose region is certain value.
|
||||
// Use e.g. to extract all selected elements:
|
||||
// subset<boolList, labelList>(selectedElems, true, lst);
|
||||
template<class T, class List>
|
||||
List subset(const UList<T>& regions, const T& region, const List&);
|
||||
template<class T, class ListType>
|
||||
ListType subset(const UList<T>& regions, const T& region, const ListType&);
|
||||
|
||||
//- Inplace extract elements of List whose region is certain value. Use e.g.
|
||||
// to extract all selected elements:
|
||||
// inplaceSubset<boolList, labelList>(selectedElems, true, lst);
|
||||
template<class T, class List>
|
||||
void inplaceSubset(const UList<T>& regions, const T& region, List&);
|
||||
template<class T, class ListType>
|
||||
void inplaceSubset(const UList<T>& regions, const T& region, ListType&);
|
||||
|
||||
//- Invert one-to-one map. Unmapped elements will be -1.
|
||||
labelList invert(const label len, const UList<label>&);
|
||||
@ -113,72 +119,72 @@ labelList identity(const label len);
|
||||
|
||||
//- Find first occurence of given element and return index,
|
||||
// return -1 if not found. Linear search.
|
||||
template<class List>
|
||||
template<class ListType>
|
||||
label findIndex
|
||||
(
|
||||
const List&,
|
||||
typename List::const_reference,
|
||||
const ListType&,
|
||||
typename ListType::const_reference,
|
||||
const label start=0
|
||||
);
|
||||
|
||||
//- Find all occurences of given element. Linear search.
|
||||
template<class List>
|
||||
template<class ListType>
|
||||
labelList findIndices
|
||||
(
|
||||
const List&,
|
||||
typename List::const_reference,
|
||||
const ListType&,
|
||||
typename ListType::const_reference,
|
||||
const label start=0
|
||||
);
|
||||
|
||||
//- Opposite of findIndices: set values at indices to given value
|
||||
template<class List>
|
||||
template<class ListType>
|
||||
void setValues
|
||||
(
|
||||
List&,
|
||||
ListType&,
|
||||
const UList<label>& indices,
|
||||
typename List::const_reference
|
||||
typename ListType::const_reference
|
||||
);
|
||||
|
||||
//- Opposite of findIndices: set values at indices to given value
|
||||
template<class List>
|
||||
List createWithValues
|
||||
template<class ListType>
|
||||
ListType createWithValues
|
||||
(
|
||||
const label sz,
|
||||
const typename List::const_reference initValue,
|
||||
const typename ListType::const_reference initValue,
|
||||
const UList<label>& indices,
|
||||
typename List::const_reference setValue
|
||||
typename ListType::const_reference setValue
|
||||
);
|
||||
|
||||
//- Find index of max element (and larger than given element).
|
||||
// return -1 if not found. Linear search.
|
||||
template<class List>
|
||||
label findMax(const List&, const label start=0);
|
||||
template<class ListType>
|
||||
label findMax(const ListType&, const label start=0);
|
||||
|
||||
|
||||
//- Find index of min element (and less than given element).
|
||||
// return -1 if not found. Linear search.
|
||||
template<class List>
|
||||
label findMin(const List&, const label start=0);
|
||||
template<class ListType>
|
||||
label findMin(const ListType&, const label start=0);
|
||||
|
||||
|
||||
//- Find first occurence of given element in sorted list and return index,
|
||||
// return -1 if not found. Binary search.
|
||||
template<class List>
|
||||
template<class ListType>
|
||||
label findSortedIndex
|
||||
(
|
||||
const List&,
|
||||
typename List::const_reference,
|
||||
const ListType&,
|
||||
typename ListType::const_reference,
|
||||
const label start=0
|
||||
);
|
||||
|
||||
|
||||
//- Find last element < given value in sorted list and return index,
|
||||
// return -1 if not found. Binary search.
|
||||
template<class List>
|
||||
template<class ListType>
|
||||
label findLower
|
||||
(
|
||||
const List&,
|
||||
typename List::const_reference,
|
||||
const ListType&,
|
||||
typename ListType::const_reference,
|
||||
const label start=0
|
||||
);
|
||||
|
||||
|
||||
@ -28,15 +28,15 @@ License
|
||||
|
||||
// * * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * //
|
||||
|
||||
template<class List>
|
||||
List Foam::renumber
|
||||
template<class ListType>
|
||||
ListType Foam::renumber
|
||||
(
|
||||
const UList<label>& oldToNew,
|
||||
const List& lst
|
||||
const ListType& lst
|
||||
)
|
||||
{
|
||||
// Create copy
|
||||
List newLst(lst.size());
|
||||
ListType newLst(lst.size());
|
||||
|
||||
forAll(lst, elemI)
|
||||
{
|
||||
@ -50,11 +50,11 @@ List Foam::renumber
|
||||
}
|
||||
|
||||
|
||||
template<class List>
|
||||
template<class ListType>
|
||||
void Foam::inplaceRenumber
|
||||
(
|
||||
const UList<label>& oldToNew,
|
||||
List& lst
|
||||
ListType& lst
|
||||
)
|
||||
{
|
||||
forAll(lst, elemI)
|
||||
@ -67,15 +67,15 @@ void Foam::inplaceRenumber
|
||||
}
|
||||
|
||||
|
||||
template<class List>
|
||||
List Foam::reorder
|
||||
template<class ListType>
|
||||
ListType Foam::reorder
|
||||
(
|
||||
const UList<label>& oldToNew,
|
||||
const List& lst
|
||||
const ListType& lst
|
||||
)
|
||||
{
|
||||
// Create copy
|
||||
List newLst(lst.size());
|
||||
ListType newLst(lst.size());
|
||||
|
||||
forAll(lst, elemI)
|
||||
{
|
||||
@ -92,15 +92,15 @@ List Foam::reorder
|
||||
}
|
||||
|
||||
|
||||
template<class List>
|
||||
template<class ListType>
|
||||
void Foam::inplaceReorder
|
||||
(
|
||||
const UList<label>& oldToNew,
|
||||
List& lst
|
||||
ListType& lst
|
||||
)
|
||||
{
|
||||
// Create copy
|
||||
List newLst(lst.size());
|
||||
ListType newLst(lst.size());
|
||||
|
||||
forAll(lst, elemI)
|
||||
{
|
||||
@ -166,18 +166,41 @@ void Foam::inplaceMapKey
|
||||
}
|
||||
|
||||
|
||||
template<class T, class List>
|
||||
List Foam::subset(const UList<T>& regions, const T& region, const List& lst)
|
||||
template<class T>
|
||||
void Foam::sortedOrder
|
||||
(
|
||||
const UList<T>& lst,
|
||||
labelList& order
|
||||
)
|
||||
{
|
||||
order.setSize(lst.size());
|
||||
|
||||
forAll(order, elemI)
|
||||
{
|
||||
order[elemI] = elemI;
|
||||
}
|
||||
|
||||
Foam::stableSort(order, typename UList<T>::less(lst));
|
||||
}
|
||||
|
||||
|
||||
template<class T, class ListType>
|
||||
ListType Foam::subset
|
||||
(
|
||||
const UList<T>& regions,
|
||||
const T& region,
|
||||
const ListType& lst
|
||||
)
|
||||
{
|
||||
if (regions.size() < lst.size())
|
||||
{
|
||||
FatalErrorIn("subset(const UList<T>&, const T&, const List&)")
|
||||
FatalErrorIn("subset(const UList<T>&, const T&, const ListType&)")
|
||||
<< "Regions is of size " << regions.size()
|
||||
<< "; list it is supposed to index is of size " << lst.size()
|
||||
<< abort(FatalError);
|
||||
}
|
||||
|
||||
List newLst(lst.size());
|
||||
ListType newLst(lst.size());
|
||||
|
||||
label nElem = 0;
|
||||
forAll(lst, elemI)
|
||||
@ -193,12 +216,17 @@ List Foam::subset(const UList<T>& regions, const T& region, const List& lst)
|
||||
}
|
||||
|
||||
|
||||
template<class T, class List>
|
||||
void Foam::inplaceSubset(const UList<T>& regions, const T& region, List& lst)
|
||||
template<class T, class ListType>
|
||||
void Foam::inplaceSubset
|
||||
(
|
||||
const UList<T>& regions,
|
||||
const T& region,
|
||||
ListType& lst
|
||||
)
|
||||
{
|
||||
if (regions.size() < lst.size())
|
||||
{
|
||||
FatalErrorIn("inplaceSubset(const UList<T>&, const T&, List&)")
|
||||
FatalErrorIn("inplaceSubset(const UList<T>&, const T&, ListType&)")
|
||||
<< "Regions is of size " << regions.size()
|
||||
<< "; list it is supposed to index is of size " << lst.size()
|
||||
<< abort(FatalError);
|
||||
@ -221,8 +249,8 @@ void Foam::inplaceSubset(const UList<T>& regions, const T& region, List& lst)
|
||||
}
|
||||
|
||||
|
||||
// As clarification coded as inversion from pointEdges to edges but completely
|
||||
// general.
|
||||
// As clarification:
|
||||
// coded as inversion from pointEdges to edges but completely general.
|
||||
template<class InList, class OutList>
|
||||
void Foam::invertManyToMany
|
||||
(
|
||||
@ -268,11 +296,11 @@ void Foam::invertManyToMany
|
||||
}
|
||||
|
||||
|
||||
template<class List>
|
||||
template<class ListType>
|
||||
Foam::label Foam::findIndex
|
||||
(
|
||||
const List& l,
|
||||
typename List::const_reference t,
|
||||
const ListType& l,
|
||||
typename ListType::const_reference t,
|
||||
const label start
|
||||
)
|
||||
{
|
||||
@ -291,11 +319,11 @@ Foam::label Foam::findIndex
|
||||
}
|
||||
|
||||
|
||||
template<class List>
|
||||
template<class ListType>
|
||||
Foam::labelList Foam::findIndices
|
||||
(
|
||||
const List& l,
|
||||
typename List::const_reference t,
|
||||
const ListType& l,
|
||||
typename ListType::const_reference t,
|
||||
const label start
|
||||
)
|
||||
{
|
||||
@ -326,12 +354,12 @@ Foam::labelList Foam::findIndices
|
||||
}
|
||||
|
||||
|
||||
template<class List>
|
||||
template<class ListType>
|
||||
void Foam::setValues
|
||||
(
|
||||
List& l,
|
||||
ListType& l,
|
||||
const UList<label>& indices,
|
||||
typename List::const_reference t
|
||||
typename ListType::const_reference t
|
||||
)
|
||||
{
|
||||
forAll(indices, i)
|
||||
@ -341,23 +369,23 @@ void Foam::setValues
|
||||
}
|
||||
|
||||
|
||||
template<class List>
|
||||
List Foam::createWithValues
|
||||
template<class ListType>
|
||||
ListType Foam::createWithValues
|
||||
(
|
||||
const label sz,
|
||||
const typename List::const_reference initValue,
|
||||
const typename ListType::const_reference initValue,
|
||||
const UList<label>& indices,
|
||||
typename List::const_reference setValue
|
||||
typename ListType::const_reference setValue
|
||||
)
|
||||
{
|
||||
List l(sz, initValue);
|
||||
ListType l(sz, initValue);
|
||||
setValues(l, indices, setValue);
|
||||
return l;
|
||||
}
|
||||
|
||||
|
||||
template<class List>
|
||||
Foam::label Foam::findMax(const List& l, const label start)
|
||||
template<class ListType>
|
||||
Foam::label Foam::findMax(const ListType& l, const label start)
|
||||
{
|
||||
if (start >= l.size())
|
||||
{
|
||||
@ -378,8 +406,8 @@ Foam::label Foam::findMax(const List& l, const label start)
|
||||
}
|
||||
|
||||
|
||||
template<class List>
|
||||
Foam::label Foam::findMin(const List& l, const label start)
|
||||
template<class ListType>
|
||||
Foam::label Foam::findMin(const ListType& l, const label start)
|
||||
{
|
||||
if (start >= l.size())
|
||||
{
|
||||
@ -400,11 +428,11 @@ Foam::label Foam::findMin(const List& l, const label start)
|
||||
}
|
||||
|
||||
|
||||
template<class List>
|
||||
template<class ListType>
|
||||
Foam::label Foam::findSortedIndex
|
||||
(
|
||||
const List& l,
|
||||
typename List::const_reference t,
|
||||
const ListType& l,
|
||||
typename ListType::const_reference t,
|
||||
const label start
|
||||
)
|
||||
{
|
||||
@ -438,11 +466,11 @@ Foam::label Foam::findSortedIndex
|
||||
}
|
||||
|
||||
|
||||
template<class List>
|
||||
template<class ListType>
|
||||
Foam::label Foam::findLower
|
||||
(
|
||||
const List& l,
|
||||
typename List::const_reference t,
|
||||
const ListType& l,
|
||||
typename ListType::const_reference t,
|
||||
const label start
|
||||
)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user