VTK  9.2.6
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 
46 class VTKCOMMONCORE_EXPORT vtkPriorityQueue : public vtkObject
47 {
48 public:
49  class Item
50  {
51  public:
52  double priority;
54  };
55 
59  static vtkPriorityQueue* New();
60 
61  vtkTypeMacro(vtkPriorityQueue, vtkObject);
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 
124 protected:
126  ~vtkPriorityQueue() override;
127 
128  Item* Resize(const vtkIdType sz);
129 
135 
136 private:
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 
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
abstract base class for most VTK objects
Definition: vtkObject.h:62
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:165
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:332
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:39
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.