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.

371 lines
8.9 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1995 - 2000.
  5. //
  6. // File: tblbuket.cxx
  7. //
  8. // Contents: Implementation of the bucket in large table.
  9. //
  10. // Classes: CTableBucket
  11. // CBucketRowIter
  12. //
  13. // History: 2-14-95 srikants Created
  14. //
  15. //--------------------------------------------------------------------------
  16. #pragma once
  17. #include <tableseg.hxx>
  18. #include <compare.hxx>
  19. #include <widiter.hxx>
  20. #include <tblrowal.hxx> // for CTableRowAlloc
  21. #include "bmkmap.hxx" // for Book Mark Mapping
  22. class CQuickBktCompare;
  23. class CTableWindow;
  24. class CLargeTable;
  25. //+---------------------------------------------------------------------------
  26. //
  27. // Class: CRowLocateInfo
  28. //
  29. // Purpose: A class that gets the location of a row in a segment. This
  30. // is used while locating a row in a bucket.
  31. //
  32. // History: 4-20-95 srikants Created
  33. //
  34. // Notes:
  35. //
  36. //----------------------------------------------------------------------------
  37. class CRowLocateInfo
  38. {
  39. friend class CTableBucket;
  40. public:
  41. CRowLocateInfo( WORKID widStart, LONG cRowsToMove ) :
  42. _widStart(widStart), _cRowsToMove(cRowsToMove),
  43. _cRowsResidual(LONG_MAX),
  44. _widOut(widInvalid), _rowOffset(ULONG_MAX)
  45. {
  46. }
  47. WORKID WidStart() const { return _widStart; }
  48. LONG RowsToMove() const { return _cRowsToMove; }
  49. BOOL IsFound() const
  50. {
  51. return 0 == _cRowsResidual &&
  52. WORKID_TBLBEFOREFIRST != _widOut &&
  53. WORKID_TBLAFTERLAST != _widOut;
  54. }
  55. WORKID WorkIdFound() const { return _widOut; }
  56. ULONG WorkIdOffset() const { return _rowOffset; }
  57. LONG ResidualRowCount() const { return _cRowsResidual; }
  58. void SetLookInNext( LONG cRowsLeft )
  59. {
  60. _cRowsResidual = cRowsLeft;
  61. _widOut = WORKID_TBLAFTERLAST;
  62. }
  63. void SetLookInPrev( LONG cRowsLeft )
  64. {
  65. _cRowsResidual = cRowsLeft;
  66. _widOut = WORKID_TBLBEFOREFIRST;
  67. }
  68. void SetRowFound( ULONG rowOffset, WORKID widFound )
  69. {
  70. _cRowsResidual = 0;
  71. _widOut = widFound;
  72. _rowOffset = rowOffset;
  73. }
  74. void SetAll( WORKID widOut, LONG rowsResidual,
  75. ULONG rowOffset = ULONG_MAX )
  76. {
  77. _widOut = widOut;
  78. _cRowsResidual = rowsResidual;
  79. _rowOffset = rowOffset;
  80. }
  81. private:
  82. //
  83. // Inputs to the search.
  84. //
  85. const WORKID _widStart;
  86. const LONG _cRowsToMove;
  87. //
  88. // Output from the search.
  89. //
  90. LONG _cRowsResidual;
  91. WORKID _widOut;
  92. ULONG _rowOffset;
  93. };
  94. //+-------------------------------------------------------------------------
  95. //
  96. // Class: CTableBucket
  97. //
  98. // Purpose: A segment of a large table which only has an identifier
  99. // for each row buffered in memory.
  100. // It must be converted to a window before it can be
  101. // transferred to the user.
  102. //
  103. // Interface:
  104. //
  105. //--------------------------------------------------------------------------
  106. class CTableBucket : public CTableSegment
  107. {
  108. friend class CBucketRowIter;
  109. friend class CBucketizeWindows;
  110. friend class CLargeTable;
  111. public:
  112. CTableBucket( const CSortSet & sortSet,
  113. CTableKeyCompare & comparator,
  114. CColumnMasterSet & masterColSet,
  115. ULONG segId ) ;
  116. // Virtual methods inherited from CTableSegment
  117. BOOL PutRow( CRetriever & obj, CTableRowKey & currKey );
  118. DBCOUNTITEM RowCount()
  119. {
  120. return _hTable.Count();
  121. }
  122. SCODE GetRows( WORKID widStart,
  123. CTableColumnSet const & rOutColumns,
  124. CGetRowsParams& rGetParams,
  125. WORKID& rwidNextRowToTransfer );
  126. //
  127. // Sort related methods.
  128. //
  129. BOOL IsRowInSegment( WORKID wid )
  130. {
  131. return _hTable.IsWorkIdPresent( wid );
  132. }
  133. //
  134. // Notification methods
  135. //
  136. SCODE GetNotifications(CNotificationParams &Params)
  137. {
  138. return S_OK;
  139. }
  140. BOOL IsEmptyForQuery()
  141. {
  142. return 0 == _hTable.Count();
  143. }
  144. BOOL IsGettingFull();
  145. // Virtual methods inherited from CTableSink
  146. BOOL IsSortedSplit( ULONG & riSplit )
  147. {
  148. return FALSE;
  149. }
  150. WORKID PathToWorkID( CRetriever & obj,
  151. CTableSink::ERowType eRowType )
  152. {
  153. Win4Assert( !"Should not be called\n" );
  154. return widInvalid;
  155. }
  156. BOOL WorkIdToPath( WORKID wid, CInlineVariant & pathVarnt ,
  157. ULONG & cbVarnt );
  158. void SetLargeTable( CLargeTable * pLargeTable )
  159. {
  160. _pLargeTable = pLargeTable;
  161. }
  162. BOOL PutRow( CRetriever & obj, CTableSink::ERowType eRowType )
  163. {
  164. Win4Assert( !"Must not be called" );
  165. return FALSE;
  166. }
  167. BOOL RemoveRow( PROPVARIANT const & varUnique,
  168. WORKID & widNext,
  169. CI_TBL_CHAPT & chapt );
  170. //
  171. // Sort order
  172. //
  173. CSortSet const & SortOrder();
  174. BOOL IsSorted() const { return _fSorted; }
  175. WORKID WorkIdAtOffset( ULONG offset ) const;
  176. BOOL RowOffset( WORKID wid, ULONG & rOffset );
  177. #ifdef CIEXTMODE
  178. void CiExtDump(void *ciExtSelf);
  179. #endif
  180. private:
  181. WORKID _minWid, _maxWid; // range of work IDs in table segment
  182. BOOL _fSorted; // Set to TRUE if we know for sure
  183. // if the wids are in sorted order.
  184. //
  185. // Array of workids that belong to this bucket. They are stored in the
  186. // same order as they are added. This way if a bucket never gets new
  187. // rows, we can be sure that it is still sorted.
  188. //
  189. CDynArrayInPlace<WORKID> _widArray;
  190. CDynArrayInPlace<LONG> _aRank;
  191. BOOL _fStoreRank;
  192. CDynArrayInPlace<LONG> _aHitCount;
  193. BOOL _fStoreHitCount;
  194. //
  195. // Hash table used to look up workids in this bucket.
  196. //
  197. TWidHashTable<CWidValueHashEntry> _hTable;
  198. //
  199. // For downlevel Wid->Path translation
  200. //
  201. CCompressedCol * _pPathCompressor;
  202. CLargeTable * _pLargeTable;
  203. BOOL _AddWorkId( WORKID wid, LONG lRank, LONG lHitCount );
  204. #if DBG==1
  205. void _CheckIfTooBig();
  206. #endif // DBG==1
  207. };
  208. //+---------------------------------------------------------------------------
  209. //
  210. // Class: CBucketRowIter
  211. //
  212. // Purpose: Iterator over wids in a bucket.
  213. //
  214. // History: 2-17-95 srikants Created
  215. //
  216. // Notes:
  217. //
  218. //----------------------------------------------------------------------------
  219. class CBucketRowIter : public PWorkIdIter
  220. {
  221. public:
  222. CBucketRowIter( CTableBucket & bkt, BOOL fRetrievePath ) :
  223. _curr(0),
  224. _widArray( bkt._widArray ),
  225. _aRank( bkt._aRank ),
  226. _aHitCount( bkt._aHitCount ),
  227. _bucket(bkt),
  228. _pathVarnt( * ((CInlineVariant *)&_abPathVarnt[0]) ),
  229. _fRetrievePath(fRetrievePath),
  230. _cwcCurrPath(0),
  231. _pwszPath( (WCHAR *) _pathVarnt.GetVarBuffer() )
  232. {}
  233. WORKID WorkId(); // virtual
  234. WORKID NextWorkId(); // virtual
  235. LONG Rank()
  236. {
  237. if ( 0 != _aRank.Count() )
  238. {
  239. Win4Assert( _curr < _aRank.Count() );
  240. return _aRank[ _curr ];
  241. }
  242. else
  243. {
  244. return MAX_QUERY_RANK;
  245. }
  246. }
  247. LONG HitCount()
  248. {
  249. if ( 0 != _aHitCount.Count() )
  250. {
  251. Win4Assert( _curr < _aHitCount.Count() );
  252. return _aHitCount[ _curr ];
  253. }
  254. else
  255. {
  256. return 0;
  257. }
  258. }
  259. WCHAR const * Path(); // virtual
  260. unsigned PathSize(); // virtual
  261. private:
  262. BOOL _AtEnd() const
  263. {
  264. Win4Assert( _curr <= _widArray.Count() );
  265. return _curr == _widArray.Count();
  266. }
  267. WORKID _Get()
  268. {
  269. Win4Assert( _curr < _widArray.Count() );
  270. return _widArray.Get( _curr );
  271. }
  272. void _Next()
  273. {
  274. _curr++;
  275. }
  276. unsigned _curr;
  277. CDynArrayInPlace<WORKID> & _widArray;
  278. CDynArrayInPlace<LONG> & _aRank;
  279. CDynArrayInPlace<LONG> & _aHitCount;
  280. CTableBucket & _bucket;
  281. enum { cbPathVarnt = sizeof(CTableVariant) + (MAX_PATH+1)*sizeof(WCHAR) };
  282. BYTE _abPathVarnt[cbPathVarnt];
  283. CInlineVariant & _pathVarnt;
  284. BOOL _fRetrievePath;
  285. ULONG _cwcCurrPath;
  286. WCHAR * _pwszPath;
  287. };