1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 1991-2008 OpenCFD Ltd.
7 -------------------------------------------------------------------------------
9 This file is part of OpenFOAM.
11 OpenFOAM is free software; you can redistribute it and/or modify it
12 under the terms of the GNU General Public License as published by the
13 Free Software Foundation; either version 2 of the License, or (at your
14 option) any later version.
16 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 You should have received a copy of the GNU General Public License
22 along with OpenFOAM; if not, write to the Free Software Foundation,
23 Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
29 Various functions to operate on Lists.
35 \*---------------------------------------------------------------------------*/
40 #include "labelList.H"
42 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
47 //- Renumber the values (not the indices) of a list. List elements <= 0 are
50 List renumber(const labelList& oldToNew, const List&);
52 //- Inplace renumber the values of a list. List elements <= 0 are
55 void inplaceRenumber(const labelList& oldToNew, List&);
58 //- Reorder the elements (indices, not values) of a list.
59 // List elements <= 0 are left as is.
61 List reorder(const labelList& oldToNew, const List&);
63 //- Inplace reorder the elements of a list.
64 // List elements <= 0 are left as is.
66 void inplaceReorder(const labelList& oldToNew, List&);
69 // Variants to work with iterators and sparse tables. Need to have iterators
72 //- Map values. Do not map negative values.
73 template<class Container>
74 void inplaceMapValue(const labelList& oldToNew, Container&);
75 //- Recreate with mapped keys. Remove elements with negative key.
76 template<class Container>
77 void inplaceMapKey(const labelList& oldToNew, Container&);
80 //- Extract elements of List whose region is certain value. Use e.g.
81 // to extract all selected elements:
82 // subset<boolList, labelList>(selectedElems, true, lst);
83 template<class T, class List>
84 List subset(const UList<T>& regions, const T& region, const List&);
86 //- Inplace extract elements of List whose region is certain value. Use e.g.
87 // to extract all selected elements:
88 // inplaceSubset<boolList, labelList>(selectedElems, true, lst);
89 template<class T, class List>
90 void inplaceSubset(const UList<T>& regions, const T& region, List&);
92 //- Invert one-to-one map. Unmapped elements will be -1.
93 labelList invert(const label len, const labelList& oldToNew);
95 //- Invert one-to-many map. Unmapped elements will be size 0.
96 labelListList invertOneToMany(const label len, const labelList&);
98 //- Invert many-to-many. Input and output types need to be inherited
99 // from List. E.g. faces to pointFaces.
100 template<class InList, class OutList>
101 void invertManyToMany(const label len, const UList<InList>&, List<OutList>&);
103 template<class InList, class OutList>
104 List<OutList> invertManyToMany(const label len, const UList<InList>& in)
107 invertManyToMany<InList,OutList>(len, in, out);
111 //- Create identity map (map[i] == i) of given length
112 labelList identity(const label len);
114 //- Find first occurence of given element and return index,
115 // return -1 if not found. Linear search.
120 typename List::const_reference,
124 //- Find all occurences of given element. Linear search.
126 labelList findIndices
129 typename List::const_reference,
133 //- Opposite of findIndices: set values at indices to given value
138 const labelList& indices,
139 typename List::const_reference
142 //- Opposite of findIndices: set values at indices to given value
144 List createWithValues
147 const typename List::const_reference initValue,
148 const labelList& indices,
149 typename List::const_reference setValue
152 //- Find index of max element (and larger than given element).
153 // return -1 if not found. Linear search.
155 label findMax(const List&, const label start=0);
158 //- Find index of min element (and less than given element).
159 // return -1 if not found. Linear search.
161 label findMin(const List&, const label start=0);
164 //- Find first occurence of given element in sorted list and return index,
165 // return -1 if not found. Binary search.
167 label findSortedIndex
170 typename List::const_reference,
175 //- Find last element < given value in sorted list and return index,
176 // return -1 if not found. Binary search.
181 typename List::const_reference,
186 //- To construct a List from a C array. Has extra Container type
187 // to initialise e.g. wordList from arrays of char*.
188 template<class Container, class T, int nRows>
189 List<Container> initList(const T[nRows]);
192 //- To construct a (square) ListList from a C array. Has extra Container type
193 // to initialise e.g. faceList from arrays of labels.
194 template<class Container, class T, int nRows, int nColumns>
195 List<Container> initListList(const T[nRows][nColumns]);
198 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
200 } // End namespace Foam
202 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
205 # include "ListOpsTemplates.C"
208 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
212 // ************************************************************************* //