Main Page | Directories | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | File Members | Related Pages

vtkPriorityQueue.h

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