Commit 04c8cdf7 authored by Mark Olesen's avatar Mark Olesen
Browse files

ListOps with (const UList<label>&) instead of (const labelList&)

PackedList with (const UList<label>&) instead of (const labelList&)
parent bbb989f8
......@@ -28,7 +28,7 @@ License
// * * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * //
Foam::labelList Foam::invert(const label len, const labelList& map)
Foam::labelList Foam::invert(const label len, const UList<label>& map)
{
labelList inverse(len, -1);
......@@ -40,8 +40,8 @@ Foam::labelList Foam::invert(const label len, const labelList& map)
{
if (inverse[newPos] >= 0)
{
FatalErrorIn("invert(const label, const labelList&)")
<< "Map is not one to one. At index " << i
FatalErrorIn("invert(const label, const UList<label>&)")
<< "Map is not one-to-one. At index " << i
<< " element " << newPos << " has already occurred before"
<< nl << "Please use invertOneToMany instead"
<< abort(FatalError);
......@@ -54,7 +54,11 @@ Foam::labelList Foam::invert(const label len, const labelList& map)
}
Foam::labelListList Foam::invertOneToMany(const label len, const labelList& map)
Foam::labelListList Foam::invertOneToMany
(
const label len,
const UList<label>& map
)
{
labelList nElems(len, 0);
......
......@@ -44,42 +44,42 @@ SourceFiles
namespace Foam
{
//- Renumber the values (not the indices) of a list. List elements <= 0 are
// left as is.
//- Renumber the values (not the indices) of a list.
// List elements < 0 are left as is.
template<class List>
List renumber(const labelList& oldToNew, const List&);
List renumber(const UList<label>& oldToNew, const List&);
//- Inplace renumber the values of a list. List elements <= 0 are
// left as is.
//- Inplace renumber the values of a list.
// List elements < 0 are left as is.
template<class List>
void inplaceRenumber(const labelList& oldToNew, List&);
void inplaceRenumber(const UList<label>& oldToNew, List&);
//- Reorder the elements (indices, not values) of a list.
// List elements <= 0 are left as is.
// List elements < 0 are left as is.
template<class List>
List reorder(const labelList& oldToNew, const List&);
List reorder(const UList<label>& oldToNew, const List&);
//- Inplace reorder the elements of a list.
// List elements <= 0 are left as is.
// List elements < 0 are left as is.
template<class List>
void inplaceReorder(const labelList& oldToNew, List&);
void inplaceReorder(const UList<label>& oldToNew, List&);
// Variants to work with iterators and sparse tables. Need to have iterators
// and insert()
// Variants to work with iterators and sparse tables.
// Need to have iterators and insert()
//- Map values. Do not map negative values.
template<class Container>
void inplaceMapValue(const labelList& oldToNew, Container&);
void inplaceMapValue(const UList<label>& oldToNew, Container&);
//- Recreate with mapped keys. Remove elements with negative key.
template<class Container>
void inplaceMapKey(const labelList& oldToNew, Container&);
void inplaceMapKey(const UList<label>& oldToNew, Container&);
//- Extract elements of List whose region is certain value. Use e.g.
// to extract all selected elements:
// subset<boolList, labelList>(selectedElems, true, lst);
//- 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&);
......@@ -90,10 +90,10 @@ template<class T, class List>
void inplaceSubset(const UList<T>& regions, const T& region, List&);
//- Invert one-to-one map. Unmapped elements will be -1.
labelList invert(const label len, const labelList& oldToNew);
labelList invert(const label len, const UList<label>&);
//- Invert one-to-many map. Unmapped elements will be size 0.
labelListList invertOneToMany(const label len, const labelList&);
labelListList invertOneToMany(const label len, const UList<label>&);
//- Invert many-to-many. Input and output types need to be inherited
// from List. E.g. faces to pointFaces.
......@@ -135,7 +135,7 @@ template<class List>
void setValues
(
List&,
const labelList& indices,
const UList<label>& indices,
typename List::const_reference
);
......@@ -145,7 +145,7 @@ List createWithValues
(
const label sz,
const typename List::const_reference initValue,
const labelList& indices,
const UList<label>& indices,
typename List::const_reference setValue
);
......
......@@ -31,7 +31,7 @@ License
template<class List>
List Foam::renumber
(
const labelList& oldToNew,
const UList<label>& oldToNew,
const List& lst
)
{
......@@ -53,7 +53,7 @@ List Foam::renumber
template<class List>
void Foam::inplaceRenumber
(
const labelList& oldToNew,
const UList<label>& oldToNew,
List& lst
)
{
......@@ -70,7 +70,7 @@ void Foam::inplaceRenumber
template<class List>
List Foam::reorder
(
const labelList& oldToNew,
const UList<label>& oldToNew,
const List& lst
)
{
......@@ -95,7 +95,7 @@ List Foam::reorder
template<class List>
void Foam::inplaceReorder
(
const labelList& oldToNew,
const UList<label>& oldToNew,
List& lst
)
{
......@@ -121,7 +121,7 @@ void Foam::inplaceReorder
template<class Container>
void Foam::inplaceMapValue
(
const labelList& oldToNew,
const UList<label>& oldToNew,
Container& lst
)
{
......@@ -143,7 +143,7 @@ void Foam::inplaceMapValue
template<class Container>
void Foam::inplaceMapKey
(
const labelList& oldToNew,
const UList<label>& oldToNew,
Container& lst
)
{
......@@ -161,7 +161,7 @@ void Foam::inplaceMapKey
newLst.insert(oldToNew[iter.key()], iter());
}
}
lst.transfer(newLst);
}
......@@ -330,7 +330,7 @@ template<class List>
void Foam::setValues
(
List& l,
const labelList& indices,
const UList<label>& indices,
typename List::const_reference t
)
{
......@@ -346,7 +346,7 @@ List Foam::createWithValues
(
const label sz,
const typename List::const_reference initValue,
const labelList& indices,
const UList<label>& indices,
typename List::const_reference setValue
)
{
......@@ -489,31 +489,31 @@ Foam::label Foam::findLower
template<class Container, class T, int nRows>
Foam::List<Container> Foam::initList(const T elems[nRows])
{
List<Container> faces(nRows);
List<Container> lst(nRows);
forAll(faces, faceI)
forAll(lst, rowI)
{
faces[faceI] = Container(elems[faceI]);
lst[rowI] = Container(elems[rowI]);
}
return faces;
return lst;
}
template<class Container, class T, int nRows, int nColumns>
Foam::List<Container> Foam::initListList(const T elems[nRows][nColumns])
{
List<Container> faces(nRows);
List<Container> lst(nRows);
Container f(nColumns);
forAll(faces, faceI)
Container cols(nColumns);
forAll(lst, rowI)
{
forAll(f, i)
forAll(cols, colI)
{
f[i] = elems[faceI][i];
cols[colI] = elems[rowI][colI];
}
faces[faceI] = f;
lst[rowI] = cols;
}
return faces;
return lst;
}
......
......@@ -26,16 +26,10 @@ License
#include "PackedList.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
//- Construct with given size and value for all elements.
template<int nBits>
PackedList<nBits>::PackedList(const label size, const unsigned int val)
Foam::PackedList<nBits>::PackedList(const label size, const unsigned int val)
:
List<unsigned int>(intSize(size)),
size_(size)
......@@ -44,26 +38,23 @@ PackedList<nBits>::PackedList(const label size, const unsigned int val)
}
//- Copy constructor.
template<int nBits>
PackedList<nBits>::PackedList(const PackedList<nBits>& PList)
Foam::PackedList<nBits>::PackedList(const PackedList<nBits>& lst)
:
List<unsigned int>(PList),
size_(PList.size())
List<unsigned int>(lst),
size_(lst.size())
{}
template<int nBits>
PackedList<nBits>::PackedList(const xfer<PackedList<nBits> >& lst)
Foam::PackedList<nBits>::PackedList(const xfer<PackedList<nBits> >& lst)
{
transfer(lst());
}
//- Construct from labelList
template<int nBits>
PackedList<nBits>::PackedList(const labelList& lst)
Foam::PackedList<nBits>::PackedList(const UList<label>& lst)
:
List<unsigned int>(intSize(lst.size()), 0),
size_(lst.size())
......@@ -76,7 +67,7 @@ PackedList<nBits>::PackedList(const labelList& lst)
template<int nBits>
autoPtr<PackedList<nBits> > PackedList<nBits>::clone() const
Foam::autoPtr<Foam::PackedList<nBits> > Foam::PackedList<nBits>::clone() const
{
return autoPtr<PackedList<nBits> >(new PackedList<nBits>(*this));
}
......@@ -84,24 +75,24 @@ autoPtr<PackedList<nBits> > PackedList<nBits>::clone() const
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template <int nBits>
void PackedList<nBits>::setSize(const label size)
template<int nBits>
void Foam::PackedList<nBits>::setSize(const label size)
{
List<unsigned int>::setSize(intSize(size));
size_ = size;
}
template <int nBits>
void PackedList<nBits>::clear()
template<int nBits>
void Foam::PackedList<nBits>::clear()
{
List<unsigned int>::clear();
size_ = 0;
}
template <int nBits>
void PackedList<nBits>::transfer(PackedList<nBits>& lst)
template<int nBits>
void Foam::PackedList<nBits>::transfer(PackedList<nBits>& lst)
{
size_ = lst.size();
List<unsigned int>::transfer(lst);
......@@ -111,16 +102,16 @@ void PackedList<nBits>::transfer(PackedList<nBits>& lst)
// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
// Assignment.
template <int nBits>
void PackedList<nBits>::operator=(const PackedList<nBits>& pl)
template<int nBits>
void Foam::PackedList<nBits>::operator=(const PackedList<nBits>& lst)
{
setSize(pl.size());
List<unsigned int>::operator=(pl);
setSize(lst.size());
List<unsigned int>::operator=(lst);
}
template <int nBits>
labelList PackedList<nBits>::operator()() const
template<int nBits>
Foam::labelList Foam::PackedList<nBits>::operator()() const
{
labelList elems(size());
......@@ -134,17 +125,14 @@ labelList PackedList<nBits>::operator()() const
// * * * * * * * * * * * * * * * Ostream Operator * * * * * * * * * * * * * //
//template <int nBits>
//Ostream& ::Foam::operator<<(Ostream& os, const PackedList<nBits>& PL)
//template<int nBits>
//Foam::Ostream& ::Foam::operator<<(Ostream& os, const PackedList<nBits>& lst)
//{
// os << PL();
// os << lst();
// return os;
//}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// ************************************************************************* //
......@@ -26,7 +26,8 @@ Class
Foam::PackedList
Description
List of packed unsigned ints. Gets given the number of bits per item.
List of packed unsigned ints.
Gets given the number of bits per item.
SourceFiles
PackedListI.H
......@@ -47,14 +48,14 @@ namespace Foam
/*---------------------------------------------------------------------------*\
Class PackedListName Declaration
Class PackedListName Declaration
\*---------------------------------------------------------------------------*/
TemplateName(PackedList);
/*---------------------------------------------------------------------------*\
Class PackedList Declaration
Class PackedList Declaration
\*---------------------------------------------------------------------------*/
//- For PackedList
......@@ -137,8 +138,8 @@ public:
//- Construct by transferring the parameter contents
PackedList(const xfer<PackedList<nBits> >&);
//- Construct from labelList.
PackedList(const labelList&);
//- Construct from a list of labels
PackedList(const UList<label>&);
//- Clone
inline autoPtr<PackedList<nBits> > clone() const;
......
Supports Markdown
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