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.

165 lines
4.9 KiB

  1. /////////////////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Microsoft WMIOLE DB Provider
  4. //
  5. // (C) Copyright 1999 Microsoft Corporation. All Rights Reserved.
  6. //
  7. // Class Definitions for CHashTbl Class and miscellaneous bookmark functions
  8. //
  9. /////////////////////////////////////////////////////////////////////////////////////////
  10. #ifndef _HASHTBL_H_
  11. #define _HASHTBL_H_
  12. #include "bitarray.h"
  13. #include "dataconvert.h"
  14. #define SIZE_64K 65535 // Actually 64*1024-1
  15. #define HASHTBLSIZE 500
  16. #define BOOKMARKSIZE sizeof(ULONG_PTR)
  17. /////////////////////////////////////////////////////////////////////////////////////////
  18. // This defines the data as stored within the row buffer. Each row has columns laid out
  19. // sequentially. Use 'offsetof' when doing pointer addition. Note that it is important
  20. // to align these. Suggest ensuring quadword alignment for double and __int64.
  21. /////////////////////////////////////////////////////////////////////////////////////////
  22. typedef struct _COLUMNDATA{
  23. _COLUMNDATA();
  24. ~_COLUMNDATA();
  25. HRESULT SetData(CVARIANT & vVar, DWORD dwColType);
  26. void ReleaseColumnData();
  27. DBLENGTH dwLength; // length of data
  28. DBSTATUS dwStatus; // status of column
  29. DBTYPE dwType;
  30. BYTE * pbData; // data here and beyond
  31. } COLUMNDATA, *PCOLUMNDATA;
  32. /////////////////////////////////////////////////////////////////////////////////////////
  33. // This is the layout of a row.
  34. //
  35. // Note the unique arrangement of the hash chain pointers inside the row itself.
  36. //
  37. // Note also that the structure for columns is defined, and each row contains an array
  38. // of columns.
  39. // Bookmarks are named separately from ColumnData, for clarity of usage. The layout
  40. // directly matches COLUMNDATA, however. There are asserts which enforce this.
  41. /////////////////////////////////////////////////////////////////////////////////////////
  42. typedef struct tagRowBuff
  43. {
  44. ULONG ulRefCount; // reference count of outstanding handles
  45. HSLOT ulSlot;
  46. tagRowBuff *prowbuffNext; // next row in bookmark hash chain
  47. USHORT wBmkHash; // hash value (redundant)
  48. VOID *pbBmk; // ptr to bookmark
  49. ULONG cbBmk; // (dwLength) bookmark size, in bytes
  50. ULONG dwBmkStatus; // (dwStatus) bookmark status
  51. DBBKMARK dwBmk; // (bData) bookmark value, , maybe row count
  52. // COLUMNDATA cdData[1]; // Column data here and beyond (Bookmark should be here)
  53. COLUMNDATA *pdData; // Column data here and beyond (Bookmark should be here)
  54. PCOLUMNDATA GetColumnData(int iCol); // Get PCOLUMNDATA pointer for a particlular column
  55. HRESULT SetRowData(PCOLUMNDATA pColData); // get the pointer to the COLUMNDATA member of the structure
  56. } ROWBUFF, *PROWBUFF;
  57. typedef struct tagSLOT
  58. {
  59. HSLOT islotNext;
  60. HSLOT islotPrev;
  61. HSLOT cslot;
  62. } SLOT, *PSLOT;
  63. typedef struct tagLSTSLOT
  64. {
  65. HSLOT islotFirst;
  66. HSLOT islotRov;
  67. HSLOT islotMin;
  68. HSLOT islotMax;
  69. BYTE *rgslot;
  70. LPBITARRAY pbitsSlot; // bit array to mark active rows
  71. ULONG_PTR cbExtra;
  72. ULONG_PTR cbslotLeftOver;
  73. ULONG_PTR cbSlot;
  74. ULONG_PTR cbPage;
  75. ULONG_PTR cbCommitCurrent;
  76. ULONG_PTR cbCommitMax;
  77. } LSTSLOT, *PLSTSLOT;
  78. HRESULT GetNextSlots(PLSTSLOT plstslot, HSLOT cslot, HSLOT* pislot);
  79. VOID DecoupleSlot(PLSTSLOT plstslot, HSLOT islot, PSLOT pslot);
  80. VOID AddSlotToList(PLSTSLOT plstslot, HSLOT islot, PSLOT pslot);
  81. HRESULT ReleaseSlots(PLSTSLOT plstslot, HSLOT islot, ULONG_PTR cslot);
  82. HRESULT InitializeSlotList(ULONG_PTR cslotMax, ULONG_PTR cbSlot, ULONG_PTR cbPage, LPBITARRAY pbits, PLSTSLOT* pplstslot, BYTE** prgslot);
  83. HRESULT ResetSlotList(PLSTSLOT plstslot);
  84. HRESULT ReleaseSlotList(PLSTSLOT plstslot);
  85. ROWBUFF* GetRowBuffer(PLSTSLOT plstslot , HSLOT islot);
  86. class IHashTbl
  87. {
  88. public:
  89. virtual STDMETHODIMP InsertFindBmk
  90. (
  91. BOOL fFindOnly,
  92. HSLOT irowbuff,
  93. ULONG_PTR cbBmk,
  94. BYTE *pbBmk,
  95. ULONG_PTR *pirowbuffFound
  96. ) = 0;
  97. //@cmember Delete a row with the given bookmark from
  98. //the hashtable.
  99. virtual STDMETHODIMP DeleteBmk
  100. (
  101. HSLOT irowbuff
  102. ) = 0;
  103. };
  104. class CHashTbl:public IHashTbl
  105. {
  106. USHORT *m_rgwHash; //@cmember hash array
  107. ULONG m_ulTableSize; //@cmember use this # of elements of the hash array
  108. PLSTSLOT m_pLstSlot; // Pointer to the slot list
  109. public:
  110. CHashTbl();
  111. ~CHashTbl(void);
  112. //@cmember Initialize hashtable object.
  113. BOOL FInit(PLSTSLOT pLstSlot);
  114. //@cmember Find or if not found insert a row with the
  115. //given bookmark into the hashtable.
  116. STDMETHODIMP InsertFindBmk
  117. (
  118. BOOL fFindOnly,
  119. HSLOT irowbuff,
  120. ULONG_PTR cbBmk,
  121. BYTE *pbBmk,
  122. ULONG_PTR *pirowbuffFound
  123. );
  124. //@cmember Delete a row with the given bookmark from
  125. //the hashtable.
  126. STDMETHODIMP DeleteBmk
  127. (
  128. HSLOT iSlot
  129. );
  130. STDMETHODIMP CHashTbl::HashBmk
  131. (
  132. DBBKMARK cbBmk,
  133. const BYTE * pbBmk,
  134. DBHASHVALUE* pdwHashedValue
  135. );
  136. };
  137. #endif