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.

109 lines
3.2 KiB

  1. /*==========================================================================
  2. *
  3. * Copyright (C) 2001-2002 Microsoft Corporation. All Rights Reserved.
  4. *
  5. * File: HashTable.h
  6. * Content: Hash Table Header File
  7. *
  8. * History:
  9. * Date By Reason
  10. * ==== == ======
  11. * 08/13/2001 masonb Created
  12. *
  13. ***************************************************************************/
  14. #ifndef __HASHTABLE_H__
  15. #define __HASHTABLE_H__
  16. //**********************************************************************
  17. // Constant definitions
  18. //**********************************************************************
  19. //**********************************************************************
  20. // Macro definitions
  21. //**********************************************************************
  22. //**********************************************************************
  23. // Structure definitions
  24. //**********************************************************************
  25. //**********************************************************************
  26. // Variable definitions
  27. //**********************************************************************
  28. //**********************************************************************
  29. // Function prototypes
  30. //**********************************************************************
  31. typedef BOOL (*PFNHASHTABLECOMPARE)(void* pvKey1, void* pvKey2);
  32. typedef DWORD (*PFNHASHTABLEHASH)(void* pvKey, BYTE bBitDepth);
  33. //**********************************************************************
  34. // Class prototypes
  35. //**********************************************************************
  36. class CHashTable
  37. {
  38. public:
  39. CHashTable();
  40. ~CHashTable();
  41. BOOL Initialize( BYTE bBitDepth,
  42. #ifndef DPNBUILD_PREALLOCATEDMEMORYMODEL
  43. BYTE bGrowBits,
  44. #endif // ! DPNBUILD_PREALLOCATEDMEMORYMODEL
  45. PFNHASHTABLECOMPARE pfnCompare,
  46. PFNHASHTABLEHASH pfnHash );
  47. void Deinitialize( void );
  48. BOOL Insert( PVOID pvKey, PVOID pvData );
  49. BOOL Remove( PVOID pvKey );
  50. #ifndef DPNBUILD_NOREGISTRY
  51. void RemoveAll( void );
  52. #endif // ! DPNBUILD_NOREGISTRY
  53. BOOL Find( PVOID pvKey, PVOID* ppvData );
  54. DWORD GetEntryCount() const
  55. {
  56. return m_dwEntriesInUse;
  57. }
  58. private:
  59. struct _HASHTABLE_ENTRY
  60. {
  61. PVOID pvKey;
  62. PVOID pvData; // This will contain the data associated with a handle
  63. CBilink blLinkage;
  64. };
  65. static BOOL HashEntry_Alloc(void* pItem, void* pvContext);
  66. #ifdef DBG
  67. static void HashEntry_Init(void* pItem, void* pvContext);
  68. static void HashEntry_Release(void* pItem);
  69. static void HashEntry_Dealloc(void* pItem);
  70. #endif // DBG
  71. #ifndef DPNBUILD_PREALLOCATEDMEMORYMODEL
  72. void GrowTable( void );
  73. #endif // ! DPNBUILD_PREALLOCATEDMEMORYMODEL
  74. BOOL LocalFind( PVOID pvKey, CBilink** ppLinkage );
  75. DWORD m_dwAllocatedEntries;
  76. DWORD m_dwEntriesInUse;
  77. #ifndef DPNBUILD_PREALLOCATEDMEMORYMODEL
  78. BYTE m_bGrowBits;
  79. #endif // ! DPNBUILD_PREALLOCATEDMEMORYMODEL
  80. BYTE m_bBitDepth;
  81. PFNHASHTABLECOMPARE m_pfnCompareFunction;
  82. PFNHASHTABLEHASH m_pfnHashFunction;
  83. CBilink* m_pblEntries;
  84. CFixedPool m_EntryPool;
  85. DEBUG_ONLY(BOOL m_fInitialized);
  86. };
  87. #endif // __HASHTABLE_H__