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.

145 lines
4.1 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 1994
  5. //
  6. // File: KeyHash.cxx
  7. //
  8. // Contents: Key hash
  9. //
  10. // History: 17-Feb-1994 KyleP Created
  11. // 29-May-1994 DwightKr Changed hash table to store bit
  12. // offset of first key on page, rather
  13. // than just the page number.
  14. //
  15. //--------------------------------------------------------------------------
  16. #include <pch.cxx>
  17. #pragma hdrstop
  18. #include "keyhash.hxx"
  19. //+-------------------------------------------------------------------------
  20. //
  21. // Method: CKeyHash::CKeyHash
  22. //
  23. // Synopsis: Construct keyhash
  24. //
  25. // Arguments: [cDirEntry] -- Number of leaf directory nodes
  26. //
  27. // History: 17-Feb-1994 KyleP Created
  28. //
  29. //--------------------------------------------------------------------------
  30. CKeyHash::CKeyHash( unsigned cDirEntry )
  31. : _cBitsPerEntry( Size(cDirEntry) )
  32. {
  33. }
  34. //+-------------------------------------------------------------------------
  35. //
  36. // Method: CRKeyHash::CRKeyHash
  37. //
  38. // Synopsis: Construct keyhash
  39. //
  40. // Arguments: [physHash] -- On disk stream
  41. // [cDirEntry] -- Number of leaf directory nodes
  42. //
  43. // History: 17-Feb-1994 KyleP Created
  44. //
  45. //--------------------------------------------------------------------------
  46. CRKeyHash::CRKeyHash( CPhysHash & physHash, unsigned cDirEntry )
  47. : CKeyHash(cDirEntry),
  48. _bitstm( physHash )
  49. {
  50. }
  51. //+-------------------------------------------------------------------------
  52. //
  53. // Method: CRKeyHash::Find
  54. //
  55. // Synopsis: Lookup value for key in hash
  56. //
  57. // Arguments: [kid] -- Key id
  58. //
  59. // Returns: Bitoffset for [kid]
  60. //
  61. // History: 17-Feb-1994 KyleP Created
  62. //
  63. //--------------------------------------------------------------------------
  64. void CRKeyHash::Find( KEYID kid, BitOffset & resultOffset )
  65. {
  66. BitOffset off = KidToOff(kid);
  67. _bitstm.Seek( off );
  68. ULONG ulResult = _bitstm.GetBits( BitsPerEntry() );
  69. resultOffset.Init( ulResult >> BITS_IN_CI_PAGE_SIZE,
  70. ulResult & CI_PAGE_MASK);
  71. ciDebugOut(( DEB_KEYLIST, "KeyHash: kid %u --> page,off 0x%x,0x%x\n",
  72. kid, resultOffset.Page(), resultOffset.Offset() ));
  73. }
  74. //+-------------------------------------------------------------------------
  75. //
  76. // Method: CWKeyHash::CWKeyHash
  77. //
  78. // Synopsis: Construct keyhash
  79. //
  80. // Arguments: [physHash] -- On disk stream
  81. // [cDirEntry] -- Number of leaf directory nodes
  82. // [kidMax] -- Number of keys to be stored
  83. //
  84. // History: 17-Feb-1994 KyleP Created
  85. //
  86. //--------------------------------------------------------------------------
  87. CWKeyHash::CWKeyHash( CPhysHash & physHash, unsigned cDirEntry, KEYID kidMax )
  88. : CKeyHash(cDirEntry),
  89. _bitstm( physHash )
  90. {
  91. //
  92. // Zero all pages by touching them.
  93. //
  94. BitOffset off = KidToOff(kidMax+1);
  95. ciDebugOut(( DEB_KEYLIST, "KeyHash: Zeroing %d pages\n", off.Page() ));
  96. for ( ULONG i = 0; i <= off.Page(); i++ )
  97. {
  98. physHash.BorrowNewBuffer( i );
  99. physHash.ReturnBuffer( i );
  100. }
  101. }
  102. //+-------------------------------------------------------------------------
  103. //
  104. // Method: CWKeyHash::Add
  105. //
  106. // Synopsis: Add mapping for new key
  107. //
  108. // Arguments: [kid] -- Key id
  109. // [bitOff] -- Directory entry corresponding to [kid]
  110. //
  111. // History: 17-Feb-1994 KyleP Created
  112. //
  113. //--------------------------------------------------------------------------
  114. void CWKeyHash::Add( KEYID kid, BitOffset & bitOff )
  115. {
  116. BitOffset off = KidToOff(kid);
  117. _bitstm.Seek( off );
  118. Win4Assert(bitOff.Page() < 0x100000); // Fits into a 20-bit number
  119. ULONG ulDirEntry = (bitOff.Page() << BITS_IN_CI_PAGE_SIZE ) | bitOff.Offset();
  120. _bitstm.OverwriteBits( ulDirEntry, BitsPerEntry() );
  121. ciDebugOut(( DEB_KEYLIST, "KeyHash: WRITE kid %u = page,offset 0x%x,0x%x\n",
  122. kid, bitOff.Page(), bitOff.Offset() ));
  123. }