diff --git a/src/cxxTemplates/resourceLib.cc b/src/cxxTemplates/resourceLib.cc new file mode 100644 index 000000000..c6d1228dc --- /dev/null +++ b/src/cxxTemplates/resourceLib.cc @@ -0,0 +1,143 @@ +/* + * + * $Id$ + * + * Author Jeffrey O. Hill + * johill@lanl.gov + * 505 665 1831 + * + * Experimental Physics and Industrial Control System (EPICS) + * + * Copyright 1991, the Regents of the University of California, + * and the University of Chicago Board of Governors. + * + * This software was produced under U.S. Government contracts: + * (W-7405-ENG-36) at the Los Alamos National Laboratory, + * and (W-31-109-ENG-38) at Argonne National Laboratory. + * + * Initial development by: + * The Controls and Automation Group (AT-8) + * Ground Test Accelerator + * Accelerator Technology Division + * Los Alamos National Laboratory + * + * Co-developed with + * The Controls and Computing Group + * Accelerator Systems Division + * Advanced Photon Source + * Argonne National Laboratory + * + * + * History + * $Log$ + * + * NOTES: + * .01 Storage for identifier must persist until an item is deleted + * .02 class T must derive from class ID and tsSLNode + */ + +#ifndef INCresourceLibcc +#define INCresourceLibcc + +#include + +// +// resTable::init() +// +template +int resTable::init(unsigned nHashTableEntries) +{ + unsigned nbits; + + if (nHashTableEntries<1u) { + return -1; + } + + // + // count the number of bits in the hash index + // + for (nbits=0; nbitshashIdMask = (1<hashIdMask) == 0){ + break; + } + } + this->hashIdNBits = nbits; + this->nInUse = 0u; + this->pTable = new tsSLList [this->hashIdMask+1u]; + if (!pTable) { + return -1; + } + return 0; +} + +// +// resTable::destroyAllEntries() +// +template +void resTable::destroyAllEntries() +{ + tsSLList *pList = this->pTable; + + while (pList<&this->pTable[this->hashIdMask+1]) { + tsSLIter iter(*pList); + T *pItem; + while ( (pItem = iter()) ) { + iter.remove(); + delete pItem; + this->nInUse--; + } + pList++; + } +} + +// +// resTable::show +// +template +void resTable::show (unsigned level) +{ + tsSLList *pList; + double X; + double XX; + double mean; + double stdDev; + unsigned maxEntries; + + printf("resTable with %d resources installed\n", this->nInUse); + + if (level >=1u) { + pList = this->pTable; + X = 0.0; + XX = 0.0; + maxEntries = 0; + while (pList < &this->pTable[this->hashIdMask+1]) { + unsigned count; + tsSLIter iter(*pList); + T *pItem; + + count = 0; + while ( (pItem = iter()) ) { + if (level >= 3u) { + pItem->show (level); + } + count++; + } + X += count; + XX += count*count; + if (count>maxEntries) { + maxEntries = count; + } + pList++; + } + + mean = X/(this->hashIdMask+1); + stdDev = sqrt(XX/(this->hashIdMask+1)- mean*mean); + printf( + "entries/table index - mean = %f std dev = %f max = %d\n", + mean, stdDev, maxEntries); + } +} + +#endif // INCresourceLibcc +