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) VTK_OVERRIDE;
64 
68  void Allocate(const vtkIdType sz, const vtkIdType ext=1000);
69 
74  void Insert(double priority, vtkIdType id);
75 
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() VTK_OVERRIDE;
128 
129  Item *Resize(const vtkIdType sz);
130 
131  vtkIdTypeArray *ItemLocation;
132  Item *Array;
133  vtkIdType Size;
134  vtkIdType MaxId;
135  vtkIdType Extend;
136 private:
137  vtkPriorityQueue(const vtkPriorityQueue&) VTK_DELETE_FUNCTION;
138  void operator=(const vtkPriorityQueue&) VTK_DELETE_FUNCTION;
139 };
140 
141 inline double vtkPriorityQueue::DeleteId(vtkIdType id)
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
vtkIdType GetMaxId()
What is the maximum id currently in the array.
dynamic, self-adjusting array of vtkIdType
a simple class to control print indentation
Definition: vtkIndent.h:40
abstract base class for most VTK objects
Definition: vtkObject.h:60
a list of ids arranged in priority order
double GetPriority(vtkIdType id)
Get the priority of an entry in the queue with specified id.
void Insert(double priority, vtkIdType id)
Insert id with priority specified.
void Reset()
Empty the queue but without releasing memory.
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
vtkIdType GetNumberOfItems()
Return the number of items in this queue.
~vtkPriorityQueue() override
static vtkPriorityQueue * New()
Instantiate priority queue with default size and extension size of 1000.
vtkIdType Pop(vtkIdType location=0)
Same as above but simplified for easier wrapping into interpreted languages.
vtkIdType Peek(vtkIdType location, double &priority)
Peek into the queue without actually removing anything.
void Allocate(const vtkIdType sz, const vtkIdType ext=1000)
Allocate initial space for priority queue.
vtkIdType Pop(vtkIdType location, double &priority)
Removes item at specified location from tree; then reorders and balances tree.
@ location
Definition: vtkX3D.h:406
@ priority
Definition: vtkX3D.h:450
int vtkIdType
Definition: vtkType.h:287
#define VTK_DOUBLE_MAX
Definition: vtkType.h:163