initial commit for version 1.5.x patch release
[OpenFOAM-1.5.x.git] / src / OpenFOAM / containers / Lists / ListOps / ListOps.H
blob61eeca7ff8da5379349c4171eb91b52526ffe190
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 1991-2008 OpenCFD Ltd.
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
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
19     for more details.
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
25 InNamspace
26     Foam
28 Description
29     Various functions to operate on Lists.
31 SourceFiles
32     ListOps.C
33     ListOpsTemplates.C
35 \*---------------------------------------------------------------------------*/
37 #ifndef ListOps_H
38 #define ListOps_H
40 #include "labelList.H"
42 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
44 namespace Foam
47 //- Renumber the values (not the indices) of a list. List elements <= 0 are
48 //  left as is.
49 template<class List>
50 List renumber(const labelList& oldToNew, const List&);
52 //- Inplace renumber the values of a list. List elements <= 0 are
53 //  left as is.
54 template<class List>
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.
60 template<class List>
61 List reorder(const labelList& oldToNew, const List&);
63 //- Inplace reorder the elements of a list.
64 //  List elements <= 0 are left as is.
65 template<class List>
66 void inplaceReorder(const labelList& oldToNew, List&);
69 // Variants to work with iterators and sparse tables. Need to have iterators
70 // and insert()
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)
106     List<OutList> out;
107     invertManyToMany<InList,OutList>(len, in, out);
108     return 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.
116 template<class List>
117 label findIndex
119     const List&,
120     typename List::const_reference,
121     const label start=0
124 //- Find all occurences of given element. Linear search.
125 template<class List>
126 labelList findIndices
128     const List&,
129     typename List::const_reference,
130     const label start=0
133 //- Opposite of findIndices: set values at indices to given value
134 template<class List>
135 void setValues
137     List&,
138     const labelList& indices,
139     typename List::const_reference
142 //- Opposite of findIndices: set values at indices to given value
143 template<class List>
144 List createWithValues
146     const label sz,
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.
154 template<class List>
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.
160 template<class List>
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.
166 template<class List>
167 label findSortedIndex
169     const List&,
170     typename List::const_reference,
171     const label start=0
175 //- Find last element < given value in sorted list and return index,
176 //  return -1 if not found. Binary search.
177 template<class List>
178 label findLower
180     const List&,
181     typename List::const_reference,
182     const label start=0
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 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
204 #ifdef NoRepository
205 #   include "ListOpsTemplates.C"
206 #endif
208 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
210 #endif
212 // ************************************************************************* //