All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
SortableListDRGEP.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-2018 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 #include <algorithm>
28 
29 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
30 
31 template <class Type>
33 :
34  List<Type>(values),
35  indices_(values.size())
36 {
37  sort();
38 }
39 
40 
41 template <class Type>
43 :
44  List<Type>(size),
45  indices_(size)
46 {}
47 
48 
49 template <class Type>
51 (
52  const label size,
53  const Type& val
54 )
55 :
56  List<Type>(size, val),
57  indices_(size)
58 {}
59 
60 
61 template <class Type>
63 (
64  const SortableListDRGEP<Type>& lst
65 )
66 :
67  List<Type>(lst),
68  indices_(lst.indices())
69 {}
70 
71 
72 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
73 
74 template <class Type>
76 {
77  List<Type>::setSize(newSize);
78  indices_.setSize(newSize);
79 }
80 
81 
82 template <class Type>
84 {
85  forAll(indices_, i)
86  {
87  indices_[i] = i;
88  }
89 
90  Foam::sort(indices_, less(*this));
91 
92  List<Type> tmpValues(this->size());
93 
94  forAll(indices_, i)
95  {
96  tmpValues[i] = this->operator[](indices_[i]);
97  }
98 
99  List<Type>::transfer(tmpValues);
100 }
101 
102 
103 template <class Type>
105 {
106  forAll(indices_, i)
107  {
108  indices_[i] = i;
109  }
110 
111  std::partial_sort
112  (
113  indices_.begin(),
114  indices_.begin()+M,
115  indices_.end(),
116  less(*this)
117  );
118 }
119 
120 
121 template <class Type>
123 {
124  forAll(indices_, i)
125  {
126  indices_[i] = i;
127  }
128 
129  Foam::stableSort(indices_, less(*this));
130 
131  List<Type> tmpValues(this->size());
132 
133  forAll(indices_, i)
134  {
135  tmpValues[i] = this->operator[](indices_[i]);
136  }
137 
138  List<Type>::transfer(tmpValues);
139 }
140 
141 
142 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
143 
144 template <class Type>
145 void
147 {
149  indices_ = rhs.indices();
150 }
151 
152 
153 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
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()
Sort the list (if changed after construction time)
Type & operator[](const label)
Return element of UList.
Definition: UListI.H:167
SortableListDRGEP(const List< Type > &)
Construct from List, sorting the elements. Starts with indices set.
A list that is sorted upon construction or when explicitly requested with the sort() method...
iterator end()
Return an iterator to end traversing the UList.
Definition: UListI.H:237
static bool less(const vector &x, const vector &y)
To compare normals.
Functions used by OpenFOAM that are specific to POSIX compliant operating systems and need to be repl...
void sort(UList< T > &)
Definition: UList.C:115
iterator begin()
Return an iterator to begin traversing the UList.
Definition: UListI.H:216
void setSize(const label)
Size the list. If grow can cause undefined indices (until next sort)
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
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)
void stableSort(UList< T > &)
Definition: UList.C:129
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)
void transfer(List< T > &)
Transfer the contents of the argument List into this list.
Definition: List.C:342
#define M(I)