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;
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:
115  ~vtkPriorityQueue() override;
116 
117  Item* Resize(vtkIdType sz);
118 
124 
125 private:
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 
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 
178 VTK_ABI_NAMESPACE_END
179 #endif
abstract base class for most VTK objects
Definition: vtkObject.h:51
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
#define VTK_DOUBLE_MAX
Definition: vtkType.h:154
vtkIdTypeArray * ItemLocation
vtkIdType Peek(vtkIdType location, double &priority)
Peek into the queue without actually removing anything.
ValueType GetValue(vtkIdType valueIdx) const
Get the value at valueIdx.
dynamic, self-adjusting array of vtkIdType
int vtkIdType
Definition: vtkType.h:315
a list of ids arranged in priority order
double GetPriority(vtkIdType id)
Get the priority of an entry in the queue with specified id.
vtkIdType Pop(vtkIdType location, double &priority)
Removes item at specified location from tree; then reorders and balances tree.
a simple class to control print indentation
Definition: vtkIndent.h:28
vtkIdType GetNumberOfItems()
Return the number of items in this queue.
double DeleteId(vtkIdType id)
Delete entry in queue with specified id.
static vtkObject * New()
Create an object with Debug turned off, modified time initialized to zero, and reference counting on...
vtkIdType GetMaxId() const
What is the maximum id currently in the array.