EMAN2
Public Member Functions | Private Member Functions | Private Attributes
wustl_mm::SkeletonMaker::GridQueue Class Reference

#include <grid_queue.h>

Collaboration diagram for wustl_mm::SkeletonMaker::GridQueue:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 GridQueue ()
gridQueueElegetHead ()
int getNumElements ()
void sort (int eles)
void pushQueue (int xx, int yy, int zz)
int popQueue (int &xx, int &yy, int &zz)

Private Member Functions

void swapEle (gridQueueEle *pre, gridQueueEle *e1, gridQueueEle *e2)

Private Attributes

gridQueueElehead
gridQueueEletail
int numEles

Detailed Description

Definition at line 21 of file grid_queue.h.


Constructor & Destructor Documentation

GridQueue::GridQueue ( )

Definition at line 8 of file grid_queue.cpp.

References head, numEles, and tail.

                                      {
                        head = NULL ;
                        tail = NULL ;
                        numEles = 0 ;
                }

Member Function Documentation

gridQueueEle * GridQueue::getHead ( )

Definition at line 14 of file grid_queue.cpp.

References head.

                                                  {
                        return head ;
                }
int GridQueue::getNumElements ( )

Definition at line 18 of file grid_queue.cpp.

References numEles.

                                               {
                        return numEles ;
                }
int GridQueue::popQueue ( int &  xx,
int &  yy,
int &  zz 
)

Definition at line 88 of file grid_queue.cpp.

References head, wustl_mm::SkeletonMaker::gridQueueEle::next, numEles, tail, wustl_mm::SkeletonMaker::gridQueueEle::x, wustl_mm::SkeletonMaker::gridQueueEle::y, and wustl_mm::SkeletonMaker::gridQueueEle::z.

                                                                   {
                        if ( head == NULL )
                        {
                                return 0 ;
                        }

                        xx = head->x ;
                        yy = head->y ;
                        zz = head->z ;

                        gridQueueEle* temp = head ;
                        head = head->next ;
                        delete temp ;

                        if ( head == NULL )
                        {
                                tail = NULL ;
                        }
                        numEles -- ;

                        return 1 ;
                }
void GridQueue::pushQueue ( int  xx,
int  yy,
int  zz 
)

Definition at line 69 of file grid_queue.cpp.

References head, wustl_mm::SkeletonMaker::gridQueueEle::next, numEles, wustl_mm::SkeletonMaker::gridQueueEle::score, tail, wustl_mm::SkeletonMaker::gridQueueEle::x, wustl_mm::SkeletonMaker::gridQueueEle::y, and wustl_mm::SkeletonMaker::gridQueueEle::z.

                                                                  {
                        gridQueueEle* ele = new gridQueueEle ;
                        ele->x = xx ;
                        ele->y = yy ;
                        ele->z = zz ;
                        ele->score = 0 ;
                        ele->next = NULL ;
                        if ( head == NULL )
                        {
                                head = ele ;
                        }
                        else
                        {
                                tail->next = ele ;
                        }
                        tail = ele ;
                        numEles ++ ;
                }
void GridQueue::sort ( int  eles)

Definition at line 23 of file grid_queue.cpp.

References head, wustl_mm::SkeletonMaker::gridQueueEle::next, wustl_mm::SkeletonMaker::gridQueueEle::score, and swapEle().

                                               {
                        //printf("Sorting elements with descending scores...\n") ;
                        gridQueueEle* pre ;
                        gridQueueEle* e1 ;
                        gridQueueEle* e2 ;

                        for ( int i = eles - 1 ; i > 0 ; i -- )
                        {
                                pre = NULL ;
                                e1 = head ;
                                e2 = e1->next ;

                                for ( int j = 0 ; j < i ; j ++ )
                                {
                                        if ( e1->score < e2->score )
                                        {
                                                swapEle( pre, e1, e2 ) ;
                                        }
                                        else if ( e1->score == e2->score && rand() < RAND_MAX / 2)
                                        {
                                                swapEle( pre, e1, e2 ) ;
                                        }

                                        if ( pre == NULL )
                                        {
                                                pre = head ;
                                        }
                                        else
                                        {
                                                pre = pre->next;
                                        }
                                        e1 = pre->next ;
                                        e2 = e1->next ;
                                }
                        }

                        /* Debugging
                        pre = head ;
                        while ( pre != NULL )
                        {
                                printf("%d ", pre->score ) ;
                                pre = pre->next ;
                        }*/
                }
void GridQueue::swapEle ( gridQueueEle pre,
gridQueueEle e1,
gridQueueEle e2 
) [private]

Definition at line 112 of file grid_queue.cpp.

References head, wustl_mm::SkeletonMaker::gridQueueEle::next, and tail.

Referenced by sort().

                {
                        if ( pre != NULL )
                        {
                                e1->next = e2->next ;
                                e2->next = pre->next ;
                                pre->next = e2 ;

                                if ( tail == e2 )
                                {
                                        tail = e1 ;
                                }
                        }
                        else
                        {
                                e1->next = e2->next ;
                                e2->next = e1 ;
                                head = e2 ;

                                if ( tail == e2 )
                                {
                                        tail = e1 ;
                                }
                        }
                }

Member Data Documentation

Definition at line 35 of file grid_queue.h.

Referenced by getHead(), GridQueue(), popQueue(), pushQueue(), sort(), and swapEle().

Definition at line 37 of file grid_queue.h.

Referenced by getNumElements(), GridQueue(), popQueue(), and pushQueue().

Definition at line 36 of file grid_queue.h.

Referenced by GridQueue(), popQueue(), pushQueue(), and swapEle().


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