VTK
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 
50  class Item
51  {
52  public:
53  double priority;
55  };
56 
60  static vtkPriorityQueue *New();
61 
62  vtkTypeMacro(vtkPriorityQueue,vtkObject);
63  void PrintSelf(ostream& os, vtkIndent indent) override;
64 
68  void Allocate(vtkIdType sz, vtkIdType ext=1000);
69 
74  void Insert(double priority, vtkIdType id);
75 
82  vtkIdType Pop(vtkIdType location, double &priority);
83 
89 
94  vtkIdType Peek(vtkIdType location, double &priority);
95 
100  vtkIdType Peek(vtkIdType location=0);
101 
106  double DeleteId(vtkIdType id);
107 
112  double GetPriority(vtkIdType id);
113 
117  vtkIdType GetNumberOfItems() {return this->MaxId+1;};
118 
123  void Reset();
124 
125 protected:
127  ~vtkPriorityQueue() override;
128 
129  Item *Resize(const vtkIdType sz);
130 
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() &&
147  (loc=this->ItemLocation->GetValue(id)) != -1 )
148  {
149  this->Pop(loc,priority);
150  }
151  return priority;
152 }
153 
155 {
156  vtkIdType loc;
157 
158  if ( id <= this->ItemLocation->GetMaxId() &&
159  (loc=this->ItemLocation->GetValue(id)) != -1 )
160  {
161  return this->Array[loc].priority;
162  }
163  return VTK_DOUBLE_MAX;
164 }
165 
167 {
168  if ( this->MaxId < 0 )
169  {
170  return -1;
171  }
172  else
173  {
174  priority = this->Array[location].priority;
175  return this->Array[location].id;
176  }
177 }
178 
180 {
181  if ( this->MaxId < 0 )
182  {
183  return -1;
184  }
185  else
186  {
187  return this->Array[location].id;
188  }
189 }
190 
191 #endif
abstract base class for most VTK objects
Definition: vtkObject.h:59
#define VTK_DOUBLE_MAX
Definition: vtkType.h:169
vtkIdTypeArray * ItemLocation
vtkIdType Peek(vtkIdType location, double &priority)
Peek into the queue without actually removing anything.
dynamic, self-adjusting array of vtkIdType
int vtkIdType
Definition: vtkType.h:347
a list of ids arranged in priority order
double GetPriority(vtkIdType id)
Get the priority of an entry in the queue with specified id.
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.