SortableListEFA.C
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 \*---------------------------------------------------------------------------*/
25 
26 #include "OSspecific.H"
27 
28 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
29 
30 template <class Type>
32 :
33  List<Type>(values),
34  indices_(values.size())
35 {
36  sort();
37 }
38 
39 
40 template <class Type>
42 :
43  List<Type>(size),
44  indices_(size)
45 {
46  forAll(indices_, i)
47  {
48  indices_[i] = i;
49  }
50 }
51 
52 
53 template <class Type>
55 :
56  List<Type>(size, val),
57  indices_(size)
58 {
59  forAll(indices_, i)
60  {
61  indices_[i] = i;
62  }
63 }
64 
65 
66 template <class Type>
68 :
69  List<Type>(lst),
70  indices_(lst.indices())
71 {
72  forAll(indices_, i)
73  {
74  indices_[i] = i;
75  }
76 
77 }
78 
79 
80 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
81 
82 template <class Type>
84 {
85  List<Type>::setSize(newSize);
86  indices_.setSize(newSize);
87 }
88 
89 
90 template <class Type>
92 {
93  forAll(indices_, i)
94  {
95  indices_[i] = i;
96  }
97 
98  Foam::sort(indices_, less(*this));
99 
100  List<Type> tmpValues(this->size());
101 
102  forAll(indices_, i)
103  {
104  tmpValues[i] = this->operator[](indices_[i]);
105  }
106 
107  List<Type>::transfer(tmpValues);
108 }
109 
110 
111 template <class Type>
113 {
114  std::partial_sort
115  (
116  indices_.begin()+start,
117  indices_.begin()+start+M,
118  indices_.end(),
119  more(*this)
120  );
121 }
122 
123 
124 template <class Type>
126 {
127  forAll(indices_, i)
128  {
129  indices_[i] = i;
130  }
131 
132  Foam::stableSort(indices_, less(*this));
133 
134  List<Type> tmpValues(this->size());
135 
136  forAll(indices_, i)
137  {
138  tmpValues[i] = this->operator[](indices_[i]);
139  }
140 
141  List<Type>::transfer(tmpValues);
142 }
143 
144 
145 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
146 
147 template <class Type>
149 {
151  indices_ = rhs.indices();
152 }
153 
154 
155 // ************************************************************************* //
Functions used by OpenFOAM that are specific to POSIX compliant operating systems and need to be repl...
#define M(I)
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
void transfer(List< T > &)
Transfer the contents of the argument List into this list.
Definition: List.C:342
void operator=(const UList< T > &)
Assignment to UList operator. Takes linear time.
Definition: List.C:376
void setSize(const label)
Reset size of List.
Definition: List.C:281
Less function class used by the sort function.
A list that is sorted upon construction or when explicitly requested with the sort() method.
void stableSort()
Sort the list (if changed after construction time)
const labelList & indices() const
Return the list of sorted indices. Updated every sort.
void operator=(const SortableListEFA< Type > &)
void sort()
Sort the list (if changed after construction time)
SortableListEFA(const List< Type > &)
Construct from List, sorting the elements. Starts with indices set.
void partialSort(int M, int start)
Partial sort the list (if changed after construction time)
void setSize(const label)
Size the list. If grow can cause undefined indices (until next sort)
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
void sort(UList< T > &)
Definition: UList.C:115
static bool less(const vector &x, const vector &y)
To compare normals.
void stableSort(UList< T > &)
Definition: UList.C:129