VTK  9.4.20250202
vtkPriorityQueue.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
2// SPDX-License-Identifier: BSD-3-Clause
26#ifndef vtkPriorityQueue_h
27#define vtkPriorityQueue_h
28
29#include "vtkCommonCoreModule.h" // For export macro
30#include "vtkObject.h"
31
32#include "vtkIdTypeArray.h" // Needed for inline methods
33
34VTK_ABI_NAMESPACE_BEGIN
35class VTKCOMMONCORE_EXPORT vtkPriorityQueue : public vtkObject
36{
37public:
38 class Item
39 {
40 public:
41 double priority;
43 };
44
49
51 void PrintSelf(ostream& os, vtkIndent indent) override;
52
56 void Allocate(vtkIdType sz, vtkIdType ext = 1000);
57
62 void Insert(double priority, vtkIdType id);
63
70 vtkIdType Pop(vtkIdType location, double& priority);
71
76 vtkIdType Pop(vtkIdType location = 0);
77
82 vtkIdType Peek(vtkIdType location, double& priority);
83
88 vtkIdType Peek(vtkIdType location = 0);
89
94 double DeleteId(vtkIdType id);
95
100 double GetPriority(vtkIdType id);
101
105 vtkIdType GetNumberOfItems() { return this->MaxId + 1; }
106
111 void Reset();
112
113protected:
116
118
124
125private:
126 vtkPriorityQueue(const vtkPriorityQueue&) = delete;
127 void operator=(const vtkPriorityQueue&) = delete;
128};
129
131{
132 double priority = VTK_DOUBLE_MAX;
133 vtkIdType loc;
134
135 if (id <= this->ItemLocation->GetMaxId() && (loc = this->ItemLocation->GetValue(id)) != -1)
136 {
137 this->Pop(loc, priority);
138 }
139 return priority;
140}
141
143{
144 vtkIdType loc;
145
146 if (id <= this->ItemLocation->GetMaxId() && (loc = this->ItemLocation->GetValue(id)) != -1)
147 {
148 return this->Array[loc].priority;
149 }
150 return VTK_DOUBLE_MAX;
151}
152
153inline vtkIdType vtkPriorityQueue::Peek(vtkIdType location, double& priority)
154{
155 if (this->MaxId < 0)
156 {
157 return -1;
158 }
159 else
160 {
161 priority = this->Array[location].priority;
162 return this->Array[location].id;
163 }
164}
165
167{
168 if (this->MaxId < 0)
169 {
170 return -1;
171 }
172 else
173 {
174 return this->Array[location].id;
175 }
176}
177
178VTK_ABI_NAMESPACE_END
179#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:108
abstract base class for most VTK objects
Definition vtkObject.h:162
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.
Item * Resize(vtkIdType sz)
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.
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:315
#define VTK_DOUBLE_MAX
Definition vtkType.h:154