VTK  9.1.0
vtkPriorityQueue.h
Go to the documentation of this file.
1/*=========================================================================
2
3 Program: Visualization Toolkit
4 Module: vtkPriorityQueue.h
5
6 Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
7 All rights reserved.
8 See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
9
10 This software is distributed WITHOUT ANY WARRANTY; without even
11 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12 PURPOSE. See the above copyright notice for more information.
13
14=========================================================================*/
38#ifndef vtkPriorityQueue_h
39#define vtkPriorityQueue_h
40
41#include "vtkCommonCoreModule.h" // For export macro
42#include "vtkObject.h"
43
44#include "vtkIdTypeArray.h" // Needed for inline methods
45
46class VTKCOMMONCORE_EXPORT vtkPriorityQueue : public vtkObject
47{
48public:
49 class Item
50 {
51 public:
52 double priority;
54 };
55
60
62 void PrintSelf(ostream& os, vtkIndent indent) override;
63
67 void Allocate(vtkIdType sz, vtkIdType ext = 1000);
68
73 void Insert(double priority, vtkIdType id);
74
81 vtkIdType Pop(vtkIdType location, double& priority);
82
87 vtkIdType Pop(vtkIdType location = 0);
88
93 vtkIdType Peek(vtkIdType location, double& priority);
94
99 vtkIdType Peek(vtkIdType location = 0);
100
105 double DeleteId(vtkIdType id);
106
111 double GetPriority(vtkIdType id);
112
116 vtkIdType GetNumberOfItems() { return this->MaxId + 1; }
117
122 void Reset();
123
124protected:
127
129
135
136private:
137 vtkPriorityQueue(const vtkPriorityQueue&) = delete;
138 void operator=(const vtkPriorityQueue&) = delete;
139};
140
142{
143 double priority = VTK_DOUBLE_MAX;
144 vtkIdType loc;
145
146 if (id <= this->ItemLocation->GetMaxId() && (loc = this->ItemLocation->GetValue(id)) != -1)
147 {
148 this->Pop(loc, priority);
149 }
150 return priority;
151}
152
154{
155 vtkIdType loc;
156
157 if (id <= this->ItemLocation->GetMaxId() && (loc = this->ItemLocation->GetValue(id)) != -1)
158 {
159 return this->Array[loc].priority;
160 }
161 return VTK_DOUBLE_MAX;
162}
163
164inline vtkIdType vtkPriorityQueue::Peek(vtkIdType location, double& priority)
165{
166 if (this->MaxId < 0)
167 {
168 return -1;
169 }
170 else
171 {
172 priority = this->Array[location].priority;
173 return this->Array[location].id;
174 }
175}
176
178{
179 if (this->MaxId < 0)
180 {
181 return -1;
182 }
183 else
184 {
185 return this->Array[location].id;
186 }
187}
188
189#endif
vtkIdType GetMaxId() const
What is the maximum id currently in the array.
dynamic, self-adjusting array of vtkIdType
a simple class to control print indentation
Definition: vtkIndent.h:113
abstract base class for most VTK objects
Definition: vtkObject.h:82
a list of ids arranged in priority order
static vtkPriorityQueue * New()
Instantiate priority queue with default size and extension size of 1000.
double GetPriority(vtkIdType id)
Get the priority of an entry in the queue with specified id.
void Insert(double priority, vtkIdType id)
Insert id with priority specified.
void Reset()
Empty the queue but without releasing memory.
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
vtkIdType GetNumberOfItems()
Return the number of items in this queue.
~vtkPriorityQueue() override
vtkIdType Pop(vtkIdType location=0)
Same as above but simplified for easier wrapping into interpreted languages.
vtkIdType Peek(vtkIdType location, double &priority)
Peek into the queue without actually removing anything.
vtkIdTypeArray * ItemLocation
vtkIdType Pop(vtkIdType location, double &priority)
Removes item at specified location from tree; then reorders and balances tree.
Item * Resize(const vtkIdType sz)
void Allocate(vtkIdType sz, vtkIdType ext=1000)
Allocate initial space for priority queue.
double DeleteId(vtkIdType id)
Delete entry in queue with specified id.
int vtkIdType
Definition: vtkType.h:332
#define VTK_DOUBLE_MAX
Definition: vtkType.h:165