1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | foam-extend: Open Source CFD
4 \\ / O peration | Version: 3.2
5 \\ / A nd | Web: http://www.foam-extend.org
6 \\/ M anipulation | For copyright notice see file Copyright
7 -------------------------------------------------------------------------------
9 This file is part of foam-extend.
11 foam-extend is free software: you can redistribute it and/or modify it
12 under the terms of the GNU General Public License as published by the
13 Free Software Foundation, either version 3 of the License, or (at your
14 option) any later version.
16 foam-extend is distributed in the hope that it will be useful, but
17 WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with foam-extend. If not, see <http://www.gnu.org/licenses/>.
28 Priority list with changing priorities for inserted elements.
29 List is sorted on access to produce element index with highest weight
32 Hrvoje Jasak, Wikki Ltd. All rights reserved
35 R. Sedgewick, "Algorithms", Addison-Wesley, Reading, MA, 2nd edition, 1988.
40 \*---------------------------------------------------------------------------*/
42 #ifndef PriorityList_H
43 #define PriorityList_H
47 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
52 /*---------------------------------------------------------------------------*\
53 Class PriorityList Declaration
54 \*---------------------------------------------------------------------------*/
61 //- Indices into weights
68 labelList sortedIndices_;
73 //- Is the list sorted?
74 mutable bool listSorted_;
77 // Private static functions
79 //- Greater element comparison
80 inline static bool greater(const Type& a, const Type& b)
86 // Private Member Functions
88 //- Disallow default bitwise copy construct
89 PriorityList(const PriorityList<Type>&);
91 //- Disallow default bitwise assignment
92 void operator=(const PriorityList<Type>&);
99 void bisectionSort(const label startIndex);
101 //- Sort upwards using bisection with root i
102 void sortUpwards(const label startIndex);
109 //- Construct given capacity
110 PriorityList(const label capacity);
113 // Destructor - default
124 //- Is the list empty?
131 const labelList& indices() const
137 const List<Type>& weights() const
143 //- Return index with highest weight and remove
146 //- Set element with weight
147 void set(const label i, const Type& value);
150 void updateWeight(const label i, const Type& newWeight);
154 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
156 } // End namespace Foam
158 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
161 # include "PriorityList.C"
164 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
168 // ************************************************************************* //