ENH: promote ListOps::identity to Foam::identity

- becoming more frequently used and there is no ambiguity in calling
  parameters either - identity(label) vs identity(labelUList&).

  Provide both int32 and int64 versions.
This commit is contained in:
Mark Olesen 2023-10-26 10:42:23 +02:00
parent ef92d31493
commit d9f0587416
20 changed files with 86 additions and 86 deletions

View File

@ -133,7 +133,7 @@ int main(int argc, char *argv[])
DynamicList<label, 64> list1; DynamicList<label, 64> list1;
list1.resize(4); list1.resize(4);
ListOps::identity(list1); Foam::identity(list1);
list1.resize(3); list1.resize(3);
printInfo("", list1); printInfo("", list1);
@ -152,7 +152,7 @@ int main(int argc, char *argv[])
DynamicList<label, 64> list2; DynamicList<label, 64> list2;
list2.resize(5); list2.resize(5);
ListOps::identity(list2); Foam::identity(list2);
Info<< "initial list" << nl; Info<< "initial list" << nl;
printInfo("", list2); printInfo("", list2);

View File

@ -147,7 +147,7 @@ int main(int argc, char *argv[])
{ {
List<label> ident(15); List<label> ident(15);
std::iota(ident.begin(), ident.end(), 0); Foam::identity(ident, 0);
Info<<"Ident:"; Info<<"Ident:";
forAllConstIters(ident, iter) forAllConstIters(ident, iter)
@ -546,10 +546,10 @@ int main(int argc, char *argv[])
Info<< "scalars: " << flatOutput(scalars) << endl; Info<< "scalars: " << flatOutput(scalars) << endl;
} }
#if WM_LABEL_SIZE == 32 // #if WM_LABEL_SIZE == 32
{ {
List<int64_t> input(10); List<int64_t> input(10);
std::iota(input.begin(), input.end(), 50); Foam::identity(input, 50);
auto output = ListOps::create<label> auto output = ListOps::create<label>
( (
@ -558,10 +558,10 @@ int main(int argc, char *argv[])
); );
Info<< "label (from int64): " << flatOutput(output) << endl; Info<< "label (from int64): " << flatOutput(output) << endl;
} }
#elif WM_LABEL_SIZE == 64 // #elif WM_LABEL_SIZE == 64
{ {
List<int32_t> input(10); List<int32_t> input(10);
std::iota(input.begin(), input.end(), 50); Foam::identity(input, 50);
auto output = ListOps::create<label> auto output = ListOps::create<label>
( (
@ -570,7 +570,7 @@ int main(int argc, char *argv[])
); );
Info<< "label (from int32): " << flatOutput(output) << endl; Info<< "label (from int32): " << flatOutput(output) << endl;
} }
#endif // #endif
labelHashSet locations{ -15, 5, 10, 15, 25, 35 }; labelHashSet locations{ -15, 5, 10, 15, 25, 35 };

View File

@ -59,7 +59,7 @@ int main(int argc, char *argv[])
{ {
List<label> ident(25); List<label> ident(25);
std::iota(ident.begin(), ident.end(), 0); Foam::identity(ident, 0);
print(ident); print(ident);
@ -108,7 +108,7 @@ int main(int argc, char *argv[])
// This is also possible since we hold a concrete pointer/size // This is also possible since we hold a concrete pointer/size
// and not an intermediate // and not an intermediate
ListOps::identity(sub.reset(ident, 8, 8)); Foam::identity(sub.reset(ident, 8, 8));
print(sub); print(sub);
print(ident); print(ident);
} }

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2011-2017 OpenFOAM Foundation Copyright (C) 2011-2017 OpenFOAM Foundation
Copyright (C) 2017-2022 OpenCFD Ltd. Copyright (C) 2017-2023 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -523,8 +523,8 @@ int main(int argc, char *argv[])
labelList faceIds; labelList faceIds;
// Markup master face ids // Markup master face ids
faceIds.setSize(masterPatch.size()); faceIds.resize_nocopy(masterPatch.size());
std::iota(faceIds.begin(), faceIds.end(), masterPatch.start()); Foam::identity(faceIds, masterPatch.start());
stitcher.clear(); stitcher.clear();
stitcher.setSize(1); stitcher.setSize(1);
@ -569,8 +569,8 @@ int main(int argc, char *argv[])
).resetAddressing(std::move(faceIds), false); ).resetAddressing(std::move(faceIds), false);
// Markup slave face ids // Markup slave face ids
faceIds.setSize(slavePatch.size()); faceIds.resize_nocopy(slavePatch.size());
std::iota(faceIds.begin(), faceIds.end(), slavePatch.start()); Foam::identity(faceIds, slavePatch.start());
mesh.faceZones() mesh.faceZones()
( (

View File

@ -62,7 +62,7 @@ $(ints)/int32/int32IO.C
$(ints)/int64/int64.C $(ints)/int64/int64.C
$(ints)/int64/int64IO.C $(ints)/int64/int64IO.C
$(ints)/label/label.C $(ints)/label/label.C
$(ints)/lists/labelList.C $(ints)/lists/labelLists.C
$(ints)/lists/labelIOList.C $(ints)/lists/labelIOList.C
$(ints)/lists/labelListIOList.C $(ints)/lists/labelListIOList.C

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com \\ / A nd | www.openfoam.com
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2019-2022 OpenCFD Ltd. Copyright (C) 2019-2023 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -25,8 +25,6 @@ License
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
#include "ListOps.H" // For identity
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
template<class T> template<class T>
@ -77,7 +75,7 @@ inline void Foam::SortList<T>::reset()
auto& addr = this->indices(); auto& addr = this->indices();
addr.resize_nocopy(this->values().size()); addr.resize_nocopy(this->values().size());
ListOps::identity(addr); Foam::identity(addr, 0);
} }
@ -89,7 +87,7 @@ inline void Foam::SortList<T>::sort(const Compare& comp)
auto& addr = this->indices(); auto& addr = this->indices();
addr.resize_nocopy(vals.size()); addr.resize_nocopy(vals.size());
ListOps::identity(addr); Foam::identity(addr, 0);
std::stable_sort std::stable_sort
( (

View File

@ -481,14 +481,7 @@ void Foam::sortedOrder
// List lengths must be identical. Old content is overwritten // List lengths must be identical. Old content is overwritten
order.resize_nocopy(list.size()); order.resize_nocopy(list.size());
// Same as std::iota and ListOps::identity Foam::identity(order, 0);
label value = 0;
for (label& item : order)
{
item = value;
++value;
}
Foam::stableSort(order, comp); Foam::stableSort(order, comp);
} }

View File

@ -431,7 +431,8 @@ Istream& operator>>(Istream& is, List<T>& list)
// * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * * //
//- Return an identity map of the given length with (map[i] == i) //- Return an identity map of the given length with (map[i] == i),
//- works like std::iota() but returning a list of label values.
// Optionally with an alternative start index, so that (map[i] == i+start) // Optionally with an alternative start index, so that (map[i] == i+start)
labelList identity(const label len, label start=0); labelList identity(const label len, label start=0);

View File

@ -201,7 +201,7 @@ public:
bool operator()(const label a, const label b) const bool operator()(const label a, const label b) const
{ {
return values[a] < values[b]; return (values[a] < values[b]);
} }
}; };
@ -217,7 +217,7 @@ public:
bool operator()(const label a, const label b) const bool operator()(const label a, const label b) const
{ {
return values[b] < values[a]; return (values[b] < values[a]);
} }
}; };
@ -677,6 +677,14 @@ Ostream& operator<<(Ostream& os, const std::vector<T>& list);
// * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * * //
//- Fill an identity map with (map[i] == i), works like std::iota().
// Optionally with an alternative start index, so that (map[i] == i+start)
void identity(UList<int32_t>& map, int32_t start = 0);
//- Fill an identity map with (map[i] == i), works like std::iota().
// Optionally with an alternative start index, so that (map[i] == i+start)
void identity(UList<int64_t>& map, int64_t start = 0);
//- Sort the list //- Sort the list
template<class T> template<class T>
void sort(UList<T>& list); void sort(UList<T>& list);

View File

@ -200,12 +200,6 @@ void Foam::inplaceReorder
} }
void Foam::ListOps::identity(labelUList& map, label start)
{
std::iota(map.begin(), map.end(), start);
}
void Foam::ListOps::unionEqOp::operator() void Foam::ListOps::unionEqOp::operator()
( (
labelList& x, labelList& x,

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2011-2017 OpenFOAM Foundation Copyright (C) 2011-2017 OpenFOAM Foundation
Copyright (C) 2017-2022 OpenCFD Ltd. Copyright (C) 2017-2023 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -593,7 +593,7 @@ struct less
bool operator()(const label a, const label b) const bool operator()(const label a, const label b) const
{ {
return values[a] < values[b]; return (values[a] < values[b]);
} }
}; };
@ -611,14 +611,19 @@ struct greater
bool operator()(const label a, const label b) const bool operator()(const label a, const label b) const
{ {
return values[b] < values[a]; return (values[b] < values[a]);
} }
}; };
//- Set identity map with (map[i] == i) //- Fill an identity map with (map[i] == i)
// Optionally with an alternative start index, so that (map[i] == i+start) // Optionally with an alternative start index, so that (map[i] == i+start)
void identity(labelUList& map, label start=0); FOAM_DEPRECATED_STRICT(2023-10, "Foam::identity(...)")
inline void identity(labelUList& map, label start = 0)
{
Foam::identity(map, start);
}
//- Count the number of matching entries. //- Count the number of matching entries.
// When start is specified, any occurrences before start are ignored. // When start is specified, any occurrences before start are ignored.

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2017-2022 OpenCFD Ltd. Copyright (C) 2017-2023 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -26,8 +26,6 @@ License
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
#include "ListOps.H" // For identity
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
template<class T> template<class T>
@ -136,7 +134,7 @@ template<class T>
void Foam::SortableList<T>::partialSort(label n, label start) void Foam::SortableList<T>::partialSort(label n, label start)
{ {
indices_.resize_nocopy(this->size()); indices_.resize_nocopy(this->size());
ListOps::identity(indices_); Foam::identity(indices_, 0);
// Forward partial sort of indices // Forward partial sort of indices
std::partial_sort std::partial_sort
@ -156,7 +154,7 @@ template<class T>
void Foam::SortableList<T>::partialReverseSort(label n, label start) void Foam::SortableList<T>::partialReverseSort(label n, label start)
{ {
indices_.resize_nocopy(this->size()); indices_.resize_nocopy(this->size());
ListOps::identity(indices_); Foam::identity(indices_, 0);
// Reverse partial sort of indices // Reverse partial sort of indices
std::partial_sort std::partial_sort

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com \\ / A nd | www.openfoam.com
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2019-2022 OpenCFD Ltd. Copyright (C) 2019-2023 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -63,13 +63,7 @@ void Foam::sortedOrder
// List lengths must be identical. Old content is overwritten // List lengths must be identical. Old content is overwritten
order.resize_nocopy(list.size()); order.resize_nocopy(list.size());
// Same as std::iota and ListOps::identity Foam::identity(order, 0);
label value = 0;
for (label& item : order)
{
item = value;
++value;
}
std::stable_sort(order.begin(), order.end(), comp); std::stable_sort(order.begin(), order.end(), comp);
} }

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2013-2016 OpenFOAM Foundation Copyright (C) 2013-2016 OpenFOAM Foundation
Copyright (C) 2019-2020 OpenCFD Ltd. Copyright (C) 2019-2023 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -28,19 +28,17 @@ License
#include "SquareMatrix.H" #include "SquareMatrix.H"
#include "RectangularMatrix.H" #include "RectangularMatrix.H"
#include "labelList.H"
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class Type> template<class Type>
template<class CompOp> template<class CompOp>
Foam::List<Foam::label> Foam::SquareMatrix<Type>::sortPermutation Foam::labelList Foam::SquareMatrix<Type>::sortPermutation
( (
CompOp& compare CompOp& compare
) const ) const
{ {
List<label> p(this->m()); labelList p = Foam::identity(this->m());
std::iota(p.begin(), p.end(), 0);
std::sort std::sort
( (
p.begin(), p.begin(),
@ -53,7 +51,7 @@ Foam::List<Foam::label> Foam::SquareMatrix<Type>::sortPermutation
template<class Type> template<class Type>
void Foam::SquareMatrix<Type>::applyPermutation(const List<label>& p) void Foam::SquareMatrix<Type>::applyPermutation(const labelUList& p)
{ {
#ifdef FULLDEBUG #ifdef FULLDEBUG
if (this->m() != p.size()) if (this->m() != p.size())

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2019-2022 OpenCFD Ltd. Copyright (C) 2019-2023 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -40,8 +40,8 @@ SourceFiles
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
#ifndef SquareMatrix_H #ifndef Foam_SquareMatrix_H
#define SquareMatrix_H #define Foam_SquareMatrix_H
#include "Matrix.H" #include "Matrix.H"
#include "Identity.H" #include "Identity.H"
@ -65,7 +65,6 @@ class SquareMatrix
: :
public Matrix<SquareMatrix<Type>, Type> public Matrix<SquareMatrix<Type>, Type>
{ {
public: public:
// Generated Methods // Generated Methods
@ -172,14 +171,13 @@ public:
// Sort // Sort
//- Return a sort permutation labelList according to //- Return a sort permutation using the given comparison operator
//- a given comparison on the diagonal entries //- on the diagonal entries
template<class CompOp> template<class CompOp>
List<label> sortPermutation(CompOp& compare) const; labelList sortPermutation(CompOp& compare) const;
//- Column-reorder this Matrix according to //- Column-reorder this Matrix according to the given permutation
//- a given permutation labelList void applyPermutation(const labelUList& p);
void applyPermutation(const List<label>& p);
// Member Operators // Member Operators

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2017-2022 OpenCFD Ltd. Copyright (C) 2017-2023 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -26,7 +26,7 @@ License
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
#include "ListOps.H" // sortedOrder, ListOps::identity #include "ListOps.H" // sortedOrder
// * * * * * * * * * * * * * * * Implementation * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Implementation * * * * * * * * * * * * * * //
@ -230,7 +230,7 @@ Foam::label Foam::Detail::mergePoints
// Setup initial identity +1 mapping for pointToUnique // Setup initial identity +1 mapping for pointToUnique
// The +1 allows negatives to mark duplicates // The +1 allows negatives to mark duplicates
ListOps::identity(pointToUnique, 1); Foam::identity(pointToUnique, 1);
// The newPointCounts is an offsets table that we use to walk // The newPointCounts is an offsets table that we use to walk
// across the adjacency list (lookupMerged), picking the original // across the adjacency list (lookupMerged), picking the original

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com \\ / A nd | www.openfoam.com
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2019 OpenCFD Ltd. Copyright (C) 2019-2023 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -30,11 +30,24 @@ License
// * * * * * * * * * * * * * * Global Data Members * * * * * * * * * * * * * // // * * * * * * * * * * * * * * Global Data Members * * * * * * * * * * * * * //
// This was deprecated (2019-02) in favour of labelList::null()
const Foam::labelList Foam::emptyLabelList; const Foam::labelList Foam::emptyLabelList;
// * * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * //
void Foam::identity(Foam::UList<int32_t>& map, int32_t start)
{
std::iota(map.begin(), map.end(), start);
}
void Foam::identity(Foam::UList<int64_t>& map, int64_t start)
{
std::iota(map.begin(), map.end(), start);
}
Foam::labelList Foam::identity(const label len, label start) Foam::labelList Foam::identity(const label len, label start)
{ {
labelList map(len); labelList map(len);

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com \\ / A nd | www.openfoam.com
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2020-2022 OpenCFD Ltd. Copyright (C) 2020-2023 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -161,16 +161,16 @@ Foam::label Foam::ensightCells::meshPointMapppings
// Non-parallel // Non-parallel
nPoints = mesh.nPoints(); nPoints = mesh.nPoints();
pointToGlobal.resize(nPoints); pointToGlobal.resize_nocopy(nPoints);
if (allCells) if (allCells)
{ {
// All cells used, and thus all points // All cells used, and thus all points
uniqueMeshPointLabels.resize(nPoints); uniqueMeshPointLabels.resize_nocopy(nPoints);
ListOps::identity(pointToGlobal); Foam::identity(pointToGlobal);
ListOps::identity(uniqueMeshPointLabels); Foam::identity(uniqueMeshPointLabels);
} }
else else
{ {

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com \\ / A nd | www.openfoam.com
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2020-2022 OpenCFD Ltd. Copyright (C) 2020-2023 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -88,8 +88,8 @@ void Foam::ensightFaces::write
nPoints = pp.meshPoints().size(); nPoints = pp.meshPoints().size();
uniqueMeshPointLabels = pp.meshPoints(); uniqueMeshPointLabels = pp.meshPoints();
pointToGlobal.resize(nPoints); pointToGlobal.resize_nocopy(nPoints);
ListOps::identity(pointToGlobal); Foam::identity(pointToGlobal);
} }
ensightOutput::Detail::writeCoordinates ensightOutput::Detail::writeCoordinates

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com \\ / A nd | www.openfoam.com
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2016-2022 OpenCFD Ltd. Copyright (C) 2016-2023 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -858,7 +858,7 @@ void Foam::vtk::vtuSizing::populateArrays
// May have been done by caller, // May have been done by caller,
// but for additional safety set an identity mapping // but for additional safety set an identity mapping
ListOps::identity(cellMap); Foam::identity(cellMap);
// =========================================== // ===========================================
// Adjust vertOffset for all cells // Adjust vertOffset for all cells