Fortuna PRNG C++ Source Code

Main Page | Namespace List | Class Hierarchy | Class List | File List | Namespace Members | Class Members | File Members

CitadelSoftwareInc::FastList< T > Class Template Reference

Fast singly linked list used to hold vector contents in non continguous memory, also contains erase which writes over bytes of each value with rand() 256. More...

#include <FastList.h>

List of all members.

Public Member Functions

 FastList ()
virtual ~FastList ()
unsigned int Add (const T &t)
void Reset ()
int ExtractAndErase (std::vector< T > &vec, const unsigned int modnum=256)
int Extract (std::vector< T > &vec)
int AddRandomData (vecuc &vData)
unsigned int Size () const

Private Attributes

ListItem< T > * m_pHead
ListItem< T > * m_pLast
unsigned int m_size
CMclCritSec m_critsec

Detailed Description

template<typename T>
class CitadelSoftwareInc::FastList< T >

Fast singly linked list used to hold vector contents in non continguous memory, also contains erase which writes over bytes of each value with rand() 256.

Definition at line 21 of file FastList.h.

Constructor & Destructor Documentation

template<typename T>
CitadelSoftwareInc::FastList< T >::FastList  )  [inline]
 

Definition at line 39 of file FastList.h.

00040                 :
00041         m_pHead(NULL),
00042         m_pLast(NULL),
00043         m_size(0)
00044         {}

template<typename T>
virtual CitadelSoftwareInc::FastList< T >::~FastList  )  [inline, virtual]
 

Definition at line 46 of file FastList.h.

00047         {
00048                 ListItem<T>* p = m_pHead;
00049                 while (p)
00050                 {
00051                         ListItem<T>* pNext = p->m_pNext;
00052                         delete p;
00053                         p = pNext;
00054                 }
00055         }

Member Function Documentation

template<typename T>
unsigned int CitadelSoftwareInc::FastList< T >::Add const T &  t  )  [inline]
 

Definition at line 57 of file FastList.h.

Referenced by CitadelSoftwareInc::TestFastList001().

00058         {
00059                 m_critsec.Enter();
00060                 if (!m_pHead)
00061                 {
00062                         m_pHead = new ListItem<T>(t);
00063                         m_pLast = m_pHead;
00064                         m_size = 1;
00065                 }
00066                 else if(m_pLast)
00067                 {
00068                         if (m_pLast->m_pNext)
00069                         {
00070                                 m_pLast->m_pNext->m_t = t;
00071                                 m_pLast = m_pLast->m_pNext;
00072                         }
00073                         else
00074                         {
00075                                 m_pLast->m_pNext = new ListItem<T>(t);
00076                                 m_pLast = m_pLast->m_pNext;
00077                         }
00078                         ++m_size;
00079                 }
00080                 else
00081                 {
00082                         m_pLast = m_pHead;
00083                         m_pLast->m_t = t;
00084                         ++m_size;
00085                 }
00086 
00087                 m_critsec.Leave();
00088 
00089                 return m_size;
00090         }

template<typename T>
int CitadelSoftwareInc::FastList< T >::AddRandomData vecuc vData  )  [inline]
 

Definition at line 174 of file FastList.h.

00175         {
00176                 int count=0;
00177                 unsigned char uc=0;
00178 
00179                 m_critsec.Enter();
00180 
00181                 ListItem<T>* p = m_pHead;
00182                 while(p)
00183                 {
00184                         const unsigned char* pData = (unsigned char*)p;
00185                         for (int i=0; i<sizeof(ListItem<T>*); ++i)
00186                         {
00187                                 uc = pData[i];
00188                                 if (uc)
00189                                 {
00190                                         vData.push_back(uc);
00191                                         ++count;
00192                                 }
00193                         }
00194 
00195                         p = p->m_pNext;
00196                 }
00197 
00198                 m_critsec.Leave();
00199 
00200                 return count;
00201         }

template<typename T>
int CitadelSoftwareInc::FastList< T >::Extract std::vector< T > &  vec  )  [inline]
 

Definition at line 145 of file FastList.h.

Referenced by CitadelSoftwareInc::TestFastList001().

00146         {
00147                 vec.clear();
00148 
00149                 if (m_size == 0)
00150                         return 0;
00151 
00152                 m_critsec.Enter();
00153 
00154                 vec.resize(m_size);
00155                 unsigned int i=0;
00156                 ListItem<T>* p = m_pHead;
00157                 while(p)
00158                 {
00159                         assert(i<m_size);
00160                         vec[i++] = p->m_t;
00161                         if (p == m_pLast)
00162                                 break;
00163                         p = p->m_pNext;
00164                 }
00165 
00166                 assert(i == m_size);
00167 
00168                 m_critsec.Leave();
00169 
00170                 return m_size;
00171         }

template<typename T>
int CitadelSoftwareInc::FastList< T >::ExtractAndErase std::vector< T > &  vec,
const unsigned int  modnum = 256
[inline]
 

Definition at line 113 of file FastList.h.

Referenced by CitadelSoftwareInc::TestFastList001().

00114         {
00115                 vec.clear();
00116                 if (m_size == 0)
00117                         return 0;
00118 
00119                 m_critsec.Enter();
00120 
00121                 unsigned int i=0;
00122                 vec.resize(m_size);
00123                 ListItem<T>* p = m_pHead;
00124                 while (p)
00125                 {
00126                         assert(i<m_size);
00127                         vec[i++] = p->m_t;
00128                         p->m_t = rand() % modnum;               // overwrite the existing data with something random looking
00129                         if (p == m_pLast)
00130                                 break;
00131 
00132                         p = p->m_pNext;
00133                 }
00134 
00135                 assert(i == m_size);
00136                 int retval = m_size;
00137                 m_size = 0;
00138                 m_pLast = NULL;
00139 
00140                 m_critsec.Leave();
00141 
00142                 return retval;
00143         }

template<typename T>
void CitadelSoftwareInc::FastList< T >::Reset  )  [inline]
 

Definition at line 92 of file FastList.h.

00093         {
00094                 m_critsec.Enter();
00095 
00096                 if (m_pLast)
00097                 {
00098                         ListItem<T> *p = m_pHead;
00099                         while(p)
00100                         {
00101                                 p->m_t = rand() % 256;          // overwrite the existing data with something random looking
00102                                 if (p == m_pLast)
00103                                         break;
00104                                 p = p->m_pNext;
00105                         }
00106                         m_pLast = NULL;
00107                         m_size = 0;
00108                 }
00109 
00110                 m_critsec.Leave();
00111         }

template<typename T>
unsigned int CitadelSoftwareInc::FastList< T >::Size  )  const [inline]
 

Definition at line 203 of file FastList.h.

Referenced by CitadelSoftwareInc::TestFastList001().

00204         {
00205                 unsigned int ui = 0;
00206 
00207                 m_critsec.Enter();
00208                 ui = m_size;
00209                 m_critsec.Leave();
00210 
00211                 return ui;
00212         }

Member Data Documentation

template<typename T>
CMclCritSec CitadelSoftwareInc::FastList< T >::m_critsec [mutable, private]
 

Definition at line 219 of file FastList.h.

template<typename T>
ListItem<T>* CitadelSoftwareInc::FastList< T >::m_pHead [private]
 

Definition at line 215 of file FastList.h.

template<typename T>
ListItem<T>* CitadelSoftwareInc::FastList< T >::m_pLast [private]
 

Definition at line 216 of file FastList.h.

template<typename T>
unsigned int CitadelSoftwareInc::FastList< T >::m_size [private]
 

Definition at line 218 of file FastList.h.

The documentation for this class was generated from the following file:
bulletFastList.h

Generated on Sat Feb 28 17:24:42 2004 for Fortuna by doxygen 1.3.5