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.

139 lines
3.4 KiB

  1. /*++
  2. Copyright (c) 1996 Microsoft Corporation
  3. Module Name :
  4. rhash.h
  5. Abstract:
  6. This file contains type definitions hash table support
  7. Author:
  8. Revision History:
  9. Nimish Khanolkar (NimishK) May-98
  10. --*/
  11. #ifndef _RHASH_H_
  12. #define _RHASH_H_
  13. #include <windows.h>
  14. #include <limits.h>
  15. #define RETRY_TABLE_SIGNATURE_VALID 'RtsV'
  16. #define RETRY_TABLE_SIGNATURE_FREE 'RtsF'
  17. class RETRYQ;
  18. typedef struct HASH_BUCKET_ENTRY
  19. {
  20. DWORD m_NumEntries;
  21. LONG m_RefNum;
  22. LIST_ENTRY m_ListHead;
  23. CShareLockNH m_Lock;
  24. HASH_BUCKET_ENTRY (void)
  25. {
  26. InitializeListHead(&m_ListHead);
  27. m_NumEntries = 0;
  28. m_RefNum = 0;
  29. }
  30. }BUCKET_ENTRY, *PBUCKET_ENTRY;
  31. #define BITS_IN_int (sizeof(int) * CHAR_BIT)
  32. #define THREE_QUARTERS ((int) ((BITS_IN_int * 3) / 4))
  33. #define ONE_EIGHTH ((int) (BITS_IN_int / 8))
  34. #define HIGH_BITS (~((unsigned int)(~0) >> ONE_EIGHTH))
  35. #define TABLE_SIZE 241
  36. /////////////////////////////////////////////////////////////////////////////////
  37. // CRETRY_HASH_TABLE:
  38. //
  39. // A hash table to store all the domains that are in the Retry queue.
  40. // The hash key is the name of the domain
  41. //
  42. /////////////////////////////////////////////////////////////////////////////////
  43. class CRETRY_HASH_TABLE
  44. {
  45. protected:
  46. DWORD m_Signature;
  47. LONG m_TotalEntries;
  48. HASH_BUCKET_ENTRY m_HashTable[TABLE_SIZE];
  49. RETRYQ* m_pRetryQueue;
  50. public:
  51. CRETRY_HASH_TABLE();
  52. ~CRETRY_HASH_TABLE();
  53. HRESULT DeInitialize(void);
  54. void RemoveAllEntries(void);
  55. void RemoveThisEntry(CRETRY_HASH_ENTRY * pHashEntry, DWORD BucketNum);
  56. BOOL RemoveFromTable(const char * SearchData, CRETRY_HASH_ENTRY* *ppExistingEntry);
  57. BOOL InsertIntoTable (CRETRY_HASH_ENTRY * pHashEntry);
  58. BOOL IsTableEmpty(void) const {return (m_TotalEntries == 0);}
  59. BOOL IsHashTableValid(void){ return (m_Signature == RETRY_TABLE_SIGNATURE_VALID);}
  60. RETRYQ* GetQueuePtr(){return m_pRetryQueue;}
  61. //An adaptation of Peter Weinberger's (PJW) generic
  62. //hashing algorithm based on Allen Holub's version.
  63. //Code from Practical Algorithms for Programmers
  64. //by Andrew Binstock
  65. unsigned int HashFunction (const char * String)
  66. {
  67. unsigned int HashValue = 0;
  68. unsigned int i = 0;
  69. _ASSERT(String != NULL);
  70. for (HashValue = 0; String && *String; ++String)
  71. {
  72. HashValue = (HashValue << ONE_EIGHTH) + * String;
  73. if((i = HashValue & HIGH_BITS) != 0)
  74. {
  75. HashValue = (HashValue ^ (i >> THREE_QUARTERS)) & ~ HIGH_BITS;
  76. }
  77. }
  78. HashValue %= TABLE_SIZE;
  79. return HashValue;
  80. }
  81. private:
  82. //Unused functions
  83. #if 0
  84. DWORD PrimaryCompareFunction(const char * SearchData, CRETRY_HASH_ENTRY * pExistingEntry)
  85. {
  86. DWORD Result = 0;
  87. Result = lstrcmpi(SearchData, pExistingEntry->GetHashKey());
  88. return Result;
  89. }
  90. CRETRY_HASH_ENTRY * FindHashData(const char * SearchData);
  91. LIST_ENTRY & GetBucketHead(DWORD BucketNum)
  92. {
  93. return m_HashTable[BucketNum].m_ListHead;
  94. }
  95. #endif
  96. public:
  97. //debug function
  98. void PrintAllEntries(void);
  99. };
  100. #endif