HeapPQ Class Reference

#include <Heap.h>

List of all members.


Detailed Description

HeapPQ class.

Maintains a hash table in order to find halfedges in n*log(n) time.

Public Member Functions

 HeapPQ ()
void PQinitialize (int sqrt_nsites, double ymin, double deltay)
void PQreset ()
void PQinsert (Halfedge *he, Site *v, double offset)
void PQdelete (Halfedge *he)
int PQbucket (Halfedge *he)
int PQempty ()
Vector2D PQ_min ()
HalfedgePQextractmin ()

Protected Attributes

int PQcount
int PQmin
int PQhashsize
double ymin
double deltay
HalfedgePQhash


Constructor & Destructor Documentation

HeapPQ::HeapPQ (  ) 

00027 {
00028     PQhash = NULL;
00029 }


Member Function Documentation

void HeapPQ::PQinitialize ( int  sqrt_nsites,
double  ymin,
double  deltay 
)

Referenced by NeighborsList::buildVoronoi().

00032 {
00033     PQcount = 0;
00034     PQmin = 0;
00035     PQhashsize = 4 * sqrt_nsites;
00036     PQhash = new Halfedge[PQhashsize];
00037     this->ymin = ymin;
00038     this->deltay = deltay;
00039 }

void HeapPQ::PQreset (  ) 

Referenced by NeighborsList::buildVoronoi().

00042 {
00043     delete[] PQhash;
00044 }

void HeapPQ::PQinsert ( Halfedge he,
Site v,
double  offset 
)

Referenced by NeighborsList::buildVoronoi().

00047 {
00048     Halfedge *last, *next;
00049 
00050     he->vertex = v;
00051     he->ystar = v->coord.y + offset;
00052     last = &PQhash[PQbucket(he)];
00053     while((next = last->PQnext) != NULL && (he->ystar  > next->ystar  || (he->ystar == next->ystar && v->coord.x > next->vertex->coord.x))) {
00054         last = next;
00055     }
00056     he->PQnext = last->PQnext;
00057     last->PQnext = he;
00058     PQcount++;
00059 }

void HeapPQ::PQdelete ( Halfedge he  ) 

Referenced by NeighborsList::buildVoronoi().

00062 {
00063     Halfedge *last;
00064 
00065     if(he->vertex != NULL) {
00066         last = &PQhash[PQbucket(he)];
00067         while(last->PQnext != he) last = last->PQnext;
00068 
00069         last->PQnext = he->PQnext;
00070         PQcount--;
00071         he->vertex = NULL;
00072     }
00073 }

int HeapPQ::PQbucket ( Halfedge he  ) 

Referenced by PQdelete(), and PQinsert().

00076 {
00077     int bucket;
00078 
00079     bucket = (int)((he->ystar - ymin)/deltay) * PQhashsize;
00080     if(bucket < 0) bucket = 0;
00081     if(bucket >= PQhashsize) bucket = PQhashsize-1;
00082     if(bucket < PQmin) PQmin = bucket;
00083     return bucket;
00084 }

int HeapPQ::PQempty (  ) 

Referenced by NeighborsList::buildVoronoi().

00087 {
00088     return PQcount==0;
00089 }

Vector2D HeapPQ::PQ_min (  ) 

Referenced by NeighborsList::buildVoronoi().

00092 {
00093     Vector2D answer;
00094 
00095     while(PQhash[PQmin].PQnext == NULL) PQmin++;
00096 
00097     answer.x = PQhash[PQmin].PQnext->vertex->coord.x;
00098     answer.y = PQhash[PQmin].PQnext->ystar;
00099     return answer;
00100 }

Halfedge * HeapPQ::PQextractmin (  ) 

Referenced by NeighborsList::buildVoronoi().

00103 {
00104     Halfedge *curr;
00105 
00106     curr = PQhash[PQmin].PQnext;
00107     PQhash[PQmin].PQnext = curr->PQnext;
00108     PQcount--;
00109     return curr;
00110 }


Member Data Documentation

int HeapPQ::PQcount [protected]

int HeapPQ::PQmin [protected]

int HeapPQ::PQhashsize [protected]

Referenced by PQbucket(), and PQinitialize().

double HeapPQ::ymin [protected]

Referenced by PQbucket().

double HeapPQ::deltay [protected]

Referenced by PQbucket().

Halfedge* HeapPQ::PQhash [protected]


The documentation for this class was generated from the following files:

Generated on Fri Sep 19 13:05:07 2008 for ITM OverSim by  doxygen 1.5.5