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 =========================================================================*/
37 #ifndef __vtkPriorityQueue_h
38 #define __vtkPriorityQueue_h
39 
40 #include "vtkObject.h"
41 
42 #include "vtkIdTypeArray.h" // Needed for inline methods
43 
45 {
46 public:
47  //BTX
48  class Item
49  {
50  public:
51  double priority;
53  };
54  //ETX
55 
58  static vtkPriorityQueue *New();
59 
60  vtkTypeMacro(vtkPriorityQueue,vtkObject);
61  void PrintSelf(ostream& os, vtkIndent indent);
62 
64  void Allocate(const vtkIdType sz, const vtkIdType ext=1000);
65 
68  void Insert(double priority, vtkIdType id);
69 
70 //BTX
72 
76  vtkIdType Pop(vtkIdType location, double &priority);
77 //ETX
79 
82  vtkIdType Pop(vtkIdType location=0);
83 
84 //BTX
86 
88  vtkIdType Peek(vtkIdType location, double &priority);
89 //ETX
91 
94  vtkIdType Peek(vtkIdType location=0);
95 
98  double DeleteId(vtkIdType id);
99 
102  double GetPriority(vtkIdType id);
103 
105  vtkIdType GetNumberOfItems() {return this->MaxId+1;};
106 
109  void Reset();
110 
111 protected:
113  ~vtkPriorityQueue();
114 
115  Item *Resize(const vtkIdType sz);
116 
122 private:
123  vtkPriorityQueue(const vtkPriorityQueue&); // Not implemented.
124  void operator=(const vtkPriorityQueue&); // Not implemented.
125 };
126 
128 {
129  double priority=VTK_DOUBLE_MAX;
130  int loc;
131 
132  if ( id <= this->ItemLocation->GetMaxId() &&
133  (loc=this->ItemLocation->GetValue(id)) != -1 )
134  {
135  this->Pop(loc,priority);
136  }
137  return priority;
138 }
139 
141 {
142  int loc;
143 
144  if ( id <= this->ItemLocation->GetMaxId() &&
145  (loc=this->ItemLocation->GetValue(id)) != -1 )
146  {
147  return this->Array[loc].priority;
148  }
149  return VTK_DOUBLE_MAX;
150 }
151 
152 inline vtkIdType vtkPriorityQueue::Peek(vtkIdType location, double &priority)
153 {
154  if ( this->MaxId < 0 )
155  {
156  return -1;
157  }
158  else
159  {
160  priority = this->Array[location].priority;
161  return this->Array[location].id;
162  }
163 }
164 
166 {
167  if ( this->MaxId < 0 )
168  {
169  return -1;
170  }
171  else
172  {
173  return this->Array[location].id;
174  }
175 }
176 
177 #endif
vtkIdType GetMaxId()
abstract base class for most VTK objects
Definition: vtkObject.h:60
#define VTK_DOUBLE_MAX
Definition: vtkType.h:133
vtkIdTypeArray * ItemLocation
vtkIdType GetValue(vtkIdType id)
vtkIdType Peek(vtkIdType location, double &priority)
dynamic, self-adjusting array of vtkIdType
int vtkIdType
Definition: vtkType.h:255
an list of ids arranged in priority order
virtual void PrintSelf(ostream &os, vtkIndent indent)
double GetPriority(vtkIdType id)
vtkIdType Pop(vtkIdType location, double &priority)
a simple class to control print indentation
Definition: vtkIndent.h:37
vtkIdType GetNumberOfItems()
#define VTK_COMMON_EXPORT
double DeleteId(vtkIdType id)
static vtkObject * New()