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 -------------------------------------------------------------------------------
10 License
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 
32 template <class Type>
34 :
35  List<Type>(values),
36  indices_(values.size())
37 {
38  sort();
39 }
40 
41 
42 template <class Type>
44 :
45  List<Type>(size),
46  indices_(size)
47 {
48  forAll(indices_, i)
49  {
50  indices_[i] = i;
51  }
52 }
53 
54 
55 template <class Type>
56 Foam::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 
68 template <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 
84 template <class Type>
85 void Foam::SortableListEFA<Type>::setSize(const label newSize)
86 {
87  List<Type>::setSize(newSize);
88  indices_.setSize(newSize);
89 }
90 
91 
92 template <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 
113 template <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 
126 template <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 
149 template <class Type>
151 {
153  indices_ = rhs.indices();
154 }
155 
156 
157 // ************************************************************************* //
OSspecific.H
Functions used by OpenFOAM that are specific to POSIX compliant operating systems and need to be repl...
Foam::SortableListEFA::SortableListEFA
SortableListEFA(const List< Type > &)
Construct from List, sorting the elements. Starts with indices set.
Definition: SortableListEFA.C:33
Foam::SortableListEFA::stableSort
void stableSort()
Sort the list (if changed after construction time)
Definition: SortableListEFA.C:127
Foam::HashTableOps::values
List< T > values(const HashTable< T, Key, Hash > &tbl, const bool doSort=false)
List of values from HashTable, optionally sorted.
Definition: HashOps.H:149
Foam::less
static bool less(const vector &x, const vector &y)
To compare normals.
Definition: meshRefinementRefine.C:57
Foam::SortableListEFA::more
Less function class used by the sort function.
Definition: SortableListEFA.H:67
Foam::SortableListEFA::setSize
void setSize(const label)
Size the list. If grow can cause undefined indices (until next sort)
Definition: SortableListEFA.C:85
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:296
Foam::stableSort
void stableSort(UList< T > &a)
Definition: UList.C:268
Foam::SortableListEFA
A list that is sorted upon construction or when explicitly requested with the sort() method.
Definition: SortableListEFA.H:52
Foam::List::transfer
void transfer(List< T > &list)
Definition: List.C:459
Foam::sort
void sort(UList< T > &a)
Definition: UList.C:254
Foam::List::operator=
void operator=(const UList< T > &a)
Assignment to UList operator. Takes linear time.
Definition: List.C:501
Foam::SortableListEFA::indices
const labelList & indices() const
Return the list of sorted indices. Updated every sort.
Definition: SortableListEFA.H:104
Foam::SortableListEFA::operator=
void operator=(const SortableListEFA< Type > &)
Definition: SortableListEFA.C:150
Foam::SortableListEFA::partialSort
void partialSort(int M, int start)
Partial sort the list (if changed after construction time)
Definition: SortableListEFA.C:114
Foam::List< Type >
M
#define M(I)
Foam::SortableListEFA::sort
void sort()
Sort the list (if changed after construction time)
Definition: SortableListEFA.C:93
Foam::List::setSize
void setSize(const label newSize)
Alias for resize(const label)
Definition: ListI.H:146