UniqueSetRaw< Elem > Class Template Reference

#include <UniqueSetRaw.h>

List of all members.

Public Member Functions

 UniqueSetRaw (int size=101)
 UniqueSetRaw (const UniqueSetRaw< Elem > &us)
 ~UniqueSetRaw (void)
UniqueSetRaw< Elem > & operator= (const UniqueSetRaw< Elem > &us)
void rehash (void)
void rehash (int size)
void setSafeNoDestruction (int flag)
int add (const Elem &elem)
int load (const Elem &elem)
Elem * find (const Elem &elem)
int del (const Elem &elem)
int size (void) const
void clear (int n=0)

Protected Attributes

int refCount
EntryGlob< Elem > * globHead

Friends

class UniqueSet< Elem >
class UniqueSetIter< Elem >


Detailed Description

template<class Elem>
class UniqueSetRaw< Elem >

Definition at line 133 of file UniqueSetRaw.h.


Constructor & Destructor Documentation

template<class Elem>
UniqueSetRaw< Elem >::UniqueSetRaw ( int  size = 101  )  [inline]

Definition at line 399 of file UniqueSetRaw.h.

00399                                                 : 
00400   table(0), tableLength(0), numElem(0), growable(1) {
00401   const int minGlobSize = 32;
00402   isSafeNoDestruction = 1;
00403   growSize = 0;
00404   globSize = minGlobSize;
00405   init(size);
00406 }

template<class Elem>
UniqueSetRaw< Elem >::UniqueSetRaw ( const UniqueSetRaw< Elem > &  us  )  [inline]

Definition at line 144 of file UniqueSetRaw.h.

00144 { copy(us); }

template<class Elem>
UniqueSetRaw< Elem >::~UniqueSetRaw ( void   )  [inline]

Definition at line 146 of file UniqueSetRaw.h.

00146 { cleanUp(); }


Member Function Documentation

template<class Elem>
int UniqueSetRaw< Elem >::add ( const Elem &  elem  )  [inline]

Definition at line 190 of file UniqueSetRaw.h.

00190                               {
00191       int tableSlot = elem.hash() % tableLength;
00192       int doadd = 1;
00193       for (Entry<Elem> *e = table[tableSlot]; e; e=e->next()) {
00194         if (e->obj == elem) { doadd = 0; break; }
00195       }
00196       if (doadd) {
00197         Entry<Elem> *entry = nextFree();
00198         *entry = elem; // sets used flag
00199         table[tableSlot] = entry->setNext(table[tableSlot]);
00200         if ( ++numElem > growSize)  
00201           rehash();
00202       }
00203       return(doadd);
00204     }

template<class Elem>
void UniqueSetRaw< Elem >::clear ( int  n = 0  )  [inline]

Definition at line 251 of file UniqueSetRaw.h.

00251                         {
00252       if (!n) n = size();
00253       cleanUp();
00254       init(n); // have to have something currently for a table
00255     }

template<class Elem>
int UniqueSetRaw< Elem >::del ( const Elem &  elem  )  [inline]

Definition at line 226 of file UniqueSetRaw.h.

00226                               {
00227       int tableSlot = elem.hash() % tableLength;
00228       int dodel = 0;
00229     
00230       Entry<Elem> *prev = 0;
00231       Entry<Elem> *e = table[tableSlot];
00232       while(e) {
00233         if (e->obj == elem) {
00234           if (0 == prev) {
00235             table[tableSlot] = e->removeSelf();
00236           } else {
00237             prev->setNext(e->removeSelf());
00238           } 
00239           addFree(e); dodel = 1; numElem--;
00240           break;
00241         }
00242         prev = e;
00243         e = e->next();
00244       }
00245       return dodel;
00246     }

template<class Elem>
Elem* UniqueSetRaw< Elem >::find ( const Elem &  elem  )  [inline]

Definition at line 215 of file UniqueSetRaw.h.

00215                                  {
00216       register Entry<Elem> *e = table[elem.hash() % tableLength];
00217       while(e) {
00218         if (elem == e->obj ) {
00219           return (&(e->obj));
00220         }
00221         e = e->next();
00222       }
00223       return (0);
00224     }

template<class Elem>
int UniqueSetRaw< Elem >::load ( const Elem &  elem  )  [inline]

Definition at line 206 of file UniqueSetRaw.h.

00206                                {
00207       Entry<Elem> *entry = nextFree();
00208       *entry = elem; // sets used flag
00209       table[0] = entry->setNext(table[0]);
00210       ++numElem;
00211       return(1);
00212     }

template<class Elem>
UniqueSetRaw<Elem>& UniqueSetRaw< Elem >::operator= ( const UniqueSetRaw< Elem > &  us  )  [inline]

Definition at line 148 of file UniqueSetRaw.h.

00148                                                                  {
00149       copy(us);
00150       return *this;
00151     }  

template<class Elem>
void UniqueSetRaw< Elem >::rehash ( int  size  )  [inline]

Definition at line 156 of file UniqueSetRaw.h.

00156                           {
00157       // Store away old pointers and Entry<Elem>(s)
00158       int oldTableLength= tableLength;
00159       Entry<Elem> **oldTable = table;
00160     
00161       // recreate the table
00162       tableLength = findSize(numElem > size ? numElem : size);
00163       if (tableLength == oldTableLength) 
00164         return;
00165       numElem = 0;
00166       table = new Entry<Elem>*[tableLength];
00167       growSize = tableLength * 4;
00168     
00169       // 0 table
00170       Entry<Elem> **t = table; Entry<Elem> **e = table+tableLength;
00171       for (; t != e; *t++ = 0);
00172     
00173       // go thru old table and chains of Entry<Elem>(s)
00174       for (int i=0; i<oldTableLength; i++) {
00175         Entry<Elem> *e = oldTable[i];
00176         while(e) {
00177           Entry<Elem> *tmp = e->next();
00178           remapEntry(e);
00179           numElem++;
00180           e = tmp;
00181         }
00182       }
00183       delete[] oldTable;
00184     } 

template<class Elem>
void UniqueSetRaw< Elem >::rehash ( void   )  [inline]

Definition at line 153 of file UniqueSetRaw.h.

Referenced by UniqueSetRaw< TaggedMsg >::add(), and UniqueSetRaw< TaggedMsg >::rehash().

00153 { rehash(numElem); }

template<class Elem>
void UniqueSetRaw< Elem >::setSafeNoDestruction ( int  flag  )  [inline]

Definition at line 187 of file UniqueSetRaw.h.

00187 { isSafeNoDestruction = flag; }

template<class Elem>
int UniqueSetRaw< Elem >::size ( void   )  const [inline]

Definition at line 249 of file UniqueSetRaw.h.

Referenced by UniqueSetRaw< TaggedMsg >::clear().

00249 { return(numElem); }


Friends And Related Function Documentation

template<class Elem>
friend class UniqueSet< Elem > [friend]

Definition at line 135 of file UniqueSetRaw.h.

template<class Elem>
friend class UniqueSetIter< Elem > [friend]

Definition at line 136 of file UniqueSetRaw.h.


Member Data Documentation

template<class Elem>
EntryGlob<Elem>* UniqueSetRaw< Elem >::globHead [protected]

Definition at line 281 of file UniqueSetRaw.h.

Referenced by UniqueSetIter< T >::begin(), and UniqueSetIter< T >::UniqueSetIter().

template<class Elem>
int UniqueSetRaw< Elem >::refCount [protected]

Definition at line 279 of file UniqueSetRaw.h.


The documentation for this class was generated from the following file:
Generated on Thu Nov 23 01:17:20 2017 for NAMD by  doxygen 1.4.7