SortableList.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 | Copyright (C) 2011-2013 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 "ListOps.H"
27 
28 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
29 
30 template<class T>
32 {}
33 
34 
35 template<class T>
37 :
38  List<T>(values)
39 {
40  sort();
41 }
42 
43 
44 template<class T>
46 :
47  List<T>(values)
48 {
49  sort();
50 }
51 
52 
53 template<class T>
55 :
56  List<T>(size)
57 {}
58 
59 
60 template<class T>
62 :
63  List<T>(size, val)
64 {}
65 
66 
67 template<class T>
69 :
70  List<T>(lst),
71  indices_(lst.indices())
72 {}
73 
74 
75 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
76 
77 
78 template<class T>
80 {
82  indices_.clear();
83 }
84 
85 
86 template<class T>
88 {
89  indices_.clear();
90  return static_cast<List<T>&>(*this);
91 }
92 
93 
94 template<class T>
96 {
97  sortedOrder(*this, indices_);
98 
99  List<T> lst(this->size());
100  forAll(indices_, i)
101  {
102  lst[i] = this->operator[](indices_[i]);
103  }
104 
105  List<T>::transfer(lst);
106 }
107 
108 
109 template<class T>
111 {
112  sortedOrder(*this, indices_, typename UList<T>::greater(*this));
113 
114  List<T> lst(this->size());
115  forAll(indices_, i)
116  {
117  lst[i] = this->operator[](indices_[i]);
118  }
119 
120  List<T>::transfer(lst);
121 }
122 
123 
124 template<class T>
126 {
127  return xferMoveTo<List<T> >(*this);
128 }
129 
130 
131 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
132 
133 template<class T>
134 inline void Foam::SortableList<T>::operator=(const T& t)
135 {
137 }
138 
139 
140 template<class T>
142 {
143  List<T>::operator=(rhs);
144  indices_.clear();
145 }
146 
147 
148 template<class T>
150 {
151  List<T>::operator=(rhs);
152  indices_ = rhs.indices();
153 }
154 
155 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
156 
157 // ************************************************************************* //
const labelList & indices() const
Return the list of sorted indices. Updated every sort.
Definition: SortableList.H:90
Greater function class that can be used for sorting.
Definition: UList.H:117
void transfer(List< T > &)
Transfer the contents of the argument List into this list.
Definition: List.C:390
void T(FieldField< Field, Type > &f1, const FieldField< Field, Type > &f2)
void sortedOrder(const UList< T > &, labelList &order)
Generate the (stable) sort order for the list.
A simple container for copying or transferring objects of type <T>.
Definition: Xfer.H:85
void operator=(const T &)
Assignment of all entries to the given value.
Definition: SortableList.C:134
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
Various functions to operate on Lists.
void sort()
(stable) sort the list (if changed after construction time)
Definition: SortableList.C:95
const volScalarField & T
Definition: createFields.H:25
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
T & operator[](const label)
Return element of UList.
Definition: UListI.H:163
void clear()
Clear the list, i.e. set size to zero.
Definition: List.C:379
void reverseSort()
Reverse (stable) sort the list.
Definition: SortableList.C:110
void clear()
Clear the list and the indices.
Definition: SortableList.C:79
A list that is sorted upon construction or when explicitly requested with the sort() method...
Definition: List.H:65
#define forAll(list, i)
Definition: UList.H:421
Xfer< List< T > > xfer()
Transfer contents to the Xfer container as a plain List.
Definition: SortableList.C:125
void operator=(const T &)
Assignment of all entries to the given value.
Definition: UList.C:70
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
Definition: HashTable.H:60
label size() const
Return the number of elements in the UList.
Definition: ListI.H:83
SortableList()
Null constructor, sort later (eg, after assignment or transfer)
Definition: SortableList.C:31
List< T > & shrink()
Clear the indices and return a reference to the underlying List.
Definition: SortableList.C:87
void operator=(const UList< T > &)
Assignment from UList operator. Takes linear time.
Definition: List.C:429