Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

124 lines
3.1 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1996-2000
  5. //
  6. // File: CHash.hxx
  7. //
  8. // Contents: Hash table
  9. //
  10. // Classes: CWidHashTable
  11. //
  12. // History: 10-Jan-96 KyleP Added header
  13. //
  14. //----------------------------------------------------------------------------
  15. #pragma once
  16. const unsigned INIT_HASH_SIZE = 17;
  17. #if CIDBG==1
  18. #define DO_STATS
  19. #endif // CIDBG==1
  20. //+-------------------------------------------------------------------------
  21. //
  22. // Class: CWidHashTable
  23. //
  24. // Purpose: Hash table. External management of table.
  25. //
  26. // History: 10-Jan-96 KyleP Added header
  27. //
  28. //--------------------------------------------------------------------------
  29. class CWidHashTable
  30. {
  31. public:
  32. CWidHashTable( BOOL fAggressiveGrowth );
  33. void Init(ULONG count, ULONG size, WORKID* table );
  34. void ReInit(ULONG count, ULONG size, WORKID* table );
  35. void Add ( unsigned hash, WORKID wid );
  36. void Remove( unsigned hash, WORKID wid, BOOL fDisableDeletionCheck );
  37. unsigned GrowSize()
  38. {
  39. if ( _fAggressiveGrowth )
  40. return _size ? ((_size - 1) * 2 ) + 1 : INIT_HASH_SIZE;
  41. return _count ? ( _count * 2 ) : INIT_HASH_SIZE;
  42. }
  43. unsigned GrowSize( unsigned count );
  44. unsigned Size() { return _size; }
  45. BOOL IsFull();
  46. BOOL IsAggressiveGrowth() const { return _fAggressiveGrowth; }
  47. WORKID operator[](unsigned i) { return _table[i]; }
  48. unsigned Count() { return _count; }
  49. unsigned Delta() { return _size / 5; }
  50. #ifdef DO_STATS
  51. void UpdateStats( unsigned cSearchLen );
  52. void GetStats( unsigned & cMaxChainLen, unsigned & cTotalSearches,
  53. LONGLONG & cTotalLen ) const
  54. {
  55. cMaxChainLen = _cMaxChainLen;
  56. cTotalSearches = _cTotalSearches;
  57. cTotalLen = _cTotalLength;
  58. }
  59. #endif // DO_STATS
  60. private:
  61. unsigned _count;
  62. unsigned _size;
  63. WORKID * _table;
  64. BOOL _fAggressiveGrowth;
  65. #ifdef DO_STATS
  66. public:
  67. //
  68. // For keeping track of usage statistics.
  69. //
  70. unsigned _cMaxChainLen;
  71. unsigned _cTotalSearches;
  72. LONGLONG _cTotalLength;
  73. #endif // DO_STATS
  74. };
  75. #ifdef DO_STATS
  76. inline void CWidHashTable::UpdateStats( unsigned cSearchLen )
  77. {
  78. _cTotalSearches++;
  79. _cTotalLength += cSearchLen;
  80. if ( cSearchLen > _cMaxChainLen )
  81. _cMaxChainLen = cSearchLen;
  82. }
  83. #endif // DO_STATS
  84. //+-------------------------------------------------------------------------
  85. //
  86. // Class: CShortWidList
  87. //
  88. // Purpose: Iterates over 'linked' records in closed hash table.
  89. //
  90. // History: 10-Jan-96 KyleP Added header
  91. //
  92. //--------------------------------------------------------------------------
  93. class CShortWidList
  94. {
  95. public:
  96. CShortWidList( unsigned hash, CWidHashTable& _hashTable );
  97. WORKID WorkId() { return _wid; }
  98. WORKID NextWorkId();
  99. private:
  100. CWidHashTable & _hashTable;
  101. unsigned _iCur;
  102. unsigned _iStart;
  103. unsigned _delta;
  104. unsigned _counter;
  105. unsigned _size;
  106. WORKID _wid;
  107. };