NAMD
Public Member Functions | Protected Attributes | Friends | List of all members
UniqueSetRaw< Elem > Class Template Reference

#include <UniqueSetRaw.h>

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 18 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.

399  :
400  table(0), tableLength(0), numElem(0), growable(1) {
401  const int minGlobSize = 32;
402  isSafeNoDestruction = 1;
403  growSize = 0;
404  globSize = minGlobSize;
405  init(size);
406 }
int size(void) const
Definition: UniqueSetRaw.h:249
template<class Elem>
UniqueSetRaw< Elem >::UniqueSetRaw ( const UniqueSetRaw< Elem > &  us)
inline

Definition at line 144 of file UniqueSetRaw.h.

144 { copy(us); }
template<class Elem>
UniqueSetRaw< Elem >::~UniqueSetRaw ( void  )
inline

Definition at line 146 of file UniqueSetRaw.h.

146 { cleanUp(); }

Member Function Documentation

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

Definition at line 190 of file UniqueSetRaw.h.

190  {
191  int tableSlot = elem.hash() % tableLength;
192  int doadd = 1;
193  for (Entry<Elem> *e = table[tableSlot]; e; e=e->next()) {
194  if (e->obj == elem) { doadd = 0; break; }
195  }
196  if (doadd) {
197  Entry<Elem> *entry = nextFree();
198  *entry = elem; // sets used flag
199  table[tableSlot] = entry->setNext(table[tableSlot]);
200  if ( ++numElem > growSize)
201  rehash();
202  }
203  return(doadd);
204  }
Entry< Elem > * next(void) const
Definition: UniqueSetRaw.h:45
void rehash(void)
Definition: UniqueSetRaw.h:153
Entry< Elem > * setNext(Entry< Elem > *e)
Definition: UniqueSetRaw.h:74
template<class Elem>
void UniqueSetRaw< Elem >::clear ( int  n = 0)
inline

Definition at line 251 of file UniqueSetRaw.h.

251  {
252  if (!n) n = size();
253  cleanUp();
254  init(n); // have to have something currently for a table
255  }
int size(void) const
Definition: UniqueSetRaw.h:249
template<class Elem>
int UniqueSetRaw< Elem >::del ( const Elem &  elem)
inline

Definition at line 226 of file UniqueSetRaw.h.

226  {
227  int tableSlot = elem.hash() % tableLength;
228  int dodel = 0;
229 
230  Entry<Elem> *prev = 0;
231  Entry<Elem> *e = table[tableSlot];
232  while(e) {
233  if (e->obj == elem) {
234  if (0 == prev) {
235  table[tableSlot] = e->removeSelf();
236  } else {
237  prev->setNext(e->removeSelf());
238  }
239  addFree(e); dodel = 1; numElem--;
240  break;
241  }
242  prev = e;
243  e = e->next();
244  }
245  return dodel;
246  }
Entry< Elem > * next(void) const
Definition: UniqueSetRaw.h:45
Elem obj
Definition: UniqueSetRaw.h:36
Entry< Elem > * setNext(Entry< Elem > *e)
Definition: UniqueSetRaw.h:74
Entry< Elem > * removeSelf(void)
Definition: UniqueSetRaw.h:58
template<class Elem>
Elem* UniqueSetRaw< Elem >::find ( const Elem &  elem)
inline

Definition at line 215 of file UniqueSetRaw.h.

215  {
216  register Entry<Elem> *e = table[elem.hash() % tableLength];
217  while(e) {
218  if (elem == e->obj ) {
219  return (&(e->obj));
220  }
221  e = e->next();
222  }
223  return (0);
224  }
Entry< Elem > * next(void) const
Definition: UniqueSetRaw.h:45
Elem obj
Definition: UniqueSetRaw.h:36
template<class Elem>
int UniqueSetRaw< Elem >::load ( const Elem &  elem)
inline

Definition at line 206 of file UniqueSetRaw.h.

206  {
207  Entry<Elem> *entry = nextFree();
208  *entry = elem; // sets used flag
209  table[0] = entry->setNext(table[0]);
210  ++numElem;
211  return(1);
212  }
Entry< Elem > * setNext(Entry< Elem > *e)
Definition: UniqueSetRaw.h:74
template<class Elem>
UniqueSetRaw<Elem>& UniqueSetRaw< Elem >::operator= ( const UniqueSetRaw< Elem > &  us)
inline

Definition at line 148 of file UniqueSetRaw.h.

148  {
149  copy(us);
150  return *this;
151  }
template<class Elem>
void UniqueSetRaw< Elem >::rehash ( void  )
inline

Definition at line 153 of file UniqueSetRaw.h.

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

153 { rehash(numElem); }
void rehash(void)
Definition: UniqueSetRaw.h:153
template<class Elem>
void UniqueSetRaw< Elem >::rehash ( int  size)
inline

Definition at line 156 of file UniqueSetRaw.h.

156  {
157  // Store away old pointers and Entry<Elem>(s)
158  int oldTableLength= tableLength;
159  Entry<Elem> **oldTable = table;
160 
161  // recreate the table
162  tableLength = findSize(numElem > size ? numElem : size);
163  if (tableLength == oldTableLength)
164  return;
165  numElem = 0;
166  table = new Entry<Elem>*[tableLength];
167  growSize = tableLength * 4;
168 
169  // 0 table
170  Entry<Elem> **t = table; Entry<Elem> **e = table+tableLength;
171  for (; t != e; *t++ = 0);
172 
173  // go thru old table and chains of Entry<Elem>(s)
174  for (int i=0; i<oldTableLength; i++) {
175  Entry<Elem> *e = oldTable[i];
176  while(e) {
177  Entry<Elem> *tmp = e->next();
178  remapEntry(e);
179  numElem++;
180  e = tmp;
181  }
182  }
183  delete[] oldTable;
184  }
int size(void) const
Definition: UniqueSetRaw.h:249
Entry< Elem > * next(void) const
Definition: UniqueSetRaw.h:45
template<class Elem>
void UniqueSetRaw< Elem >::setSafeNoDestruction ( int  flag)
inline

Definition at line 187 of file UniqueSetRaw.h.

187 { isSafeNoDestruction = flag; }
template<class Elem>
int UniqueSetRaw< Elem >::size ( void  ) const
inline

Definition at line 249 of file UniqueSetRaw.h.

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

249 { 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
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: