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.

89 lines
2.5 KiB

  1. /**********************************************************************/
  2. /** Microsoft Windows NT **/
  3. /** Copyright(c) Microsoft Corp., 1994 **/
  4. /**********************************************************************/
  5. /*
  6. blobhash.hxx
  7. This module defines the classes used for storing blob
  8. objects in a hash table.
  9. FILE HISTORY:
  10. MCourage 09-Dec-1997 Created
  11. */
  12. #include <lkrhash.h>
  13. #include <mbstring.h>
  14. class CBlobKey {
  15. public:
  16. CHAR * m_pszPathName; // The path name in upper-case
  17. DWORD m_cbPathName; // The number of bytes in the path name
  18. DWORD m_dwService; // Service ID
  19. DWORD m_dwInstance; // Instance ID
  20. DWORD m_dwDemux; // Type of object
  21. };
  22. class CBlobHashTable
  23. : public CTypedHashTable<CBlobHashTable, BLOB_HEADER, const CBlobKey*>
  24. {
  25. public:
  26. CBlobHashTable(
  27. LPCSTR pszName)
  28. : CTypedHashTable<CBlobHashTable, BLOB_HEADER, const CBlobKey*>(pszName)
  29. {}
  30. static const CBlobKey *
  31. ExtractKey(const BLOB_HEADER *pBlob)
  32. {
  33. return pBlob->pBlobKey;
  34. }
  35. static DWORD
  36. CalcKeyHash(const CBlobKey * blobKey)
  37. {
  38. DWORD dw = Hash(blobKey->m_dwService)
  39. + 37 * Hash(blobKey->m_dwInstance)
  40. + 61 * Hash(blobKey->m_dwDemux);
  41. // use the last 16 chars of the pathname
  42. // this gives a good distribution
  43. const CHAR * psz = blobKey->m_pszPathName;
  44. if (blobKey->m_cbPathName > 80)
  45. psz += blobKey->m_cbPathName - 80;
  46. return HashString(psz, dw * blobKey->m_cbPathName);
  47. }
  48. static bool
  49. EqualKeys(const CBlobKey * blobKey1, const CBlobKey * blobKey2)
  50. {
  51. if ((blobKey1->m_dwService == blobKey2->m_dwService) &&
  52. (blobKey1->m_dwInstance == blobKey2->m_dwInstance) &&
  53. (blobKey1->m_dwDemux == blobKey2->m_dwDemux) &&
  54. (blobKey1->m_cbPathName == blobKey2->m_cbPathName) &&
  55. (memcmp(blobKey1->m_pszPathName,
  56. blobKey2->m_pszPathName,
  57. blobKey2->m_cbPathName) == 0)) {
  58. return TRUE;
  59. } else {
  60. return FALSE;
  61. }
  62. }
  63. static void
  64. AddRefRecord(BLOB_HEADER * pBlob, int nIncr)
  65. {
  66. DBG_ASSERT( nIncr == +1 || nIncr == -1 );
  67. if (nIncr == +1) {
  68. pBlob->AddRef();
  69. } else {
  70. pBlob->Deref();
  71. }
  72. }
  73. };