cgma
|
#include <IntegerHash.hpp>
Public Member Functions | |
IntegerHash (int nBins=101, int binSizeIncr=100) | |
~IntegerHash () | |
void | getNumberofBins (int *numBins) const |
int * | getHashBin (int hashValue, int *binSize) |
void | addtoHashList (int hashValue, int value) |
Private Member Functions | |
void | allocateMoreHash (int index) |
Private Attributes | |
int | numberofBins |
int | binSizeIncrement |
int ** | binArray |
int * | binSize |
int * | maxBinSize |
int | hashIndex |
Definition at line 31 of file IntegerHash.hpp.
IntegerHash::IntegerHash | ( | int | nBins = 101 , |
int | binSizeIncr = 100 |
||
) |
Definition at line 29 of file IntegerHash.cpp.
{ int i; numberofBins = numBins; binSizeIncrement = binSizeIncr; binSize = new int[numberofBins]; maxBinSize = new int[numberofBins]; binArray = new int *[numberofBins]; for ( i = 0; i < numberofBins; i++ ) { maxBinSize[i] = binSizeIncrement; binSize[i] = 0; binArray[i] = new int[maxBinSize[i]]; } }
Definition at line 46 of file IntegerHash.cpp.
{ int i; if ( binSize) delete[] binSize; if ( maxBinSize) delete[] maxBinSize; for ( i = 0; i < numberofBins; i++ ) { if ( binArray[i] ) delete[] binArray[i]; } if ( binArray ) delete [] binArray; }
void IntegerHash::addtoHashList | ( | int | hashValue, |
int | value | ||
) |
Definition at line 70 of file IntegerHash.cpp.
{ int i; hashIndex = hashValue%numberofBins; // Is it already there? for ( i = 0; i < binSize[hashIndex]; i++ ) { if ( binArray[hashIndex][i] == value ) return; } if ( binSize[hashIndex] > maxBinSize[hashIndex] - 1 ) { // Add more memory to this bin. allocateMoreHash(hashIndex); } binArray[hashIndex][binSize[hashIndex]] = value; binSize[hashIndex] += 1; }
void IntegerHash::allocateMoreHash | ( | int | index | ) | [private] |
Definition at line 88 of file IntegerHash.cpp.
{ int *itemp; maxBinSize[hashIndex] += binSizeIncrement; itemp = new int[maxBinSize[hashIndex]]; memcpy(itemp,binArray[index],binSize[hashIndex]*sizeof(int)); delete [] binArray[index]; binArray[index] = itemp; }
int * IntegerHash::getHashBin | ( | int | hashValue, |
int * | binSize | ||
) |
Definition at line 63 of file IntegerHash.cpp.
void IntegerHash::getNumberofBins | ( | int * | numBins | ) | const |
Definition at line 58 of file IntegerHash.cpp.
{ *numBins = numberofBins; }
int** IntegerHash::binArray [private] |
Definition at line 44 of file IntegerHash.hpp.
int* IntegerHash::binSize [private] |
Definition at line 45 of file IntegerHash.hpp.
int IntegerHash::binSizeIncrement [private] |
Definition at line 43 of file IntegerHash.hpp.
int IntegerHash::hashIndex [private] |
Definition at line 45 of file IntegerHash.hpp.
int * IntegerHash::maxBinSize [private] |
Definition at line 45 of file IntegerHash.hpp.
int IntegerHash::numberofBins [private] |
Definition at line 42 of file IntegerHash.hpp.