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.

152 lines
3.6 KiB

  1. /********************************************************************
  2. Copyright (c) 1999-2000 Microsoft Corporation
  3. Module Name:
  4. hashtbl.h
  5. Abstract:
  6. contains the CPFHash def. Note that this hash table is in NO
  7. WAY thread safe.
  8. Revision History:
  9. DerekM created 05/01/99
  10. DerekM modified 03/06/00
  11. ********************************************************************/
  12. #ifndef PFHASH_H
  13. #define PFHASH_H
  14. /*
  15. #if defined(DEBUG) || defined(_DEBUG)
  16. #include <stdio.h>
  17. #endif
  18. */
  19. #include "util.h"
  20. /////////////////////////////////////////////////////////////////////////////
  21. // SPFHashEntry definition
  22. struct SPFHashObj
  23. {
  24. LPVOID pvTag;
  25. LPVOID pvData;
  26. SPFHashObj *pNext;
  27. };
  28. typedef void (*pfnDeleteHash)(LPVOID pv);
  29. /////////////////////////////////////////////////////////////////////////////
  30. // CPFHashBase definition
  31. class CPFHashBase : public CPFGenericClassBase
  32. {
  33. protected:
  34. // member data
  35. pfnDeleteHash m_pfnDelete;
  36. SPFHashObj **m_rgpMap;
  37. DWORD m_cObjs;
  38. DWORD m_cSlots;
  39. SPFHashObj *m_pEnumNext;
  40. DWORD m_iEnumSlot;
  41. // internal type specific methods
  42. virtual HRESULT AllocTag(LPVOID pvTag, LPVOID *ppvTagCopy) = 0;
  43. virtual DWORD ComputeSlot(LPVOID pvTag) = 0;
  44. virtual void DeleteTag(LPVOID pvTag) = 0;
  45. virtual INT_PTR CompareTag(LPVOID pvTag1, LPVOID pvTag2) = 0;
  46. // internal methods
  47. SPFHashObj *FindInChain(LPVOID pvTag, DWORD iSlot,
  48. SPFHashObj ***pppObjStore = NULL);
  49. void Cleanup(void);
  50. public:
  51. // construction
  52. CPFHashBase(void);
  53. virtual ~CPFHashBase(void);
  54. void SetDeleteMethod(pfnDeleteHash pfnDelete) { m_pfnDelete = pfnDelete; }
  55. // exposed methods
  56. HRESULT Init(DWORD cSlots = 31);
  57. HRESULT AddToMap(LPVOID pvTag, LPVOID pv, LPVOID *ppvOld = NULL);
  58. HRESULT RemoveFromMap(LPVOID pvTag, LPVOID *ppvOld = NULL);
  59. HRESULT FindInMap(LPVOID pvTag, LPVOID *ppv);
  60. HRESULT RemoveAll(void);
  61. HRESULT BeginEnum(void);
  62. HRESULT EnumNext(LPVOID *ppvTag, LPVOID *ppvData);
  63. /*
  64. #if defined(DEBUG) || defined(_DEBUG)
  65. virtual void PrintTag(FILE *pf, LPVOID pvTag) { fprintf(pf, "0x%08x, ", pvTag); }
  66. void DumpAll(FILE *pf);
  67. void DumpCount(FILE *pf);
  68. #endif
  69. */
  70. };
  71. /////////////////////////////////////////////////////////////////////////////
  72. // CPFHashWSTR definition
  73. class CPFHashWSTR : public CPFHashBase
  74. {
  75. private:
  76. virtual HRESULT AllocTag(LPVOID pvTag, LPVOID *ppvTagCopy);
  77. virtual DWORD ComputeSlot(LPVOID pvTag);
  78. virtual void DeleteTag(LPVOID pvTag);
  79. virtual INT_PTR CompareTag(LPVOID pvTag1, LPVOID pvTag2);
  80. public:
  81. CPFHashWSTR(void) {}
  82. /*
  83. #if defined(DEBUG) || defined(_DEBUG)
  84. virtual void PrintTag(FILE *pf, LPVOID pvTag) { fprintf(pf, "%ls, ", (WCHAR *)pvTag); }
  85. #endif
  86. */
  87. };
  88. /////////////////////////////////////////////////////////////////////////////
  89. // CPFHashDWORD definition
  90. class CPFHashDWORD : public CPFHashBase
  91. {
  92. private:
  93. virtual HRESULT AllocTag(LPVOID pvTag, LPVOID *ppvTagCopy)
  94. {
  95. *ppvTagCopy = pvTag;
  96. return NOERROR;
  97. }
  98. virtual DWORD ComputeSlot(LPVOID pvTag)
  99. {
  100. return (DWORD)(((DWORD_PTR)pvTag) % (DWORD_PTR)m_cSlots);
  101. }
  102. virtual void DeleteTag(LPVOID pvTag)
  103. {
  104. };
  105. virtual INT_PTR CompareTag(LPVOID pvTag1, LPVOID pvTag2)
  106. {
  107. return (INT_PTR)pvTag1 - (INT_PTR)pvTag2;
  108. }
  109. public:
  110. CPFHashDWORD(void) {}
  111. /*
  112. #if defined(DEBUG) || defined(_DEBUG)
  113. virtual void PrintTag(FILE *pf, LPVOID pvTag) { fprintf(pf, "%d, ", (DWORD)pvTag); }
  114. #endif
  115. */
  116. };
  117. #endif