Use epicsStrHash()

This commit is contained in:
Andrew Johnson
2009-03-24 17:04:02 +00:00
parent 57635a364b
commit 547e9bcfea
2 changed files with 11 additions and 82 deletions

View File

@@ -3,8 +3,7 @@
* National Laboratory.
* Copyright (c) 2002 The Regents of the University of California, as
* Operator of Los Alamos National Laboratory.
* EPICS BASE Versions 3.13.7
* and higher are distributed subject to a Software License Agreement found
* EPICS BASE is distributed subject to a Software License Agreement found
* in file LICENSE that is included with this distribution.
\*************************************************************************/

View File

@@ -3,8 +3,7 @@
* National Laboratory.
* Copyright (c) 2002 The Regents of the University of California, as
* Operator of Los Alamos National Laboratory.
* EPICS BASE Versions 3.13.7
* and higher are distributed subject to a Software License Agreement found
* EPICS BASE is distributed subject to a Software License Agreement found
* in file LICENSE that is included with this distribution.
\*************************************************************************/
/*
@@ -43,6 +42,7 @@
#endif
#include "tsSLList.h"
#include "epicsString.h"
#include "shareLib.h"
typedef size_t resTableIndex;
@@ -269,7 +269,6 @@ private:
stringId ( const stringId &);
const char * pStr;
const allocationType allocType;
static const unsigned char fastHashPermutedIndexSpace[256];
};
/////////////////////////////////////////////////
@@ -397,6 +396,7 @@ void resTable<T,ID>::show ( unsigned level ) const
double X = 0.0;
double XX = 0.0;
unsigned maxEntries = 0u;
unsigned empty = 0;
for ( unsigned i = 0u; i < N; i++ ) {
tsSLIter<T> pItem = this->pTable[i].firstIter ();
unsigned count = 0;
@@ -413,14 +413,16 @@ void resTable<T,ID>::show ( unsigned level ) const
if ( count > maxEntries ) {
maxEntries = count;
}
}
} else
empty++;
}
double mean = X / N;
double stdDev = sqrt( XX / N - mean * mean );
printf (
"entries per bucket: mean = %f std dev = %f max = %d\n",
"entries per bucket: mean = %f std dev = %f max = %u\n",
mean, stdDev, maxEntries );
printf("%u empty buckets\n", empty);
if ( X != this->nInUse ) {
printf ("this->nInUse didnt match items counted which was %f????\n", X );
}
@@ -1156,86 +1158,14 @@ stringId::~stringId()
//
// stringId::hash()
//
// This is a modification of the algorithm described in
// "Fast Hashing of Variable Length Text Strings", Peter K. Pearson,
// Communications of the ACM, June 1990. The initial modifications
// were designed by Marty Kraimer. Some additional minor optimizations
// by Jeff Hill.
//
resTableIndex stringId::hash() const
{
const unsigned stringIdMinIndexWidth = CHAR_BIT;
const unsigned stringIdMaxIndexWidth = CHAR_BIT * sizeof ( unsigned );
const unsigned char *pUStr =
reinterpret_cast < const unsigned char * > ( this->pStr );
if ( ! pUStr ) {
if (!this->pStr) {
return 0u;
}
unsigned h0 = 0;
unsigned h1 = 0;
unsigned h2 = 0;
unsigned h3 = 0;
unsigned c;
while ( true ) {
c = * ( pUStr++ );
if ( c == 0 ) {
break;
}
h0 = fastHashPermutedIndexSpace [ h0 ^ c ];
c = * ( pUStr++ );
if ( c == 0 ) {
break;
}
h1 = fastHashPermutedIndexSpace [ h1 ^ c ];
c = * ( pUStr++ );
if ( c == 0 ) {
break;
}
h2 = fastHashPermutedIndexSpace [ h2 ^ c ];
c = * ( pUStr++ );
if ( c == 0 ) {
break;
}
h3 = fastHashPermutedIndexSpace [ h3 ^ c ];
}
h0 = ( h3 << 24 ) | ( h2 << 16 ) | ( h1 << 8 ) | h0;
return integerHash ( stringIdMinIndexWidth, stringIdMaxIndexWidth, h0 );
return epicsStrHash(this->pStr, 0);
}
//
// This is a modification of the algorithm described in
// "Fast Hashing of Variable Length Text Strings", Peter K.
// Pearson, Communications of the ACM, June 1990
// The modifications were designed by Marty Kraimer
//
const unsigned char stringId::fastHashPermutedIndexSpace[256] = {
39,159,180,252, 71, 6, 13,164,232, 35,226,155, 98,120,154, 69,
157, 24,137, 29,147, 78,121, 85,112, 8,248,130, 55,117,190,160,
176,131,228, 64,211,106, 38, 27,140, 30, 88,210,227,104, 84, 77,
75,107,169,138,195,184, 70, 90, 61,166, 7,244,165,108,219, 51,
9,139,209, 40, 31,202, 58,179,116, 33,207,146, 76, 60,242,124,
254,197, 80,167,153,145,129,233,132, 48,246, 86,156,177, 36,187,
45, 1, 96, 18, 19, 62,185,234, 99, 16,218, 95,128,224,123,253,
42,109, 4,247, 72, 5,151,136, 0,152,148,127,204,133, 17, 14,
182,217, 54,199,119,174, 82, 57,215, 41,114,208,206,110,239, 23,
189, 15, 3, 22,188, 79,113,172, 28, 2,222, 21,251,225,237,105,
102, 32, 56,181,126, 83,230, 53,158, 52, 59,213,118,100, 67,142,
220,170,144,115,205, 26,125,168,249, 66,175, 97,255, 92,229, 91,
214,236,178,243, 46, 44,201,250,135,186,150,221,163,216,162, 43,
11,101, 34, 37,194, 25, 50, 12, 87,198,173,240,193,171,143,231,
111,141,191,103, 74,245,223, 20,161,235,122, 63, 89,149, 73,238,
134, 68, 93,183,241, 81,196, 49,192, 65,212, 94,203, 10,200, 47
};
#endif // if instantiateRecourceLib is defined
#endif // INCresourceLibh