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

PackedList with (const UList<label>&) instead of (const labelList&)
This commit is contained in:
Mark Olesen 2008-11-18 11:02:25 +01:00
parent bbb989f8cd
commit 04c8cdf729
5 changed files with 77 additions and 84 deletions

View File

@ -28,7 +28,7 @@ License
// * * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * 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); labelList inverse(len, -1);
@ -40,8 +40,8 @@ Foam::labelList Foam::invert(const label len, const labelList& map)
{ {
if (inverse[newPos] >= 0) if (inverse[newPos] >= 0)
{ {
FatalErrorIn("invert(const label, const labelList&)") FatalErrorIn("invert(const label, const UList<label>&)")
<< "Map is not one to one. At index " << i << "Map is not one-to-one. At index " << i
<< " element " << newPos << " has already occurred before" << " element " << newPos << " has already occurred before"
<< nl << "Please use invertOneToMany instead" << nl << "Please use invertOneToMany instead"
<< abort(FatalError); << 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); labelList nElems(len, 0);

View File

@ -44,41 +44,41 @@ SourceFiles
namespace Foam namespace Foam
{ {
//- Renumber the values (not the indices) of a list. List elements <= 0 are //- Renumber the values (not the indices) of a list.
// left as is. // List elements < 0 are left as is.
template<class List> 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 //- Inplace renumber the values of a list.
// left as is. // List elements < 0 are left as is.
template<class List> 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. //- 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> 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. //- Inplace reorder the elements of a list.
// List elements <= 0 are left as is. // List elements < 0 are left as is.
template<class List> 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 // Variants to work with iterators and sparse tables.
// and insert() // Need to have iterators and insert()
//- Map values. Do not map negative values. //- Map values. Do not map negative values.
template<class Container> 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. //- Recreate with mapped keys. Remove elements with negative key.
template<class Container> 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. //- Extract elements of List whose region is certain value.
// to extract all selected elements: // Use e.g. to extract all selected elements:
// subset<boolList, labelList>(selectedElems, true, lst); // subset<boolList, labelList>(selectedElems, true, lst);
template<class T, class List> template<class T, class List>
List subset(const UList<T>& regions, const T& region, const 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&); void inplaceSubset(const UList<T>& regions, const T& region, List&);
//- Invert one-to-one map. Unmapped elements will be -1. //- 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. //- 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 //- Invert many-to-many. Input and output types need to be inherited
// from List. E.g. faces to pointFaces. // from List. E.g. faces to pointFaces.
@ -135,7 +135,7 @@ template<class List>
void setValues void setValues
( (
List&, List&,
const labelList& indices, const UList<label>& indices,
typename List::const_reference typename List::const_reference
); );
@ -145,7 +145,7 @@ List createWithValues
( (
const label sz, const label sz,
const typename List::const_reference initValue, const typename List::const_reference initValue,
const labelList& indices, const UList<label>& indices,
typename List::const_reference setValue typename List::const_reference setValue
); );

View File

@ -31,7 +31,7 @@ License
template<class List> template<class List>
List Foam::renumber List Foam::renumber
( (
const labelList& oldToNew, const UList<label>& oldToNew,
const List& lst const List& lst
) )
{ {
@ -53,7 +53,7 @@ List Foam::renumber
template<class List> template<class List>
void Foam::inplaceRenumber void Foam::inplaceRenumber
( (
const labelList& oldToNew, const UList<label>& oldToNew,
List& lst List& lst
) )
{ {
@ -70,7 +70,7 @@ void Foam::inplaceRenumber
template<class List> template<class List>
List Foam::reorder List Foam::reorder
( (
const labelList& oldToNew, const UList<label>& oldToNew,
const List& lst const List& lst
) )
{ {
@ -95,7 +95,7 @@ List Foam::reorder
template<class List> template<class List>
void Foam::inplaceReorder void Foam::inplaceReorder
( (
const labelList& oldToNew, const UList<label>& oldToNew,
List& lst List& lst
) )
{ {
@ -121,7 +121,7 @@ void Foam::inplaceReorder
template<class Container> template<class Container>
void Foam::inplaceMapValue void Foam::inplaceMapValue
( (
const labelList& oldToNew, const UList<label>& oldToNew,
Container& lst Container& lst
) )
{ {
@ -143,7 +143,7 @@ void Foam::inplaceMapValue
template<class Container> template<class Container>
void Foam::inplaceMapKey void Foam::inplaceMapKey
( (
const labelList& oldToNew, const UList<label>& oldToNew,
Container& lst Container& lst
) )
{ {
@ -330,7 +330,7 @@ template<class List>
void Foam::setValues void Foam::setValues
( (
List& l, List& l,
const labelList& indices, const UList<label>& indices,
typename List::const_reference t typename List::const_reference t
) )
{ {
@ -346,7 +346,7 @@ List Foam::createWithValues
( (
const label sz, const label sz,
const typename List::const_reference initValue, const typename List::const_reference initValue,
const labelList& indices, const UList<label>& indices,
typename List::const_reference setValue typename List::const_reference setValue
) )
{ {
@ -489,31 +489,31 @@ Foam::label Foam::findLower
template<class Container, class T, int nRows> template<class Container, class T, int nRows>
Foam::List<Container> Foam::initList(const T elems[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> template<class Container, class T, int nRows, int nColumns>
Foam::List<Container> Foam::initListList(const T elems[nRows][nColumns]) Foam::List<Container> Foam::initListList(const T elems[nRows][nColumns])
{ {
List<Container> faces(nRows); List<Container> lst(nRows);
Container f(nColumns); Container cols(nColumns);
forAll(faces, faceI) 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;
} }

View File

@ -26,16 +26,10 @@ License
#include "PackedList.H" #include "PackedList.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
//- Construct with given size and value for all elements.
template<int nBits> 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)), List<unsigned int>(intSize(size)),
size_(size) size_(size)
@ -44,26 +38,23 @@ PackedList<nBits>::PackedList(const label size, const unsigned int val)
} }
//- Copy constructor.
template<int nBits> template<int nBits>
PackedList<nBits>::PackedList(const PackedList<nBits>& PList) Foam::PackedList<nBits>::PackedList(const PackedList<nBits>& lst)
: :
List<unsigned int>(PList), List<unsigned int>(lst),
size_(PList.size()) size_(lst.size())
{} {}
template<int nBits> template<int nBits>
PackedList<nBits>::PackedList(const xfer<PackedList<nBits> >& lst) Foam::PackedList<nBits>::PackedList(const xfer<PackedList<nBits> >& lst)
{ {
transfer(lst()); transfer(lst());
} }
//- Construct from labelList
template<int nBits> template<int nBits>
PackedList<nBits>::PackedList(const labelList& lst) Foam::PackedList<nBits>::PackedList(const UList<label>& lst)
: :
List<unsigned int>(intSize(lst.size()), 0), List<unsigned int>(intSize(lst.size()), 0),
size_(lst.size()) size_(lst.size())
@ -76,7 +67,7 @@ PackedList<nBits>::PackedList(const labelList& lst)
template<int nBits> 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)); return autoPtr<PackedList<nBits> >(new PackedList<nBits>(*this));
} }
@ -85,7 +76,7 @@ autoPtr<PackedList<nBits> > PackedList<nBits>::clone() const
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<int nBits> template<int nBits>
void PackedList<nBits>::setSize(const label size) void Foam::PackedList<nBits>::setSize(const label size)
{ {
List<unsigned int>::setSize(intSize(size)); List<unsigned int>::setSize(intSize(size));
size_ = size; size_ = size;
@ -93,7 +84,7 @@ void PackedList<nBits>::setSize(const label size)
template<int nBits> template<int nBits>
void PackedList<nBits>::clear() void Foam::PackedList<nBits>::clear()
{ {
List<unsigned int>::clear(); List<unsigned int>::clear();
size_ = 0; size_ = 0;
@ -101,7 +92,7 @@ void PackedList<nBits>::clear()
template<int nBits> template<int nBits>
void PackedList<nBits>::transfer(PackedList<nBits>& lst) void Foam::PackedList<nBits>::transfer(PackedList<nBits>& lst)
{ {
size_ = lst.size(); size_ = lst.size();
List<unsigned int>::transfer(lst); List<unsigned int>::transfer(lst);
@ -112,15 +103,15 @@ void PackedList<nBits>::transfer(PackedList<nBits>& lst)
// Assignment. // Assignment.
template<int nBits> template<int nBits>
void PackedList<nBits>::operator=(const PackedList<nBits>& pl) void Foam::PackedList<nBits>::operator=(const PackedList<nBits>& lst)
{ {
setSize(pl.size()); setSize(lst.size());
List<unsigned int>::operator=(pl); List<unsigned int>::operator=(lst);
} }
template<int nBits> template<int nBits>
labelList PackedList<nBits>::operator()() const Foam::labelList Foam::PackedList<nBits>::operator()() const
{ {
labelList elems(size()); labelList elems(size());
@ -135,16 +126,13 @@ labelList PackedList<nBits>::operator()() const
// * * * * * * * * * * * * * * * Ostream Operator * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Ostream Operator * * * * * * * * * * * * * //
//template<int nBits> //template<int nBits>
//Ostream& ::Foam::operator<<(Ostream& os, const PackedList<nBits>& PL) //Foam::Ostream& ::Foam::operator<<(Ostream& os, const PackedList<nBits>& lst)
//{ //{
// os << PL(); // os << lst();
// return os; // return os;
//} //}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// ************************************************************************* // // ************************************************************************* //

View File

@ -26,7 +26,8 @@ Class
Foam::PackedList Foam::PackedList
Description 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 SourceFiles
PackedListI.H PackedListI.H
@ -137,8 +138,8 @@ public:
//- Construct by transferring the parameter contents //- Construct by transferring the parameter contents
PackedList(const xfer<PackedList<nBits> >&); PackedList(const xfer<PackedList<nBits> >&);
//- Construct from labelList. //- Construct from a list of labels
PackedList(const labelList&); PackedList(const UList<label>&);
//- Clone //- Clone
inline autoPtr<PackedList<nBits> > clone() const; inline autoPtr<PackedList<nBits> > clone() const;