OpenFOAM logo
Open Source CFD Toolkit

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-2005 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.
00048 template<class List>
00049 List renumber(const labelList& oldToNew, const List&);
00050 
00051 //- Inplace renumber the values of a list.
00052 template<class List>
00053 void inplaceRenumber(const labelList& oldToNew, List&);
00054 
00055 
00056 //- Reorder the elements (indices, not values) of a list. Does not do any
00057 //  check for illegal indices (e.g. -1)
00058 template<class List>
00059 List reorder(const labelList& oldToNew, const List&);
00060 
00061 //- Inplace reorder the elements of a list. Does not do any
00062 //  check for illegal indices.
00063 template<class List>
00064 void inplaceReorder(const labelList& oldToNew, List&);
00065 
00066 
00067 //- Extract elements of List whose region is certain value. Use e.g.
00068 //  to extract all selected elements: 
00069 //  extract<boolList, labelList>(selectedElems, true, lst);
00070 template<class T, class List>
00071 List extract(const UList<T>& regions, const T& region, const List&);
00072 
00073 
00074 //- Invert one-to-one map. Unmapped elements will be -1.
00075 labelList invert(const label len, const labelList& oldToNew);
00076 
00077 //- Invert one-to-many map. Unmapped elements will be size 0.
00078 labelListList invertOneToMany(const label len, const labelList&);
00079 
00080 //- Create identity map (map[i] == i) of given length
00081 labelList identity(const label len);
00082 
00083 //- Find first occurence of given element and return index,
00084 //  return -1 if not found. Linear search.
00085 template<class List>
00086 label findIndex(const List&, typename List::const_reference);
00087 
00088 
00089 //- Find index of max element (and larger than given element).
00090 //  return -1 if not found. Linear search.
00091 template<class List>
00092 label findMax(const List&);
00093 
00094 
00095 //- Find index of min element (and less than given element).
00096 //  return -1 if not found. Linear search.
00097 template<class List>
00098 label findMin(const List&);
00099 
00100 
00101 //- Find first occurence of given element in sorted list and return index,
00102 //  return -1 if not found. Binary search.
00103 template<class List>
00104 label findSortedIndex(const List&, typename List::const_reference);
00105 
00106 
00107 //- Find last element < given value in sorted list and return index,
00108 //  return -1 if not found. Binary search.
00109 template<class List>
00110 label findLower(const List&, typename List::const_reference);
00111 
00112 
00113 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00114 
00115 } // End namespace Foam
00116 
00117 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00118 
00119 #ifdef NoRepository
00120 #   include "ListOpsTemplates.C"
00121 #endif
00122 
00123 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00124 
00125 #endif
00126 
00127 // ************************************************************************* //
00128 
For further information go to www.openfoam.org