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.

178 lines
4.6 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 1994.
  5. //
  6. // File: buketize.cxx
  7. //
  8. // Classes: CBuketizeWindows
  9. //
  10. // History: 2-16-95 srikants Created
  11. //
  12. //----------------------------------------------------------------------------
  13. #include "pch.cxx"
  14. #pragma hdrstop
  15. #include <bigtable.hxx>
  16. #include "buketize.hxx"
  17. CBucketizeWindows::CBucketizeWindows( CLargeTable & largeTable,
  18. CTableWindow &srcWindow )
  19. : _largeTable(largeTable),
  20. _srcWindow( srcWindow ),
  21. _fFirstBkt(TRUE),
  22. _cRowsToCopy(0),
  23. _pBucket(0)
  24. {
  25. }
  26. //+---------------------------------------------------------------------------
  27. //
  28. // Function: _AddWorkIds
  29. //
  30. // Synopsis: Adds workids from the given window to the bucket.
  31. //
  32. // Arguments: [iter] -
  33. //
  34. // History: 2-16-95 srikants Created
  35. // 4-27-95 srikants Modified to deal with converting
  36. // single window to multiple buckets.
  37. //
  38. // Notes:
  39. //
  40. //----------------------------------------------------------------------------
  41. ULONG CBucketizeWindows::_AddWorkIds( CWindowRowIter & iter )
  42. {
  43. #if CIDBG==1
  44. ULONG cTotal = iter.TotalRows();
  45. Win4Assert( _cRowsToCopy+iter.GetCurrPos() <= cTotal );
  46. #endif // CIDBG==1
  47. Win4Assert( 0 != _pBucket );
  48. ULONG iFirstRow = ULONG_MAX;
  49. ULONG iLastRow = ULONG_MAX;
  50. ULONG cRowsCopied = 0;
  51. for ( ; !iter.AtEnd() && (cRowsCopied < _cRowsToCopy) ; iter.Next() )
  52. {
  53. if ( !iter.IsDeletedRow() )
  54. {
  55. iLastRow = iter.GetCurrPos();
  56. if ( 0 == cRowsCopied )
  57. iFirstRow = iter.GetCurrPos();
  58. _pBucket->_AddWorkId( iter.Get(), iter.Rank(), iter.HitCount() );
  59. cRowsCopied++;
  60. }
  61. }
  62. //
  63. // Initialize the lowest and the highest rows.
  64. //
  65. if ( 0 != cRowsCopied )
  66. {
  67. _srcWindow.GetSortKey( iFirstRow,
  68. _pBucket->GetLowestKey() );
  69. _srcWindow.GetSortKey( iLastRow,
  70. _pBucket->GetHighestKey() );
  71. }
  72. return cRowsCopied;
  73. }
  74. //+---------------------------------------------------------------------------
  75. //
  76. // Function: LokCreateBuckets
  77. //
  78. // Synopsis: Creates buckets from the source window.
  79. //
  80. // Arguments: [pSortSet] - The sortset on the table.
  81. // [colSet] - Master column set for the table.
  82. // [segId] - Segment Id for the new bucket.
  83. //
  84. // History: 2-16-95 srikants Created
  85. //
  86. // Notes:
  87. //
  88. //----------------------------------------------------------------------------
  89. void CBucketizeWindows::LokCreateBuckets( const CSortSet & sortSet,
  90. CTableKeyCompare & comparator,
  91. CColumnMasterSet & colSet
  92. )
  93. {
  94. CWindowRowIter iter(_srcWindow);
  95. ULONG cRowsRemaining = iter.TotalRows();
  96. const cRowsPerBkt = CTableSink::cBucketRowLimit;
  97. const cRowsMax = cRowsPerBkt * 110 /100; // allow a 10% fall over
  98. //
  99. // While there are more rows in the windows, copy a set to the next
  100. // bucket.
  101. //
  102. while ( !iter.AtEnd() )
  103. {
  104. if ( cRowsRemaining <= cRowsMax )
  105. {
  106. //
  107. // This is to prevent a very small last bucket.
  108. //
  109. _cRowsToCopy = cRowsRemaining;
  110. }
  111. else
  112. {
  113. _cRowsToCopy = cRowsPerBkt;
  114. }
  115. ULONG bktSegId;
  116. if ( _fFirstBkt )
  117. {
  118. //
  119. // For the first bucket, use the same segment id as the original
  120. // window.
  121. //
  122. bktSegId = _srcWindow.GetSegId();
  123. _fFirstBkt = FALSE;
  124. }
  125. else
  126. {
  127. bktSegId = _largeTable._AllocSegId();
  128. }
  129. //
  130. // Create a new bucket and append it to the end of bucket list.
  131. //
  132. _pBucket = new CTableBucket( sortSet,
  133. comparator,
  134. colSet,
  135. bktSegId );
  136. //
  137. // Add the workids from the _iStart to _iEnd to the bucket.
  138. //
  139. ULONG cRowsCopied = _AddWorkIds( iter );
  140. if ( 0 != cRowsCopied )
  141. {
  142. _bktList.Queue( _pBucket );
  143. _pBucket = 0;
  144. }
  145. Win4Assert( iter.GetCurrPos() <= iter.TotalRows() );
  146. cRowsRemaining = iter.TotalRows() - iter.GetCurrPos();
  147. }
  148. Win4Assert( cRowsRemaining == 0 );
  149. }