NAMD
Public Member Functions | List of all members
HashPool< T > Class Template Reference

#include <CompressPsf.h>

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.

References HashPool< T >::clear().

105  {
106  clear();
107  }
void clear()
Definition: CompressPsf.h:109

Member Function Documentation

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

Definition at line 109 of file CompressPsf.h.

Referenced by HashPool< T >::~HashPool().

109  {
110  // Delete the pool entries
111  for ( int i=0; i < pool.size(); i++)
112  delete pool[i];
113  // Clear the pool and hash table
114  pool.clear();
115  index_table.empty();
116  }
template<class T >
void HashPool< T >::dump_tables ( )

Definition at line 1386 of file CompressPsf.C.

References HashPoolAdaptorT< T >::hash().

Referenced by HashPool< T >::lookupCstPool().

1387 {
1388  for(int j=0; j < pool.size(); j++) {
1389  HashPoolAdaptorT<T>* pval = pool[j];
1390  CmiPrintf("Pool[%d]=%p %p hash = %d\n",j,pool[j],pval,pval->hash());
1391  }
1392  CkHashtableIterator *iter = index_table.iterator();
1393  void *key,*indx;
1394  while (iter->hasNext()) {
1395  indx = iter->next(&key);
1397  CmiPrintf("key %p indx %p %d hash=%d\n",key,indx,*((int *)indx),pkey->hash());
1398  }
1399 }
CkHashCode hash(void) const
Definition: CompressPsf.h:77
template<typename T >
int HashPool< T >::lookupCstPool ( const T &  val)
inline

Definition at line 118 of file CompressPsf.h.

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

119  {
120  HashPoolAdaptorT<T> hx(val);
121  // Ugly: Can't store zeros in the table, so add 1 to indices on insert and
122  // subtract 1 to get real index when retrieving
123  int loc = index_table.get(hx) - 1;
124 #if 0
125  int i;
126  for(i=0; i < pool.size(); i++)
127  {
128  if (pool[i]->getVal() == val) {
129  if (i != loc) {
130  CmiPrintf("Get[%d] returned %d, actual is %d\n",hx.hash(),loc,i);
131  dump_tables();
132  loc = i;
133  }
134  break;
135  }
136  }
137  if (loc != -1 && i == pool.size()) {
138  CmiPrintf("Get returned %d, actual not found\n",loc);
139  }
140 #endif
141  return loc;
142  }
void dump_tables()
Definition: CompressPsf.C:1386
template<typename T >
T& HashPool< T >::operator[] ( int  i) const
inline

Definition at line 163 of file CompressPsf.h.

163 { return pool[i]->getVal(); }
template<typename T >
void HashPool< T >::push_back ( const T &  x)
inline

Definition at line 144 of file CompressPsf.h.

References x.

145  {
146  // Behave like a STL vector, but also store the indexing info in
147  // the hashtable index
148 
149  // Add to vector
151  pool.push_back(val);
152  // Also add to hash table. Make sure pointer doesn't change
153  int* index = &(index_table.put(*val));
154  // Ugly: Can't store zeros in the table, so add one to all entries
155  *index = pool.size(); // pool.size() - 1 + 1
156 
157  // CmiPrintf("Adding hx=%p hash=%d index[%p]=%d\n",&val,val->hash(),index,*index);
158  // dump_tables();
159  }
gridSize x
template<typename T >
int HashPool< T >::size ( )
inline

Definition at line 165 of file CompressPsf.h.

165 { return pool.size(); }

The documentation for this class was generated from the following files: