Files Classes Functions Hierarchy
00001 #ifndef BUCKETLINK_H 00002 #define BUCKETLINK_H 00003 00004 #include <cassert> 00005 using namespace std; 00006 00007 #include <typedefs.h> 00008 00009 00010 //#define DEBUG_BUCKETLINK 00011 00012 #ifdef DEBUG_BUCKETLINK 00013 #include <iostream> 00014 #include <print.h> 00015 #endif 00016 00017 00021 template< typename T> 00022 class bucketlink 00023 { 00024 public: 00025 00027 T * data; 00028 00030 bucketlink * next; 00031 00033 bucketlink() 00034 : data(0), next(0) 00035 {} 00037 bucketlink(T * data_) 00038 : data(data_), next(0) 00039 {} 00040 00043 static uint insertafterselfcounter; 00044 00048 template< typename I2 > 00049 void insertafterself(bucketlink<T>* b, I2 & fn); 00050 00051 }; 00052 00053 //--------------------------------------------------------- 00054 // Implementation 00055 00056 template< typename T> 00057 uint bucketlink<T>::insertafterselfcounter = 0; 00058 00059 template< typename T> 00060 template< typename I2 > 00061 void bucketlink<T>::insertafterself(bucketlink<T>* b, I2 & fn) 00062 { 00063 assert(b!=0); 00064 assert( fn(*(b->data),*(this->data))==false ); 00065 00066 insertafterselfcounter=0; 00067 00068 bucketlink<T>* cp = next; 00069 bucketlink<T>* cp0 = this; 00070 for ( ;cp!=0; ) 00071 { 00072 00073 ++insertafterselfcounter; 00074 #ifdef DEBUG_BUCKETLINK 00075 cout << SHOW(insertafterselfcounter) << endl; 00076 #endif 00077 00078 if (fn(*(b->data),*(cp->data))) 00079 { 00080 b->next = cp; 00081 cp0->next = b; 00082 return; 00083 } 00084 00085 cp0 = cp; 00086 cp = cp->next; 00087 } 00088 00089 // Insert at the end of the list. 00090 cp0->next = b; 00091 b->next=0; 00092 } 00093 00094 #endif 00095
1.5.8