SortableListEFA.C
Go to the documentation of this file.
1/*---------------------------------------------------------------------------*\
2 ========= |
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4 \\ / O peration |
5 \\ / A nd | www.openfoam.com
6 \\/ M anipulation |
7-------------------------------------------------------------------------------
8 Copyright (C) 2016 OpenFOAM Foundation
9-------------------------------------------------------------------------------
10License
11 This file is part of OpenFOAM.
12
13 OpenFOAM is free software: you can redistribute it and/or modify it
14 under the terms of the GNU General Public License as published by
15 the Free Software Foundation, either version 3 of the License, or
16 (at your option) any later version.
17
18 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 for more details.
22
23 You should have received a copy of the GNU General Public License
24 along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25
26\*---------------------------------------------------------------------------*/
27
28#include "OSspecific.H"
29
30// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
31
32template <class Type>
34:
35 List<Type>(values),
36 indices_(values.size())
37{
38 sort();
39}
40
41
42template <class Type>
44:
45 List<Type>(size),
46 indices_(size)
47{
48 forAll(indices_, i)
49 {
50 indices_[i] = i;
51 }
52}
53
54
55template <class Type>
56Foam::SortableListEFA<Type>::SortableListEFA(const label size, const Type& val)
57:
58 List<Type>(size, val),
59 indices_(size)
60{
61 forAll(indices_, i)
62 {
63 indices_[i] = i;
64 }
65}
66
67
68template <class Type>
70:
71 List<Type>(lst),
72 indices_(lst.indices())
73{
74 forAll(indices_, i)
75 {
76 indices_[i] = i;
77 }
78
79}
80
81
82// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
83
84template <class Type>
85void Foam::SortableListEFA<Type>::setSize(const label newSize)
86{
87 List<Type>::setSize(newSize);
88 indices_.setSize(newSize);
89}
90
91
92template <class Type>
94{
95 forAll(indices_, i)
96 {
97 indices_[i] = i;
98 }
99
100 Foam::sort(indices_, less(*this));
101
102 List<Type> tmpValues(this->size());
103
104 forAll(indices_, i)
105 {
106 tmpValues[i] = this->operator[](indices_[i]);
107 }
108
109 List<Type>::transfer(tmpValues);
110}
111
112
113template <class Type>
115{
116 std::partial_sort
117 (
118 indices_.begin()+start,
119 indices_.begin()+start+M,
120 indices_.end(),
121 more(*this)
122 );
123}
124
125
126template <class Type>
128{
129 forAll(indices_, i)
130 {
131 indices_[i] = i;
132 }
133
134 Foam::stableSort(indices_, less(*this));
135
136 List<Type> tmpValues(this->size());
137
138 forAll(indices_, i)
139 {
140 tmpValues[i] = this->operator[](indices_[i]);
141 }
142
143 List<Type>::transfer(tmpValues);
144}
145
146
147// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
148
149template <class Type>
151{
153 indices_ = rhs.indices();
154}
155
156
157// ************************************************************************* //
Functions used by OpenFOAM that are specific to POSIX compliant operating systems and need to be repl...
#define M(I)
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: List.H:77
void setSize(const label n)
Alias for resize()
Definition: List.H:218
void operator=(const UList< T > &a)
Assignment to UList operator. Takes linear time.
Definition: List.C:480
Less function class used by the sort function.
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 stableSort()
Sort the list (if changed after construction time)
void operator=(const SortableListEFA< Type > &)
void sort()
Sort the list (if changed after construction time)
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)
static bool less(const vector &x, const vector &y)
To compare normals.
void sort(UList< T > &list)
Sort the list.
Definition: UList.C:342
void stableSort(UList< T > &list)
Stable sort the list.
Definition: UList.C:356
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:333