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.

198 lines
4.3 KiB

  1. /*++
  2. Copyright (c) 1998-2001 Microsoft Corporation
  3. Module Name:
  4. hashp.h
  5. Abstract:
  6. The private definition of response cache hash table.
  7. Author:
  8. Alex Chen (alexch) 28-Mar-2001
  9. Revision History:
  10. --*/
  11. #ifndef _HASHP_H_
  12. #define _HASHP_H_
  13. #include "hash.h"
  14. #ifdef __cplusplus
  15. extern "C" {
  16. #endif
  17. // Global Variables
  18. extern ULONG g_UlHashTableBits;
  19. extern ULONG g_UlHashTableSize;
  20. extern ULONG g_UlHashTableMask;
  21. extern ULONG g_UlHashIndexShift;
  22. extern ULONG g_UlNumOfHashUriKeys;
  23. // If we're using PagedPool for the hashtable, we must not access the
  24. // hashtable at dispatch level. The ((void) 0) is because PAGED_CODE()
  25. // expands to nothing in a free build and otherwise you get a compiler
  26. // warning.
  27. #define HASH_PAGED_CODE(pHashTable) \
  28. do { \
  29. if ((pHashTable)->PoolType == PagedPool) { \
  30. PAGED_CODE(); \
  31. ((void) 0); /* for free build */ \
  32. } \
  33. } while (0)
  34. #undef HASH_TEST
  35. //
  36. // Hash Table Bucket Stored UriKey definitions
  37. //
  38. #define INVALID_SLOT_INDEX ((LONG) (-1))
  39. typedef struct _HASH_URIKEY
  40. {
  41. PUL_URI_CACHE_ENTRY pUriCacheEntry;
  42. ULONG Hash; // Hash signature
  43. } HASHURIKEY, *PHASHURIKEY;
  44. //
  45. // Hash Table Bucket definitions
  46. //
  47. typedef struct _HASH_BUCKET
  48. {
  49. RWSPINLOCK RWSpinLock;
  50. PUL_URI_CACHE_ENTRY pUriCacheEntry;
  51. ULONG_PTR Entries; // force alignment
  52. // followed immediately by HASHURIKEY HashUriKey[g_UlNumOfHashUriKeys];
  53. } HASHBUCKET, *PHASHBUCKET;
  54. /***************************************************************************++
  55. Routine Description:
  56. Get the indexed bucket
  57. Return Value:
  58. --***************************************************************************/
  59. __inline
  60. PHASHBUCKET
  61. UlpHashTableIndexedBucket(
  62. IN PHASHTABLE pHashTable,
  63. IN ULONG Index
  64. )
  65. {
  66. ASSERT(Index < g_UlHashTableSize);
  67. ASSERT(NULL != pHashTable->pBuckets);
  68. PHASHBUCKET pBucket = (PHASHBUCKET) (((PBYTE) pHashTable->pBuckets)
  69. + (Index << g_UlHashIndexShift));
  70. ASSERT((PBYTE) pBucket
  71. < (PBYTE) pHashTable->pBuckets + pHashTable->NumberOfBytes);
  72. return pBucket;
  73. } // UlpHashTableIndexedBucket
  74. /***************************************************************************++
  75. Routine Description:
  76. Retrieve the bucket associated with a URI_KEY
  77. Return Value:
  78. --***************************************************************************/
  79. __inline
  80. PHASHBUCKET
  81. UlpHashTableBucketFromUriKey(
  82. IN PHASHTABLE pHashTable,
  83. IN PURI_KEY pUriKey
  84. )
  85. {
  86. ASSERT(NULL != pUriKey);
  87. ASSERT(HASH_INVALID_SIGNATURE != pUriKey->Hash);
  88. return UlpHashTableIndexedBucket(
  89. pHashTable,
  90. pUriKey->Hash & g_UlHashTableMask
  91. );
  92. } // UlpHashTableBucketFromUriKey
  93. /***************************************************************************++
  94. Routine Description:
  95. Get the address of the inline array of HASHURIKEYs at the end of
  96. the HASHBUCKET
  97. Return Value:
  98. --***************************************************************************/
  99. __inline
  100. PHASHURIKEY
  101. UlpHashTableUriKeyFromBucket(
  102. IN PHASHBUCKET pBucket
  103. )
  104. {
  105. return (PHASHURIKEY) ((PBYTE) pBucket + sizeof(HASHBUCKET));
  106. }
  107. /***************************************************************************++
  108. Routine Description:
  109. Compare two URI_KEYS that have identical hashes to see if the
  110. URIs also match (case-insensitively).
  111. (Hashes must have been computed with HashStringNoCaseW or
  112. HashCharNoCaseW.)
  113. Return Value:
  114. --***************************************************************************/
  115. __inline
  116. BOOLEAN
  117. UlpEqualUriKeys(
  118. IN PURI_KEY pUriKey1,
  119. IN PURI_KEY pUriKey2
  120. )
  121. {
  122. ASSERT(pUriKey1->Hash == pUriKey2->Hash);
  123. return (pUriKey1->Length == pUriKey2->Length
  124. && UlEqualUnicodeString(
  125. pUriKey1->pUri,
  126. pUriKey2->pUri,
  127. pUriKey1->Length,
  128. TRUE
  129. )
  130. );
  131. }
  132. #ifdef __cplusplus
  133. }; // extern "C"
  134. #endif
  135. #endif // _HASHP_H_