00001 /*========================================================================= 00002 00003 Program: Visualization Toolkit 00004 Module: $RCSfile: vtkPriorityQueue.h,v $ 00005 Language: C++ 00006 00007 Copyright (c) 1993-2002 Ken Martin, Will Schroeder, Bill Lorensen 00008 All rights reserved. 00009 See Copyright.txt or http://www.kitware.com/Copyright.htm for details. 00010 00011 This software is distributed WITHOUT ANY WARRANTY; without even 00012 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 00013 PURPOSE. See the above copyright notice for more information. 00014 00015 =========================================================================*/ 00055 #ifndef __vtkPriorityQueue_h 00056 #define __vtkPriorityQueue_h 00057 00058 #include "vtkObject.h" 00059 00060 #include "vtkIdTypeArray.h" // Needed for inline methods 00061 00062 class VTK_COMMON_EXPORT vtkPriorityQueue : public vtkObject 00063 { 00064 public: 00065 //BTX 00066 class Item 00067 { 00068 public: 00069 float priority; 00070 vtkIdType id; 00071 }; 00072 //ETX 00073 00076 static vtkPriorityQueue *New(); 00077 00078 vtkTypeRevisionMacro(vtkPriorityQueue,vtkObject); 00079 void PrintSelf(ostream& os, vtkIndent indent); 00080 00082 void Allocate(const vtkIdType sz, const vtkIdType ext=1000); 00083 00086 void Insert(float priority, vtkIdType id); 00087 00092 vtkIdType Pop(vtkIdType location, float &priority); 00093 //ETX 00094 00097 vtkIdType Pop(vtkIdType location=0); 00098 00101 vtkIdType Peek(vtkIdType location, float &priority); 00102 //ETX 00103 00106 vtkIdType Peek(vtkIdType location=0); 00107 00110 float DeleteId(vtkIdType id); 00111 00114 float GetPriority(vtkIdType id); 00115 00117 vtkIdType GetNumberOfItems() {return this->MaxId+1;}; 00118 00121 void Reset(); 00122 00123 protected: 00124 vtkPriorityQueue(); 00125 ~vtkPriorityQueue(); 00126 00127 Item *Resize(const vtkIdType sz); 00128 00129 vtkIdTypeArray *ItemLocation; 00130 Item *Array; 00131 vtkIdType Size; 00132 vtkIdType MaxId; 00133 vtkIdType Extend; 00134 private: 00135 vtkPriorityQueue(const vtkPriorityQueue&); // Not implemented. 00136 void operator=(const vtkPriorityQueue&); // Not implemented. 00137 }; 00138 00139 inline float vtkPriorityQueue::DeleteId(vtkIdType id) 00140 { 00141 float priority=VTK_LARGE_FLOAT; 00142 int loc; 00143 00144 if ( id <= this->ItemLocation->GetMaxId() && 00145 (loc=this->ItemLocation->GetValue(id)) != -1 ) 00146 { 00147 this->Pop(loc,priority); 00148 } 00149 return priority; 00150 } 00151 00152 inline float vtkPriorityQueue::GetPriority(vtkIdType id) 00153 { 00154 int loc; 00155 00156 if ( id <= this->ItemLocation->GetMaxId() && 00157 (loc=this->ItemLocation->GetValue(id)) != -1 ) 00158 { 00159 return this->Array[loc].priority; 00160 } 00161 return VTK_LARGE_FLOAT; 00162 } 00163 00164 inline vtkIdType vtkPriorityQueue::Peek(vtkIdType location, float &priority) 00165 { 00166 if ( this->MaxId < 0 ) 00167 { 00168 return -1; 00169 } 00170 else 00171 { 00172 priority = this->Array[location].priority; 00173 return this->Array[location].id; 00174 } 00175 } 00176 00177 inline vtkIdType vtkPriorityQueue::Peek(vtkIdType location) 00178 { 00179 if ( this->MaxId < 0 ) 00180 { 00181 return -1; 00182 } 00183 else 00184 { 00185 return this->Array[location].id; 00186 } 00187 } 00188 00189 #endif