CHashTable Class Reference

#include <svdhash.h>

Collaboration diagram for CHashTable:

Collaboration graph
[legend]

Public Member Functions

 CHashTable (void)
void ResetStats (void)
void GetStats (unsigned int *hashsize, int *entries, INT64 *deletes, INT64 *scans, INT64 *hits, INT64 *checks, int *max_scan)
INT64 GetEntryCount ()
void Reset (void)
bool Insert (HP_HEAPLENGTH nRecord, UINT32 nHash, void *pRecord)
HP_DIRINDEX FindFirstKey (UINT32 nHash)
HP_DIRINDEX FindNextKey (HP_DIRINDEX iDir, UINT32 nHash)
HP_DIRINDEX FindFirst (HP_PHEAPLENGTH pnRecord, void *pRecord)
HP_DIRINDEX FindNext (HP_PHEAPLENGTH pnRecord, void *pRecord)
void Copy (HP_DIRINDEX iDir, HP_PHEAPLENGTH pnRecord, void *pRecord)
void Remove (HP_DIRINDEX iDir)
void Update (HP_DIRINDEX iDir, HP_HEAPLENGTH nRecord, void *pRecord)
 ~CHashTable (void)

Private Member Functions

bool DoubleDirectory (void)
void Init (void)
void Final (void)

Private Attributes

unsigned int m_nDir
unsigned int m_nDirDepth
pCHashPagem_pDir
CHashPagem_hpLast
unsigned int m_iPage
unsigned int m_nPages
unsigned int m_nEntries
INT64 m_nDeletions
INT64 m_nScans
INT64 m_nHits
INT64 m_nChecks
unsigned int m_nMaxScan

Detailed Description

Definition at line 247 of file svdhash.h.


Constructor & Destructor Documentation

CHashTable::CHashTable ( void   ) 

Definition at line 2203 of file svdhash.cpp.

References Init(), and SeedRandomNumberGenerator().

02204 {
02205     SeedRandomNumberGenerator();
02206     Init();
02207 }

CHashTable::~CHashTable ( void   ) 

Definition at line 2457 of file svdhash.cpp.

References Final().

02458 {
02459     Final();
02460 }


Member Function Documentation

void CHashTable::Copy ( HP_DIRINDEX  iDir,
HP_PHEAPLENGTH  pnRecord,
void *  pRecord 
)

Definition at line 2440 of file svdhash.cpp.

References CHashPage::HeapCopy(), and m_hpLast.

Referenced by dbclean_RemoveStaleAttributeNames(), dbclean_RenumberAttributes(), hashdeleteLEN(), hashfindLEN(), hashreplLEN(), vattr_delete_LEN(), vattr_find_LEN(), and vattr_rename_LEN().

02441 {
02442     m_hpLast->HeapCopy(iDir, pnRecord, pRecord);
02443 }

bool CHashTable::DoubleDirectory ( void   )  [private]

Definition at line 2352 of file svdhash.cpp.

References m_nDir, m_nDirDepth, and m_pDir.

Referenced by Insert().

02353 {
02354     unsigned int nNewDir      = 2 * m_nDir;
02355     unsigned int nNewDirDepth = m_nDirDepth + 1;
02356 
02357     pCHashPage *pNewDir = new pCHashPage[nNewDir];
02358     if (pNewDir)
02359     {
02360         unsigned int iNewDir = 0;
02361         for (unsigned int iDir = 0; iDir < m_nDir; iDir++)
02362         {
02363             pNewDir[iNewDir++] = m_pDir[iDir];
02364             pNewDir[iNewDir++] = m_pDir[iDir];
02365         }
02366 
02367         delete [] m_pDir;
02368 
02369         m_pDir = pNewDir;
02370         m_nDirDepth = nNewDirDepth;
02371         m_nDir = nNewDir;
02372         return true;
02373     }
02374     return false;
02375 }

void CHashTable::Final ( void   )  [private]

Definition at line 2462 of file svdhash.cpp.

References m_hpLast, m_nDir, and m_pDir.

Referenced by Reset(), and ~CHashTable().

02463 {
02464     if (m_pDir)
02465     {
02466         m_hpLast = 0;
02467         for (unsigned int i = 0; i < m_nDir; i++)
02468         {
02469             CHashPage *hp = m_pDir[i];
02470 
02471             if (hp != m_hpLast && hp)
02472             {
02473                 delete hp;
02474                 m_hpLast = hp;
02475             }
02476         }
02477         delete [] m_pDir;
02478         m_pDir = NULL;
02479     }
02480 }

HP_DIRINDEX CHashTable::FindFirst ( HP_PHEAPLENGTH  pnRecord,
void *  pRecord 
)

Definition at line 2488 of file svdhash.cpp.

References CHashPage::FindFirst(), HF_FIND_END, HP_DIR_EMPTY, m_hpLast, m_iPage, m_nDir, and m_pDir.

Referenced by hash_firstentry(), hash_firstkey(), hashreplall(), and vattr_first().

02489 {
02490     m_hpLast = 0;
02491     for (m_iPage = 0; m_iPage < m_nDir; m_iPage++)
02492     {
02493         if (m_pDir[m_iPage] == m_hpLast) continue;
02494         m_hpLast = m_pDir[m_iPage];
02495         if (m_hpLast)
02496         {
02497             HP_DIRINDEX iDir = m_hpLast->FindFirst(pnRecord, pRecord);
02498             if (iDir != HP_DIR_EMPTY)
02499             {
02500                 return iDir;
02501             }
02502         }
02503     }
02504     return HF_FIND_END;
02505 }

HP_DIRINDEX CHashTable::FindFirstKey ( UINT32  nHash  ) 

Definition at line 2377 of file svdhash.cpp.

References CHashPage::FindFirstKey(), CHashPage::GetRange(), HF_FIND_END, HP_DIR_EMPTY, Log, m_hpLast, m_nChecks, m_nDir, m_nDirDepth, m_nHits, m_nMaxScan, m_nScans, m_pDir, and CLogFile::WriteString().

Referenced by dbclean_RemoveStaleAttributeNames(), dbclean_RenumberAttributes(), hashdeleteLEN(), hashfindLEN(), hashreplLEN(), vattr_delete_LEN(), vattr_find_LEN(), and vattr_rename_LEN().

02378 {
02379     m_nScans++;
02380     UINT32  iTableDir = nHash >> (32-m_nDirDepth);
02381 #ifdef HP_PROTECTION
02382     if (iTableDir >= m_nDir)
02383     {
02384         Log.WriteString("CHashTable::Insert - iTableDir out of range." ENDLINE);
02385         return HF_FIND_END;
02386     }
02387 #endif // HP_PROTECTION
02388     m_hpLast = m_pDir[iTableDir];
02389     if (!m_hpLast)
02390     {
02391         Log.WriteString("CHashTable::Insert - Page wasn't valid." ENDLINE);
02392         return HF_FIND_END;
02393     }
02394 #ifdef HP_PROTECTION
02395     UINT32  nStart, nEnd;
02396     m_hpLast->GetRange(m_nDirDepth, nStart, nEnd);
02397     if (iTableDir < nStart || nEnd < iTableDir)
02398     {
02399         Log.WriteString("CHashTable::Find - Directory points to the wrong page." ENDLINE);
02400         return HF_FIND_END;
02401     }
02402 #endif // HP_PROTECTION
02403     unsigned int numchecks;
02404 
02405     HP_DIRINDEX iDir = m_hpLast->FindFirstKey(nHash, &numchecks);
02406 
02407     m_nChecks += numchecks;
02408     if (numchecks > m_nMaxScan)
02409     {
02410         m_nMaxScan = numchecks;
02411     }
02412     if (iDir == HP_DIR_EMPTY)
02413     {
02414         return HF_FIND_END;
02415     }
02416     m_nHits++;
02417     return iDir;
02418 }

HP_DIRINDEX CHashTable::FindNext ( HP_PHEAPLENGTH  pnRecord,
void *  pRecord 
)

Definition at line 2507 of file svdhash.cpp.

References CHashPage::FindFirst(), CHashPage::FindNext(), HF_FIND_END, HP_DIR_EMPTY, m_hpLast, m_iPage, m_nDir, and m_pDir.

Referenced by hash_nextentry(), hash_nextkey(), hashreplall(), and vattr_next().

02508 {
02509     if (m_hpLast)
02510     {
02511         HP_DIRINDEX iDir = m_hpLast->FindNext(pnRecord, pRecord);
02512         if (iDir != HP_DIR_EMPTY)
02513         {
02514             return iDir;
02515         }
02516     }
02517 
02518     // Move on to the next page.
02519     //
02520     for ( ; m_iPage < m_nDir; m_iPage++)
02521     {
02522         // Move on to the next page.
02523         //
02524         if (m_pDir[m_iPage] == m_hpLast) continue;
02525         m_hpLast = m_pDir[m_iPage];
02526         if (m_hpLast)
02527         {
02528             HP_DIRINDEX iDir = m_hpLast->FindFirst(pnRecord, pRecord);
02529             if (iDir != HP_DIR_EMPTY)
02530             {
02531                 return iDir;
02532             }
02533         }
02534     }
02535     return HF_FIND_END;
02536 }

HP_DIRINDEX CHashTable::FindNextKey ( HP_DIRINDEX  iDir,
UINT32  nHash 
)

Definition at line 2420 of file svdhash.cpp.

References CHashPage::FindNextKey(), HF_FIND_END, HP_DIR_EMPTY, m_hpLast, m_nChecks, m_nHits, m_nMaxScan, and m_nScans.

Referenced by dbclean_RemoveStaleAttributeNames(), dbclean_RenumberAttributes(), hashdeleteLEN(), hashfindLEN(), hashreplLEN(), vattr_delete_LEN(), vattr_find_LEN(), and vattr_rename_LEN().

02421 {
02422     m_nScans++;
02423     unsigned int numchecks;
02424 
02425     iDir = m_hpLast->FindNextKey(iDir, nHash, &numchecks);
02426 
02427     m_nChecks += numchecks;
02428     if (numchecks > m_nMaxScan)
02429     {
02430         m_nMaxScan = numchecks;
02431     }
02432     if (iDir == HP_DIR_EMPTY)
02433     {
02434         return HF_FIND_END;
02435     }
02436     m_nHits++;
02437     return iDir;
02438 }

INT64 CHashTable::GetEntryCount (  ) 

Definition at line 2538 of file svdhash.cpp.

References m_nEntries.

Referenced by do_chanlist().

02539 {
02540     return m_nEntries;
02541 }

void CHashTable::GetStats ( unsigned int *  hashsize,
int *  entries,
INT64 deletes,
INT64 scans,
INT64 hits,
INT64 checks,
int *  max_scan 
)

Definition at line 2544 of file svdhash.cpp.

Referenced by list_hashstat().

02553 {
02554     *hashsize = m_nPages;
02555     *entries = m_nEntries;
02556     *deletes = m_nDeletions;
02557     *scans = m_nScans;
02558     *hits = m_nHits;
02559     *checks = m_nChecks;
02560     *max_scan = m_nMaxScan;
02561 }

void CHashTable::Init ( void   )  [private]

Definition at line 2209 of file svdhash.cpp.

References CHashPage::Empty(), HT_SIZEOF_PAGE, m_nChecks, m_nDeletions, m_nDir, m_nDirDepth, m_nEntries, m_nHits, m_nMaxScan, m_nPages, m_nScans, and m_pDir.

Referenced by CHashTable(), and Reset().

02210 {
02211     m_nDir = 2;
02212     m_nDirDepth = 1;
02213     m_pDir = new pCHashPage[m_nDir];
02214     if (m_pDir)
02215     {
02216         m_pDir[1] = m_pDir[0] = new CHashPage;
02217         if (m_pDir[0])
02218         {
02219             if (m_pDir[0]->Allocate(HT_SIZEOF_PAGE))
02220             {
02221                 m_pDir[0]->Empty(0, 0UL, 100);
02222             }
02223             else
02224             {
02225                 delete m_pDir[0];
02226                 m_pDir[0] = NULL;
02227             }
02228         }
02229     }
02230 
02231     m_nPages = 1;
02232     m_nEntries = 0;
02233     m_nDeletions = 0;
02234     m_nScans = 0;
02235     m_nHits = 0;
02236     m_nChecks = 0;
02237     m_nMaxScan = 0;
02238 }

bool CHashTable::Insert ( HP_HEAPLENGTH  nRecord,
UINT32  nHash,
void *  pRecord 
)

Definition at line 2247 of file svdhash.cpp.

References CHashPage::Allocate(), DoubleDirectory(), CHashPage::GetDepth(), CHashPage::GetRange(), HP_INSERT_ERROR_ILLEGAL, HP_INSERT_SUCCESS_DEFRAG, HT_SIZEOF_PAGE, CHashPage::Insert(), IS_HP_SUCCESS, Log, m_hpLast, m_nDir, m_nDirDepth, m_nEntries, m_nMaxScan, m_nPages, m_pDir, CHashPage::Split(), and CLogFile::WriteString().

Referenced by hashaddLEN(), vattr_define_LEN(), and vattr_rename_LEN().

02248 {
02249     for (;;)
02250     {
02251         UINT32  iTableDir = nHash >> (32 - m_nDirDepth);
02252 #ifdef HP_PROTECTION
02253         if (iTableDir >= m_nDir)
02254         {
02255             Log.WriteString("CHashTable::Insert - iTableDir out of range." ENDLINE);
02256             return false;
02257         }
02258 #endif // HP_PROTECTION
02259         m_hpLast = m_pDir[iTableDir];
02260         if (!m_hpLast)
02261         {
02262             Log.WriteString("CHashTable::Insert - Page wasn't valid." ENDLINE);
02263             return false;
02264         }
02265         UINT32  nStart, nEnd;
02266 #ifdef HP_PROTECTION
02267         m_hpLast->GetRange(m_nDirDepth, nStart, nEnd);
02268         if (iTableDir < nStart || nEnd < iTableDir)
02269         {
02270             Log.WriteString("CHashTable::Insert - Directory points to the wrong page." ENDLINE);
02271             return false;
02272         }
02273 #endif // HP_PROTECTION
02274         int errInserted = m_hpLast->Insert(nRecord, nHash, pRecord);
02275         if (IS_HP_SUCCESS(errInserted))
02276         {
02277             if (errInserted == HP_INSERT_SUCCESS_DEFRAG)
02278             {
02279                 // Otherwise, this value will be over inflated.
02280                 //
02281                 m_nMaxScan = 0;
02282             }
02283             break;
02284         }
02285         if (errInserted == HP_INSERT_ERROR_ILLEGAL)
02286         {
02287             return false;
02288         }
02289 
02290         // If the depth of this page is already as deep as the directory
02291         // depth,then we must increase depth of the directory, first.
02292         //
02293         if (m_nDirDepth == m_hpLast->GetDepth())
02294         {
02295             if (!DoubleDirectory())
02296             {
02297                 return false;
02298             }
02299         }
02300 
02301         // Split this page into two pages. We become a new one, and we
02302         // are given a pointer to the other one.
02303         //
02304         CHashPage *hpEmpty0 = new CHashPage;
02305         if (!hpEmpty0) return false;
02306         if (!hpEmpty0->Allocate(HT_SIZEOF_PAGE))
02307         {
02308             delete hpEmpty0;
02309             return false;
02310         }
02311 
02312         CHashPage *hpEmpty1 = new CHashPage;
02313         if (!hpEmpty1) return false;
02314         if (!hpEmpty1->Allocate(HT_SIZEOF_PAGE))
02315         {
02316             delete hpEmpty0;
02317             delete hpEmpty1;
02318             return false;
02319         }
02320 
02321         if (!m_hpLast->Split(*hpEmpty0, *hpEmpty1))
02322         {
02323             return false;
02324         }
02325 
02326         // Otherwise, this value will be over inflated.
02327         //
02328         m_nMaxScan = 0;
02329 
02330         // Now, update the directory.
02331         //
02332         hpEmpty0->GetRange(m_nDirDepth, nStart, nEnd);
02333         for ( ; nStart <= nEnd; nStart++)
02334         {
02335             m_pDir[nStart] = hpEmpty0;
02336         }
02337 
02338         hpEmpty1->GetRange(m_nDirDepth, nStart, nEnd);
02339         for ( ; nStart <= nEnd; nStart++)
02340         {
02341             m_pDir[nStart] = hpEmpty1;
02342         }
02343         m_nPages++;
02344 
02345         delete m_hpLast;
02346         m_hpLast = 0;
02347     }
02348     m_nEntries++;
02349     return true;
02350 }

void CHashTable::Remove ( HP_DIRINDEX  iDir  ) 

Definition at line 2445 of file svdhash.cpp.

References CHashPage::HeapFree(), m_hpLast, m_nDeletions, and m_nEntries.

Referenced by dbclean_RemoveStaleAttributeNames(), hashdeleteLEN(), vattr_delete_LEN(), and vattr_rename_LEN().

02446 {
02447     m_nEntries--;
02448     m_nDeletions++;
02449     m_hpLast->HeapFree(iDir);
02450 }

void CHashTable::Reset ( void   ) 

Definition at line 2482 of file svdhash.cpp.

References Final(), and Init().

Referenced by hashflush().

02483 {
02484     Final();
02485     Init();
02486 }

void CHashTable::ResetStats ( void   ) 

Definition at line 2240 of file svdhash.cpp.

References m_nChecks, m_nHits, and m_nScans.

Referenced by hashreset().

02241 {
02242     m_nScans = 0;
02243     m_nHits = 0;
02244     m_nChecks = 0;
02245 }

void CHashTable::Update ( HP_DIRINDEX  iDir,
HP_HEAPLENGTH  nRecord,
void *  pRecord 
)

Definition at line 2452 of file svdhash.cpp.

References CHashPage::HeapUpdate(), and m_hpLast.

Referenced by dbclean_RenumberAttributes(), hashreplall(), and hashreplLEN().

02453 {
02454     m_hpLast->HeapUpdate(iDir, nRecord, pRecord);
02455 }


Field Documentation

CHashPage* CHashTable::m_hpLast [private]

Definition at line 253 of file svdhash.h.

Referenced by Copy(), Final(), FindFirst(), FindFirstKey(), FindNext(), FindNextKey(), Insert(), Remove(), and Update().

unsigned int CHashTable::m_iPage [private]

Definition at line 254 of file svdhash.h.

Referenced by FindFirst(), and FindNext().

INT64 CHashTable::m_nChecks [private]

Definition at line 261 of file svdhash.h.

Referenced by FindFirstKey(), FindNextKey(), Init(), and ResetStats().

INT64 CHashTable::m_nDeletions [private]

Definition at line 258 of file svdhash.h.

Referenced by Init(), and Remove().

unsigned int CHashTable::m_nDir [private]

Definition at line 250 of file svdhash.h.

Referenced by DoubleDirectory(), Final(), FindFirst(), FindFirstKey(), FindNext(), Init(), and Insert().

unsigned int CHashTable::m_nDirDepth [private]

Definition at line 251 of file svdhash.h.

Referenced by DoubleDirectory(), FindFirstKey(), Init(), and Insert().

unsigned int CHashTable::m_nEntries [private]

Definition at line 257 of file svdhash.h.

Referenced by GetEntryCount(), Init(), Insert(), and Remove().

INT64 CHashTable::m_nHits [private]

Definition at line 260 of file svdhash.h.

Referenced by FindFirstKey(), FindNextKey(), Init(), and ResetStats().

unsigned int CHashTable::m_nMaxScan [private]

Definition at line 262 of file svdhash.h.

Referenced by FindFirstKey(), FindNextKey(), Init(), and Insert().

unsigned int CHashTable::m_nPages [private]

Definition at line 256 of file svdhash.h.

Referenced by Init(), and Insert().

INT64 CHashTable::m_nScans [private]

Definition at line 259 of file svdhash.h.

Referenced by FindFirstKey(), FindNextKey(), Init(), and ResetStats().

pCHashPage* CHashTable::m_pDir [private]

Definition at line 252 of file svdhash.h.

Referenced by DoubleDirectory(), Final(), FindFirst(), FindFirstKey(), FindNext(), Init(), and Insert().


The documentation for this class was generated from the following files:
Generated on Mon May 28 04:40:24 2007 for MUX by  doxygen 1.4.7