VTK: Common/Core/vtkPriorityQueue.h Source File

| VTK 9.3.1

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
34 VTK_ABI_NAMESPACE_BEGIN
35 class VTKCOMMONCORE_EXPORT vtkPriorityQueue : public vtkObject
36 {
37 public:
38 class Item
39 {
40 public:
41 double priority;
42 vtkIdType id;
43 };
44
48 static vtkPriorityQueue* New();
49
50 vtkTypeMacro(vtkPriorityQueue, vtkObject);
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
113 protected:
114 vtkPriorityQueue();
115 ~vtkPriorityQueue() override;
116
117 Item* Resize(vtkIdType sz);
118
119 vtkIdTypeArray* ItemLocation;
120 Item* Array;
121 vtkIdType Size;
122 vtkIdType MaxId;
123 vtkIdType Extend;
124
125 private:
126 vtkPriorityQueue(const vtkPriorityQueue&) = delete;
127 void operator=(const vtkPriorityQueue&) = delete;
128 };
129
130 inline double vtkPriorityQueue::DeleteId(vtkIdType id)
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
142 inline double vtkPriorityQueue::GetPriority(vtkIdType id)
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
153 inline 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
166 inline vtkIdType vtkPriorityQueue::Peek(vtkIdType location)
167 {
168 if (this->MaxId < 0)
169 {
170 return -1;
171 }
172 else
173 {
174 return this->Array[location].id;
175 }
176 }
177
178 VTK_ABI_NAMESPACE_END
179 #endif
vtkAbstractArray::GetMaxId
vtkIdType GetMaxId() const
What is the maximum id currently in the array.
Definition: vtkAbstractArray.h:327
vtkIdTypeArray
dynamic, self-adjusting array of vtkIdType
Definition: vtkIdTypeArray.h:37
vtkIndent
a simple class to control print indentation
Definition: vtkIndent.h:38
vtkObject
abstract base class for most VTK objects
Definition: vtkObject.h:61
vtkPriorityQueue::Item
Definition: vtkPriorityQueue.h:39
vtkPriorityQueue::Item::id
vtkIdType id
Definition: vtkPriorityQueue.h:42
vtkPriorityQueue::Item::priority
double priority
Definition: vtkPriorityQueue.h:41
vtkPriorityQueue
a list of ids arranged in priority order
Definition: vtkPriorityQueue.h:36
vtkPriorityQueue::Array
Item * Array
Definition: vtkPriorityQueue.h:120
vtkPriorityQueue::GetPriority
double GetPriority(vtkIdType id)
Get the priority of an entry in the queue with specified id.
Definition: vtkPriorityQueue.h:142
vtkPriorityQueue::Insert
void Insert(double priority, vtkIdType id)
Insert id with priority specified.
vtkPriorityQueue::Size
vtkIdType Size
Definition: vtkPriorityQueue.h:121
vtkPriorityQueue::Reset
void Reset()
Empty the queue but without releasing memory.
vtkPriorityQueue::PrintSelf
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
vtkPriorityQueue::GetNumberOfItems
vtkIdType GetNumberOfItems()
Return the number of items in this queue.
Definition: vtkPriorityQueue.h:105
vtkPriorityQueue::~vtkPriorityQueue
~vtkPriorityQueue() override
vtkPriorityQueue::New
static vtkPriorityQueue * New()
Instantiate priority queue with default size and extension size of 1000.
vtkPriorityQueue::Pop
vtkIdType Pop(vtkIdType location=0)
Same as above but simplified for easier wrapping into interpreted languages.
vtkPriorityQueue::Peek
vtkIdType Peek(vtkIdType location, double &priority)
Peek into the queue without actually removing anything.
Definition: vtkPriorityQueue.h:153
vtkPriorityQueue::ItemLocation
vtkIdTypeArray * ItemLocation
Definition: vtkPriorityQueue.h:119
vtkPriorityQueue::Extend
vtkIdType Extend
Definition: vtkPriorityQueue.h:123
vtkPriorityQueue::vtkPriorityQueue
vtkPriorityQueue()
vtkPriorityQueue::Resize
Item * Resize(vtkIdType sz)
vtkPriorityQueue::MaxId
vtkIdType MaxId
Definition: vtkPriorityQueue.h:122
vtkPriorityQueue::Pop
vtkIdType Pop(vtkIdType location, double &priority)
Removes item at specified location from tree; then reorders and balances tree.
vtkPriorityQueue::Allocate
void Allocate(vtkIdType sz, vtkIdType ext=1000)
Allocate initial space for priority queue.
vtkPriorityQueue::DeleteId
double DeleteId(vtkIdType id)
Delete entry in queue with specified id.
Definition: vtkPriorityQueue.h:130
vtkX3D::location
@ location
Definition: vtkX3D.h:406
vtkX3D::priority
@ priority
Definition: vtkX3D.h:450
vtkIdTypeArray.h
vtkObject.h
vtkIdType
int vtkIdType
Definition: vtkType.h:315
VTK_DOUBLE_MAX
#define VTK_DOUBLE_MAX
Definition: vtkType.h:154