VTK  9.0.1
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
vtkPriorityQueue::GetPriority
double GetPriority(vtkIdType id)
Get the priority of an entry in the queue with specified id.
Definition: vtkPriorityQueue.h:153
vtkPriorityQueue::GetNumberOfItems
vtkIdType GetNumberOfItems()
Return the number of items in this queue.
Definition: vtkPriorityQueue.h:116
vtkPriorityQueue::MaxId
vtkIdType MaxId
Definition: vtkPriorityQueue.h:133
vtkIdType
int vtkIdType
Definition: vtkType.h:338
vtkPriorityQueue::Size
vtkIdType Size
Definition: vtkPriorityQueue.h:132
vtkObject::New
static vtkObject * New()
Create an object with Debug turned off, modified time initialized to zero, and reference counting on.
vtkPriorityQueue
a list of ids arranged in priority order
Definition: vtkPriorityQueue.h:46
vtkObject
abstract base class for most VTK objects
Definition: vtkObject.h:62
vtkPriorityQueue::DeleteId
double DeleteId(vtkIdType id)
Delete entry in queue with specified id.
Definition: vtkPriorityQueue.h:141
vtkPriorityQueue::Array
Item * Array
Definition: vtkPriorityQueue.h:131
vtkIndent
a simple class to control print indentation
Definition: vtkIndent.h:33
vtkObject::PrintSelf
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
vtkPriorityQueue::Item::priority
double priority
Definition: vtkPriorityQueue.h:52
vtkIdTypeArray.h
vtkPriorityQueue::ItemLocation
vtkIdTypeArray * ItemLocation
Definition: vtkPriorityQueue.h:130
vtkObject.h
vtkPriorityQueue::Extend
vtkIdType Extend
Definition: vtkPriorityQueue.h:134
vtkAbstractArray::GetMaxId
vtkIdType GetMaxId() const
What is the maximum id currently in the array.
Definition: vtkAbstractArray.h:319
vtkIdTypeArray
dynamic, self-adjusting array of vtkIdType
Definition: vtkIdTypeArray.h:35
vtkPriorityQueue::Item
Definition: vtkPriorityQueue.h:49
vtkPriorityQueue::Peek
vtkIdType Peek(vtkIdType location, double &priority)
Peek into the queue without actually removing anything.
Definition: vtkPriorityQueue.h:164
vtkX3D::location
@ location
Definition: vtkX3D.h:412
vtkPriorityQueue::Item::id
vtkIdType id
Definition: vtkPriorityQueue.h:53
vtkPriorityQueue::Pop
vtkIdType Pop(vtkIdType location, double &priority)
Removes item at specified location from tree; then reorders and balances tree.
VTK_DOUBLE_MAX
#define VTK_DOUBLE_MAX
Definition: vtkType.h:165
vtkX3D::priority
@ priority
Definition: vtkX3D.h:456