EMAN2
grid_queue2.cpp
Go to the documentation of this file.
00001 // Copyright (C) 2005-2008 Washington University in St Louis, Baylor College of Medicine.  All rights reserved
00002 // Author:        Tao Ju, Refactored by Sasakthi S. Abeysinghe (sasakthi@gmail.com)
00003 // Description:   Grid queue
00004 
00005 #include "grid_queue2.h"
00006 
00007 using namespace wustl_mm::SkeletonMaker;
00008 
00009                 GridQueue2::GridQueue2( )
00010                 {
00011                         head = NULL ;
00012                         cur = NULL ;
00013                         pre = NULL ;
00014                         prepre = NULL ;
00015                         numEles = 0 ;
00016                 }
00017 
00018                 GridQueue2::~GridQueue2()
00019                 {
00020                         gridQueueEle* ele;
00021                         reset();
00022                         ele=getNext();
00023                         while ( (ele=remove()) != NULL ){};
00024                 }
00025                 gridQueueEle* GridQueue2::getNext( )
00026                 {
00027                         if ( cur == NULL )
00028                         {
00029                                 prepre = NULL ;
00030                                 pre = NULL ;
00031                                 cur = head ;
00032                         }
00033                         else
00034                         {
00035                                 prepre = pre ;
00036                                 pre = cur ;
00037                                 cur = cur->next ;
00038                         }
00039 
00040                         return cur ;
00041                 }
00042 
00043                 void GridQueue2::reset( )
00044                 {
00045                         prepre = NULL ;
00046                         pre = NULL ;
00047                         cur = NULL ;
00048                 }
00049 
00050                 int GridQueue2::getNumElements( )
00051                 {
00052                         return numEles ;
00053                 }
00054 
00055                 void GridQueue2::prepend( int xx, int yy, int zz )
00056                 {
00057                         gridQueueEle* ele = new gridQueueEle ;
00058                         ele->x = xx ;
00059                         ele->y = yy ;
00060                         ele->z = zz ;
00061                         ele->score = 0 ;
00062                         ele->next = head;
00063                         head = ele ;
00064                         numEles ++ ;
00065 
00066                         reset() ;
00067                 }
00068 
00069                 /* Remove current element pointed by cur */
00070                 gridQueueEle * GridQueue2::remove( )
00071                 {
00072                         gridQueueEle* temp = cur ;
00073                         if ( cur != NULL )
00074                         {
00075                                 cur = cur->next ;
00076                                 delete temp ;
00077 
00078                                 if ( pre != NULL )
00079                                 {
00080                                         pre->next = cur ;
00081                                 }
00082                                 else
00083                                 {
00084                                         head = cur ;
00085                                 }
00086                                 numEles -- ;
00087                         }
00088 
00089 
00090                         return cur ;
00091                 }
00092 
00093                 /* Switching pre and cur */
00094                 gridQueueEle * GridQueue2::swap( )
00095                 {
00096                         if ( prepre != NULL )
00097                         {
00098                                 pre->next = cur->next ;
00099                                 cur->next = prepre->next ;
00100                                 prepre->next = cur ;
00101 
00102                         }
00103                         else
00104                         {
00105                                 pre->next = cur->next ;
00106                                 cur->next = pre ;
00107                                 head = cur ;
00108                         }
00109 
00110                         gridQueueEle* temp = pre ;
00111                         pre = cur ;
00112                         cur = temp ;
00113 
00114                         return cur ;
00115                 }