OpenFOAM logo
The Open Source CFD Toolbox
  Programmer’s C++ Doxygen OpenCFD Solutions Contact OpenFOAM

ListOps.H

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------------*\
00002   =========                 |
00003   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
00004    \\    /   O peration     |
00005     \\  /    A nd           | Copyright (C) 1991-2007 OpenCFD Ltd.
00006      \\/     M anipulation  |
00007 -------------------------------------------------------------------------------
00008 License
00009     This file is part of OpenFOAM.
00010 
00011     OpenFOAM is free software; you can redistribute it and/or modify it
00012     under the terms of the GNU General Public License as published by the
00013     Free Software Foundation; either version 2 of the License, or (at your
00014     option) any later version.
00015 
00016     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
00017     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00018     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00019     for more details.
00020 
00021     You should have received a copy of the GNU General Public License
00022     along with OpenFOAM; if not, write to the Free Software Foundation,
00023     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
00024 
00025 Class
00026     ListOps
00027 
00028 Description
00029     Various functions to operate on Lists.
00030 
00031 SourceFiles
00032     ListOps.C
00033     ListOpsTemplates.C
00034 
00035 \*---------------------------------------------------------------------------*/
00036 
00037 #ifndef ListOps_H
00038 #define ListOps_H
00039 
00040 #include "labelList.H"
00041 
00042 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00043 
00044 namespace Foam
00045 {
00046 
00047 //- Renumber the values (not the indices) of a list. List elements <= 0 are
00048 //  left as is.
00049 template<class List>
00050 List renumber(const labelList& oldToNew, const List&);
00051 
00052 //- Inplace renumber the values of a list. List elements <= 0 are
00053 //  left as is.
00054 template<class List>
00055 void inplaceRenumber(const labelList& oldToNew, List&);
00056 
00057 
00058 //- Reorder the elements (indices, not values) of a list.
00059 //  List elements <= 0 are left as is.
00060 template<class List>
00061 List reorder(const labelList& oldToNew, const List&);
00062 
00063 //- Inplace reorder the elements of a list.
00064 //  List elements <= 0 are left as is.
00065 template<class List>
00066 void inplaceReorder(const labelList& oldToNew, List&);
00067 
00068 
00069 //- Extract elements of List whose region is certain value. Use e.g.
00070 //  to extract all selected elements: 
00071 //  extract<boolList, labelList>(selectedElems, true, lst);
00072 template<class T, class List>
00073 List extract(const UList<T>& regions, const T& region, const List&);
00074 
00075 //- Invert one-to-one map. Unmapped elements will be -1.
00076 labelList invert(const label len, const labelList& oldToNew);
00077 
00078 //- Invert one-to-many map. Unmapped elements will be size 0.
00079 labelListList invertOneToMany(const label len, const labelList&);
00080 
00081 //- Create identity map (map[i] == i) of given length
00082 labelList identity(const label len);
00083 
00084 //- Find first occurence of given element and return index,
00085 //  return -1 if not found. Linear search.
00086 template<class List>
00087 label findIndex(const List&, typename List::const_reference);
00088 
00089 //- Find all occurences of given element. Linear search.
00090 template<class List>
00091 labelList findIndices(const List&, typename List::const_reference);
00092 
00093 //- Opposite of findIndices: set values at indices to given value
00094 template<class List>
00095 void setValues
00096 (
00097     List&,
00098     const labelList& indices,
00099     typename List::const_reference
00100 );
00101 
00102 //- Opposite of findIndices: set values at indices to given value
00103 template<class List>
00104 List createWithValues
00105 (
00106     const label sz,
00107     const typename List::const_reference initValue,
00108     const labelList& indices,
00109     typename List::const_reference setValue
00110 );
00111 
00112 //- Find index of max element (and larger than given element).
00113 //  return -1 if not found. Linear search.
00114 template<class List>
00115 label findMax(const List&);
00116 
00117 
00118 //- Find index of min element (and less than given element).
00119 //  return -1 if not found. Linear search.
00120 template<class List>
00121 label findMin(const List&);
00122 
00123 
00124 //- Find first occurence of given element in sorted list and return index,
00125 //  return -1 if not found. Binary search.
00126 template<class List>
00127 label findSortedIndex(const List&, typename List::const_reference);
00128 
00129 
00130 //- Find last element < given value in sorted list and return index,
00131 //  return -1 if not found. Binary search.
00132 template<class List>
00133 label findLower(const List&, typename List::const_reference);
00134 
00135 
00136 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00137 
00138 } // End namespace Foam
00139 
00140 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00141 
00142 #ifdef NoRepository
00143 #   include "ListOpsTemplates.C"
00144 #endif
00145 
00146 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00147 
00148 #endif
00149 
00150 // ************************************************************************* //
00151 
Copyright © 2000-2007 OpenCFD Ltd