SortableListEFA.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-2020 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::SortableListEFA
26 
27 Description
28  A list that is sorted upon construction or when explicitly requested
29  with the sort() method.
30 
31 SourceFiles
32  SortableListEFA.C
33 
34 \*---------------------------------------------------------------------------*/
35 
36 #ifndef SortableListEFA_H
37 #define SortableListEFA_H
38 
39 #include "labelList.H"
40 
41 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
42 
43 namespace Foam
44 {
45 
46 /*---------------------------------------------------------------------------*\
47  Class SortableListEFA Declaration
48 \*---------------------------------------------------------------------------*/
49 
50 template <class Type>
51 class SortableListEFA
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 more
67  {
68  const UList<Type>& values_;
69 
70  public:
71 
72  more(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 SortableListEFA(const List<Type>&);
89 
90  //- Construct given size. Sort later on.
91  explicit SortableListEFA(const label size);
92 
93  //- Construct given size and initial value. Sort later on.
94  SortableListEFA(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, int start);
116 
117  //- Sort the list (if changed after construction time)
118  void stableSort();
119 
120 
121  // Member Operators
122 
123  void operator=(const SortableListEFA<Type>&);
124 };
125 
126 
127 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
128 
129 } // End namespace Foam
130 
131 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
132 
133 #ifdef NoRepository
134  #include "SortableListEFA.C"
135 #endif
136 
137 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
138 
139 #endif
140 
141 // ************************************************************************* //
bool operator()(const label a, const label b)
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
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
SortableListEFA(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...
const labelList & indices() const
Return the list of sorted indices. Updated every sort.
void operator=(const SortableListEFA< Type > &)
Less function class used by the sort function.
void setSize(const label)
Size the list. If grow can cause undefined indices (until next sort)
more(const UList< Type > &values)
void partialSort(int M, int start)
Partial sort the list (if changed after construction time)
void stableSort()
Sort the list (if changed after construction time)
label size() const
Return the number of elements in the UList.
Definition: ListI.H:171
#define M(I)
Namespace for OpenFOAM.
void sort()
Sort the list (if changed after construction time)