Leaked source code of windows server 2003
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.

214 lines
5.1 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 1994.
  5. //
  6. // File: KeyHash.hxx
  7. //
  8. // Contents: Persistent key hash table
  9. //
  10. // History: 17-Feb-94 KyleP Created
  11. //
  12. //--------------------------------------------------------------------------
  13. #pragma once
  14. #include <bitoff.hxx>
  15. #include <misc.hxx>
  16. #include "keylist.hxx"
  17. #include "physidx.hxx"
  18. #include "bitstm.hxx"
  19. #define BITS_IN_CI_PAGE_SIZE 12 // Number of bits in CI_PAGE_SIZE
  20. #define CI_PAGE_MASK 0x0FFF //
  21. //+-------------------------------------------------------------------------
  22. //
  23. // Class: CKeyHash
  24. //
  25. // Purpose: Base key hash class
  26. //
  27. // History: 17-Feb-94 KyleP Created
  28. //
  29. // Notes: The key hash is an array. It is referenced by key id and
  30. // contains the index of the directory (PDir) leaf node which
  31. // points to the page on which key kid is stored.
  32. //
  33. // Each entry is Log2(# directory leaf nodes) long.
  34. //
  35. //--------------------------------------------------------------------------
  36. class CKeyHash : INHERIT_UNWIND
  37. {
  38. DECLARE_UNWIND
  39. public:
  40. CKeyHash( unsigned cDirEntry );
  41. inline unsigned BitsPerEntry() const;
  42. protected:
  43. inline BitOffset KidToOff( KEYID kid );
  44. unsigned const _cBitsPerEntry;
  45. private:
  46. inline unsigned Size( unsigned cDirEntry );
  47. };
  48. //+-------------------------------------------------------------------------
  49. //
  50. // Class: CRKeyHash
  51. //
  52. // Purpose: Readable key hash
  53. //
  54. // History: 17-Feb-94 KyleP Created
  55. //
  56. //--------------------------------------------------------------------------
  57. class CRKeyHash : public CKeyHash
  58. {
  59. DECLARE_UNWIND
  60. public:
  61. CRKeyHash( CPhysHash & physHash, unsigned cDirEntry );
  62. //
  63. // Lookup
  64. //
  65. void Find( KEYID kid, BitOffset & off);
  66. private:
  67. CRBitStream _bitstm;
  68. };
  69. //+-------------------------------------------------------------------------
  70. //
  71. // Class: CWKeyHash
  72. //
  73. // Purpose: Writeable key hash
  74. //
  75. // History: 17-Feb-94 KyleP Created
  76. //
  77. //--------------------------------------------------------------------------
  78. class CWKeyHash : public CKeyHash
  79. {
  80. DECLARE_UNWIND
  81. public:
  82. CWKeyHash( CPhysHash & physHash, unsigned cDirEntry, KEYID kidMax );
  83. void Add( KEYID kid, BitOffset & bitOff );
  84. private:
  85. CPBitStream _bitstm;
  86. };
  87. //+-------------------------------------------------------------------------
  88. //
  89. // Method: CKeyHash::BitsPerEntry
  90. //
  91. // Returns: Bits required to store each key hash
  92. //
  93. // History: 17-Feb-1994 KyleP Created
  94. //
  95. //--------------------------------------------------------------------------
  96. inline unsigned CKeyHash::BitsPerEntry() const
  97. {
  98. return( _cBitsPerEntry );
  99. }
  100. //+-------------------------------------------------------------------------
  101. //
  102. // Method: CKeyHash::SetSize
  103. //
  104. // Synopsis: Sets maximum number of unique hash values
  105. //
  106. // Arguments: [cNumPages] -- # of pages in the keylist stream
  107. //
  108. // History: 17-Feb-1994 KyleP Created
  109. // 30-May-1994 DwightKr Added BITS_IN_CI_PAGE_SIZE so
  110. // that offsets in addition to page
  111. // #'s are stored.
  112. //
  113. //--------------------------------------------------------------------------
  114. inline unsigned CKeyHash::Size( unsigned cNumPages )
  115. {
  116. unsigned c = Log2( cNumPages );
  117. if ( c == 0 )
  118. c = 1;
  119. c += BITS_IN_CI_PAGE_SIZE;
  120. ciDebugOut(( DEB_KEYLIST, "KeyHash: %d dir entries --> %d bits/entry\n",
  121. cNumPages, c ));
  122. Win4Assert(c <= (sizeof(ULONG) * 8) );
  123. return( c );
  124. }
  125. //+-------------------------------------------------------------------------
  126. //
  127. // Method: CKeyHash::KidToOff
  128. //
  129. // Arguments: [kid] -- Key id
  130. //
  131. // Returns: Bit offset of position where hash for [kid] is stored
  132. //
  133. // History: 17-Feb-1994 KyleP Created
  134. //
  135. //--------------------------------------------------------------------------
  136. inline BitOffset CKeyHash::KidToOff( KEYID kid )
  137. {
  138. BitOffset off;
  139. //
  140. // WARNING: If kid > 2^27 (~ 134,000,000) this will overflow.
  141. //
  142. off.Init( (kid * _cBitsPerEntry) / (CI_PAGE_SIZE * 8),
  143. (kid * _cBitsPerEntry) % (CI_PAGE_SIZE * 8) );
  144. return( off );
  145. }
  146. //+---------------------------------------------------------------------------
  147. //
  148. // Class: PKeyHash
  149. //
  150. // Purpose: Smart Pointer to key list
  151. //
  152. // History: 28-Oct-93 w-PatG Stolen from BartoszM
  153. //
  154. //----------------------------------------------------------------------------
  155. class PRKeyHash : INHERIT_UNWIND
  156. {
  157. DECLARE_UNWIND
  158. public:
  159. PRKeyHash ( CRKeyHash * pKeyHash )
  160. {
  161. _pKeyHash = pKeyHash;
  162. END_CONSTRUCTION( PRKeyHash );
  163. }
  164. ~PRKeyHash () { delete _pKeyHash; }
  165. CRKeyHash * operator-> () { return _pKeyHash; }
  166. private:
  167. CRKeyHash * _pKeyHash;
  168. };