HashPool< T > Class Template Reference

#include <CompressPsf.h>

List of all members.

Public Member Functions

 ~HashPool ()
void clear ()
int lookupCstPool (const T &val)
void push_back (const T &x)
void dump_tables ()
T & operator[] (int i) const
int size ()


Detailed Description

template<typename T>
class HashPool< T >

Definition at line 103 of file CompressPsf.h.


Constructor & Destructor Documentation

template<typename T>
HashPool< T >::~HashPool (  )  [inline]

Definition at line 105 of file CompressPsf.h.

00105               {
00106     clear();
00107   }


Member Function Documentation

template<typename T>
void HashPool< T >::clear (  )  [inline]

Definition at line 109 of file CompressPsf.h.

00109                {
00110     // Delete the pool entries
00111     for ( int i=0; i < pool.size(); i++)
00112       delete pool[i];
00113     // Clear the pool and hash table
00114     pool.clear();
00115     index_table.empty();
00116   }

template<class T>
void HashPool< T >::dump_tables (  ) 

Definition at line 1386 of file CompressPsf.C.

References HashPoolAdaptorT< T >::hash(), and j.

01387 {
01388   for(int j=0; j < pool.size(); j++) {
01389     HashPoolAdaptorT<T>* pval = pool[j];
01390     CmiPrintf("Pool[%d]=%p %p  hash = %d\n",j,pool[j],pval,pval->hash());
01391   }
01392   CkHashtableIterator *iter = index_table.iterator();
01393   void *key,*indx;
01394   while (iter->hasNext()) {
01395     indx = iter->next(&key);
01396     HashPoolAdaptorT<T> *pkey = (HashPoolAdaptorT<T>*)key;
01397     CmiPrintf("key %p indx %p %d hash=%d\n",key,indx,*((int *)indx),pkey->hash());
01398   }
01399 }

template<typename T>
int HashPool< T >::lookupCstPool ( const T &  val  )  [inline]

Definition at line 118 of file CompressPsf.h.

References HashPoolAdaptorT< T >::getVal(), and HashPoolAdaptorT< T >::hash().

00119   {
00120     HashPoolAdaptorT<T> hx(val);
00121     // Ugly: Can't store zeros in the table, so add 1 to indices on insert and
00122     // subtract 1 to get real index when retrieving
00123     int loc = index_table.get(hx) - 1;
00124 #if 0
00125     int i;
00126     for(i=0; i < pool.size(); i++)
00127     {
00128       if (pool[i]->getVal() == val)  {
00129         if (i != loc) {
00130           CmiPrintf("Get[%d] returned %d, actual is %d\n",hx.hash(),loc,i);
00131           dump_tables();
00132           loc = i;
00133         }
00134         break;
00135       }
00136     }
00137     if (loc != -1 && i == pool.size()) {
00138       CmiPrintf("Get returned %d, actual not found\n",loc);
00139     }
00140 #endif
00141     return loc;
00142   }

template<typename T>
T& HashPool< T >::operator[] ( int  i  )  const [inline]

Definition at line 163 of file CompressPsf.h.

00163 { return pool[i]->getVal(); }

template<typename T>
void HashPool< T >::push_back ( const T &  x  )  [inline]

Definition at line 144 of file CompressPsf.h.

00145   {
00146     // Behave like a STL vector, but also store the indexing info in
00147     // the hashtable index
00148     
00149     // Add to vector
00150     HashPoolAdaptorT<T>* val = new HashPoolAdaptorT<T>(x);
00151     pool.push_back(val);
00152     // Also add to hash table. Make sure pointer doesn't change
00153     int* index = &(index_table.put(*val));
00154     // Ugly: Can't store zeros in the table, so add one to all entries
00155     *index = pool.size(); // pool.size()  - 1 + 1
00156     
00157     //  CmiPrintf("Adding hx=%p hash=%d index[%p]=%d\n",&val,val->hash(),index,*index);
00158     //  dump_tables();  
00159   }

template<typename T>
int HashPool< T >::size (  )  [inline]

Definition at line 165 of file CompressPsf.h.

00165 { return pool.size(); }


The documentation for this class was generated from the following files:
Generated on Sun Sep 24 01:17:18 2017 for NAMD by  doxygen 1.4.7