All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
SortableListDRGEP.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2016-2021 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
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
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
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.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 Class
25  Foam::SortableListDRGEP
26 
27 Description
28  A list that is sorted upon construction or when explicitly requested
29  with the sort() method.
30 
31 SourceFiles
32  SortableListDRGEP.C
33 
34 \*---------------------------------------------------------------------------*/
35 
36 #ifndef SortableListDRGEP_H
37 #define SortableListDRGEP_H
38 
39 #include "labelList.H"
40 
41 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
42 
43 namespace Foam
44 {
45 
46 /*---------------------------------------------------------------------------*\
47  Class SortableListDRGEP Declaration
48 \*---------------------------------------------------------------------------*/
49 
50 template <class Type>
52 :
53  public List<Type>
54 {
55  // Private Data
56 
57  //- Original indices
58  labelList indices_;
59 
60 
61 public:
62 
63  // Public classes
64 
65  //- Less function class used by the sort function
66  class less
67  {
68  const UList<Type>& values_;
69 
70  public:
71 
72  less(const UList<Type>& values)
73  :
74  values_(values)
75  {}
76 
77  bool operator()(const label a, const label b)
78  {
79  return values_[a] < values_[b];
80  }
81  };
82 
83 
84  // Constructors
85 
86  //- Construct from List, sorting the elements. Starts with indices set
87  // to index in argument
88  explicit SortableListDRGEP(const List<Type>&);
89 
90  //- Construct given size. Sort later on.
91  explicit SortableListDRGEP(const label size);
92 
93  //- Construct given size and initial value. Sort later on.
94  SortableListDRGEP(const label size, const Type&);
95 
96  //- Construct as copy.
98 
99 
100  // Member Functions
101 
102  //- Return the list of sorted indices. Updated every sort.
103  const labelList& indices() const
104  {
105  return indices_;
106  }
107 
108  //- Size the list. If grow can cause undefined indices (until next sort)
109  void setSize(const label);
110 
111  //- Sort the list (if changed after construction time)
112  void sort();
113 
114  //- Partial sort the list (if changed after construction time)
115  void partialSort(int M);
116 
117  //- Sort the list (if changed after construction time)
118  void stableSort();
119 
120 
121  // Member Operators
122 
123  void operator=(const SortableListDRGEP<Type>&);
124 
125 };
126 
127 
128 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
129 
130 } // End namespace Foam
131 
132 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
133 
134 #ifdef NoRepository
135  #include "SortableListDRGEP.C"
136 #endif
137 
138 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
139 
140 #endif
141 
142 // ************************************************************************* //
less(const UList< Type > &values)
Less function class used by the sort function.
void sort()
Sort the list (if changed after construction time)
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: HashTable.H:59
SortableListDRGEP(const List< Type > &)
Construct from List, sorting the elements. Starts with indices set.
const dimensionedScalar b
Wien displacement law constant: default SI units: [m K].
Definition: createFields.H:27
A list that is sorted upon construction or when explicitly requested with the sort() method...
void setSize(const label)
Size the list. If grow can cause undefined indices (until next sort)
bool operator()(const label a, const label b)
void operator=(const SortableListDRGEP< Type > &)
const labelList & indices() const
Return the list of sorted indices. Updated every sort.
void partialSort(int M)
Partial sort the list (if changed after construction time)
label size() const
Return the number of elements in the UList.
Definition: ListI.H:171
void stableSort()
Sort the list (if changed after construction time)
#define M(I)
Namespace for OpenFOAM.