This is Unofficial EPICS BASE Doxygen Site
resTable< T, ID > Class Template Reference

#include "resourceLib.h"

Public Types

typedef resTableIter< T, ID > iterator
 
typedef resTableIterConst< T, ID > iteratorConst
 

Public Member Functions

 resTable ()
 
virtual ~resTable ()
 
void show (unsigned level) const
 
void verify () const
 
int add (T &res)
 
T * remove (const ID &idIn)
 
void removeAll (tsSLList< T > &destination)
 
T * lookup (const ID &idIn) const
 
void traverse (void(T::*pCB)())
 
void traverseConst (void(T::*pCB)() const ) const
 
unsigned numEntriesInstalled () const
 
void setTableSize (const unsigned newTableSize)
 
iterator firstIter ()
 
iteratorConst firstIter () const
 

Friends

class resTableIter< T, ID >
 
class resTableIterConst< T, ID >
 

Detailed Description

template<class T, class ID>
class resTable< T, ID >

Definition at line 76 of file resourceLib.h.

Member Typedef Documentation

template<class T, class ID>
typedef resTableIter< T, ID > resTable< T, ID >::iterator

Definition at line 95 of file resourceLib.h.

template<class T, class ID>
typedef resTableIterConst< T, ID > resTable< T, ID >::iteratorConst

Definition at line 96 of file resourceLib.h.

Constructor & Destructor Documentation

template<class T , class ID >
resTable< T, ID >::resTable ( )
inline

Definition at line 280 of file resourceLib.h.

280  :
281  pTable ( 0 ), nextSplitIndex ( 0 ), hashIxMask ( 0 ),
282  hashIxSplitMask ( 0 ), nBitsHashIxSplitMask ( 0 ),
283  logBaseTwoTableSize ( 0 ), nInUse ( 0 ) {}
template<class T , class ID >
resTable< T, ID >::~resTable ( )
virtual

Definition at line 690 of file resourceLib.h.

691 {
692  operator delete ( this->pTable );
693 }

Member Function Documentation

template<class T, class ID >
int resTable< T, ID >::add ( T &  res)

Definition at line 643 of file resourceLib.h.

644 {
645  if ( ! this->pTable ) {
646  this->setTableSizePrivate ( 10 );
647  }
648  else if ( this->nInUse >= this->tableSize() ) {
649  this->splitBucket ();
650  tsSLList<T> &list = this->pTable[this->hash(res)];
651  if ( this->find ( list, res ) != 0 ) {
652  return -1;
653  }
654  }
655  tsSLList<T> &list = this->pTable[this->hash(res)];
656  if ( this->find ( list, res ) != 0 ) {
657  return -1;
658  }
659  list.add ( res );
660  this->nInUse++;
661  return 0;
662 }
void add(T &item)
Definition: tsSLList.h:211
template<class T , class ID >
resTableIter< T, ID > resTable< T, ID >::firstIter ( )
inline

Definition at line 721 of file resourceLib.h.

722 {
723  return resTableIter < T, ID > ( *this );
724 }
template<class T , class ID >
resTableIterConst< T, ID > resTable< T, ID >::firstIter ( ) const
inline

Definition at line 715 of file resourceLib.h.

716 {
717  return resTableIterConst < T, ID > ( *this );
718 }
template<class T , class ID>
T * resTable< T, ID >::lookup ( const ID &  idIn) const
inline

Definition at line 342 of file resourceLib.h.

343 {
344  if ( this->pTable ) {
345  tsSLList<T> & list = this->pTable [ this->hash ( idIn ) ];
346  return this->find ( list, idIn );
347  }
348  else {
349  return 0;
350  }
351 }
template<class T , class ID >
unsigned resTable< T, ID >::numEntriesInstalled ( ) const
inline

Definition at line 509 of file resourceLib.h.

510 {
511  return this->nInUse;
512 }
template<class T , class ID>
T * resTable< T, ID >::remove ( const ID &  idIn)

Definition at line 297 of file resourceLib.h.

298 {
299  if ( this->pTable ) {
300  // search list for idIn and remove the first match
301  tsSLList<T> & list = this->pTable [ this->hash(idIn) ];
302  tsSLIter <T> pItem = list.firstIter ();
303  T *pPrev = 0;
304  while ( pItem.valid () ) {
305  const ID & idOfItem = *pItem;
306  if ( idOfItem == idIn ) {
307  if ( pPrev ) {
308  list.remove ( *pPrev );
309  }
310  else {
311  list.get ();
312  }
313  this->nInUse--;
314  break;
315  }
316  pPrev = pItem.pointer ();
317  pItem++;
318  }
319  return pItem.pointer ();
320  }
321  else {
322  return 0;
323  }
324 }
T * pointer() const
Definition: tsSLList.h:438
tsSLIterConst< T > firstIter() const
Definition: tsSLList.h:262
T * get()
Definition: tsSLList.h:220
void remove(T &itemBefore)
Definition: tsSLList.h:254
bool valid() const
Definition: tsSLList.h:384
template<class T, class ID >
void resTable< T, ID >::removeAll ( tsSLList< T > &  destination)

Definition at line 327 of file resourceLib.h.

328 {
329  const unsigned N = this->tableSize ();
330  for ( unsigned i = 0u; i < N; i++ ) {
331  while ( T * pItem = this->pTable[i].get() ) {
332  destination.add ( *pItem );
333  }
334  }
335  this->nInUse = 0;
336 }
int i
Definition: scan.c:967
void add(T &item)
Definition: tsSLList.h:211
template<class T , class ID >
void resTable< T, ID >::setTableSize ( const unsigned  newTableSize)

Definition at line 528 of file resourceLib.h.

529 {
530  if ( newTableSize == 0u ) {
531  return;
532  }
533 
534  //
535  // count the number of bits in newTableSize and round up
536  // to the next power of two
537  //
538  unsigned newMask = newTableSize - 1;
539  unsigned nbits;
540  for ( nbits = 0; nbits < sizeof (newTableSize) * CHAR_BIT; nbits++ ) {
541  unsigned nBitsMask = resTableBitMask ( nbits );
542  if ( ( newMask & ~nBitsMask ) == 0){
543  break;
544  }
545  }
546  setTableSizePrivate ( nbits );
547 }
template<class T , class ID >
void resTable< T, ID >::show ( unsigned  level) const

Definition at line 371 of file resourceLib.h.

372 {
373  const unsigned N = this->tableSize ();
374 
375  printf ( "Hash table with %u buckets and %u items of type %s installed\n",
376  N, this->nInUse, typeid(T).name() );
377 
378  if ( level >= 1u && N ) {
379 
380  if ( level >= 2u ) {
381  tsSLList<T> * pList = this->pTable;
382  while ( pList < & this->pTable[N] ) {
383  tsSLIter<T> pItem = pList->firstIter ();
384  while ( pItem.valid () ) {
385  tsSLIter<T> pNext = pItem;
386  pNext++;
387  pItem.pointer()->show ( level - 2u );
388  pItem = pNext;
389  }
390  pList++;
391  }
392  }
393 
394  double X = 0.0;
395  double XX = 0.0;
396  unsigned maxEntries = 0u;
397  unsigned empty = 0;
398  for ( unsigned i = 0u; i < N; i++ ) {
399  tsSLIter<T> pItem = this->pTable[i].firstIter ();
400  unsigned count = 0;
401  while ( pItem.valid () ) {
402  if ( level >= 3u ) {
403  pItem->show ( level );
404  }
405  count++;
406  pItem++;
407  }
408  if ( count > 0u ) {
409  X += count;
410  XX += count * count;
411  if ( count > maxEntries ) {
412  maxEntries = count;
413  }
414  } else
415  empty++;
416  }
417 
418  double mean = X / N;
419  double stdDev = sqrt( XX / N - mean * mean );
420  printf (
421  "entries per bucket: mean = %f std dev = %f max = %u\n",
422  mean, stdDev, maxEntries );
423  printf("%u empty buckets\n", empty);
424  if ( X != this->nInUse ) {
425  printf ("this->nInUse didnt match items counted which was %f????\n", X );
426  }
427  }
428 }
T * pointer() const
Definition: tsSLList.h:438
epics::pvData::BitSetPtr empty
Definition: pvAccess.cpp:135
tsSLIterConst< T > firstIter() const
Definition: tsSLList.h:262
int i
Definition: scan.c:967
#define printf
Definition: epicsStdio.h:41
bool valid() const
Definition: tsSLList.h:384
template<class T, class ID >
void resTable< T, ID >::traverse ( void(T::*)()  pCB)

Definition at line 475 of file resourceLib.h.

476 {
477  const unsigned N = this->tableSize ();
478  for ( unsigned i = 0u; i < N; i++ ) {
479  tsSLIter<T> pItem = this->pTable[i].firstIter ();
480  while ( pItem.valid () ) {
481  tsSLIter<T> pNext = pItem;
482  pNext++;
483  ( pItem.pointer ()->*pCB ) ();
484  pItem = pNext;
485  }
486  }
487 }
T * pointer() const
Definition: tsSLList.h:438
int i
Definition: scan.c:967
bool valid() const
Definition: tsSLList.h:384
template<class T, class ID >
void resTable< T, ID >::traverseConst ( void(T::*)() const  pCB) const

Definition at line 493 of file resourceLib.h.

494 {
495  const unsigned N = this->tableSize ();
496  for ( unsigned i = 0u; i < N; i++ ) {
497  const tsSLList < T > & table = this->pTable[i];
498  tsSLIterConst<T> pItem = table.firstIter ();
499  while ( pItem.valid () ) {
500  tsSLIterConst<T> pNext = pItem;
501  pNext++;
502  ( pItem.pointer ()->*pCB ) ();
503  pItem = pNext;
504  }
505  }
506 }
tsSLIterConst< T > firstIter() const
Definition: tsSLList.h:262
int i
Definition: scan.c:967
const T * pointer() const
Definition: tsSLList.h:360
bool valid() const
Definition: tsSLList.h:306
template<class T , class ID >
void resTable< T, ID >::verify ( ) const

Definition at line 432 of file resourceLib.h.

433 {
434  const unsigned N = this->tableSize ();
435 
436  if ( this->pTable ) {
437  assert ( this->nextSplitIndex <= this->hashIxMask + 1 );
438  assert ( this->hashIxMask );
439  assert ( this->hashIxMask == ( this->hashIxSplitMask >> 1 ) );
440  assert ( this->hashIxSplitMask );
441  assert ( this->nBitsHashIxSplitMask );
442  assert ( resTableBitMask ( this->nBitsHashIxSplitMask )
443  == this->hashIxSplitMask );
444  assert ( this->logBaseTwoTableSize );
445  assert ( this->nBitsHashIxSplitMask <= this->logBaseTwoTableSize );
446  }
447  else {
448  assert ( this->nextSplitIndex == 0 );
449  assert ( this->hashIxMask == 0 );
450  assert ( this->hashIxSplitMask == 0 );
451  assert ( this->nBitsHashIxSplitMask == 0 );
452  assert ( this->logBaseTwoTableSize == 0 );
453  }
454 
455  unsigned total = 0u;
456  for ( unsigned i = 0u; i < N; i++ ) {
457  tsSLIter<T> pItem = this->pTable[i].firstIter ();
458  unsigned count = 0;
459  while ( pItem.valid () ) {
460  resTableIndex index = this->hash ( *pItem );
461  assert ( index == i );
462  count++;
463  pItem++;
464  }
465  total += count;
466  }
467  assert ( total == this->nInUse );
468 }
#define assert(exp)
Declare that a condition should be true.
Definition: epicsAssert.h:70
int i
Definition: scan.c:967
size_t resTableIndex
Definition: resourceLib.h:45
bool valid() const
Definition: tsSLList.h:384

Friends And Related Function Documentation

template<class T, class ID>
friend class resTableIter< T, ID >
friend

Definition at line 115 of file resourceLib.h.

template<class T, class ID>
friend class resTableIterConst< T, ID >
friend

Definition at line 116 of file resourceLib.h.


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