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.

235 lines
5.1 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1991 - 1998.
  5. //
  6. // File: FRETABLE.HXX
  7. //
  8. // Contents: Fresh table
  9. //
  10. // Classes: CFreshItem, CFreshTable, CIdxSubstitution, CFreshTableIter
  11. //
  12. // History: 15-Oct-91 BartoszM created
  13. // 5-Dec-97 dlee rewrote as simple sorted array
  14. //
  15. //
  16. //--------------------------------------------------------------------------
  17. #pragma once
  18. #include <tsort.hxx>
  19. //+-------------------------------------------------------------------------
  20. //
  21. // Class: CIdxSubstitution
  22. //
  23. // Purpose: Holds info about substituting index ids after a merge
  24. //
  25. // History: ?
  26. //
  27. //--------------------------------------------------------------------------
  28. class CIdxSubstitution
  29. {
  30. public:
  31. CIdxSubstitution (BOOL isMaster, INDEXID iid, int cInd, INDEXID const * aIidOld)
  32. :_isMaster(isMaster),
  33. _iid (iid),
  34. _cInd (cInd),
  35. _aIidOld (aIidOld) {}
  36. BOOL IsMaster() const { return _isMaster; }
  37. INDEXID IidOldDeleted () const
  38. {
  39. Win4Assert (_isMaster);
  40. return _iid;
  41. }
  42. INDEXID IidNew () const
  43. {
  44. Win4Assert (!_isMaster);
  45. return _iid;
  46. }
  47. BOOL Find (INDEXID iid) const
  48. {
  49. for ( int j = 0; j < _cInd; j++ )
  50. {
  51. if ( iid == _aIidOld[j] )
  52. {
  53. return TRUE;
  54. }
  55. }
  56. return FALSE;
  57. }
  58. private:
  59. const BOOL _isMaster;
  60. const INDEXID _iid; // if is master, old iid deleted, otherwise iid merge target
  61. const int _cInd;
  62. INDEXID const * const _aIidOld;
  63. };
  64. //+-------------------------------------------------------------------------
  65. //
  66. // Class: CFreshItem
  67. //
  68. // Purpose: A single fresh item
  69. //
  70. // History: 5-Dec-97 dlee created
  71. //
  72. //--------------------------------------------------------------------------
  73. class CFreshItem
  74. {
  75. public:
  76. INDEXID IndexId() const { return _iid; }
  77. WORKID WorkId() const { return _wid; }
  78. void SetIndexId ( INDEXID iid )
  79. {
  80. _iid = iid;
  81. }
  82. int Compare( CFreshItem const * p2 ) const
  83. {
  84. if ( _wid < p2->_wid )
  85. return -1;
  86. return ( _wid != p2->_wid );
  87. }
  88. int Compare( const WORKID wid ) const
  89. {
  90. if ( _wid < wid )
  91. return -1;
  92. return ( _wid != wid );
  93. }
  94. BOOL IsEQ( const WORKID wid ) const
  95. {
  96. return ( _wid == wid );
  97. }
  98. BOOL IsLT( const WORKID wid ) const
  99. {
  100. return ( _wid < wid );
  101. }
  102. BOOL IsGT( const WORKID wid ) const
  103. {
  104. return ( _wid > wid );
  105. }
  106. BOOL IsGE( const WORKID wid ) const
  107. {
  108. return ( _wid >= wid );
  109. }
  110. BOOL IsEQ( CFreshItem const * p2 ) const
  111. {
  112. return ( _wid == p2->_wid );
  113. }
  114. BOOL IsLT( CFreshItem const * p2 ) const
  115. {
  116. return ( _wid < p2->_wid );
  117. }
  118. BOOL IsGT( CFreshItem const * p2 ) const
  119. {
  120. return ( _wid > p2->_wid );
  121. }
  122. BOOL IsGE( CFreshItem const * p2 ) const
  123. {
  124. return ( _wid >= p2->_wid );
  125. }
  126. WORKID _wid;
  127. INDEXID _iid;
  128. };
  129. //+-------------------------------------------------------------------------
  130. //
  131. // Class: CFreshTable
  132. //
  133. // Purpose: Table of fresh items
  134. //
  135. // History: 5-Dec-97 dlee created
  136. //
  137. //--------------------------------------------------------------------------
  138. class CFreshTable
  139. {
  140. friend class CFreshTableIter;
  141. public:
  142. CFreshTable( unsigned size ) : _aItems( size ) {}
  143. CFreshTable( CFreshTable & freshTable );
  144. CFreshTable( CFreshTable const & freshTable,
  145. CIdxSubstitution const & subst);
  146. unsigned Count() const { return _aItems.Count(); }
  147. void Add( WORKID wid, INDEXID iid );
  148. INDEXID AddReplace( WORKID wid, INDEXID iid );
  149. CFreshItem * Find( WORKID wid )
  150. {
  151. CSortable<CFreshItem,WORKID> sort( _aItems );
  152. return sort.Search( wid );
  153. }
  154. void ModificationsComplete();
  155. private:
  156. CDynArrayInPlace<CFreshItem> _aItems;
  157. };
  158. //+-------------------------------------------------------------------------
  159. //
  160. // Class: CFreshTableIter
  161. //
  162. // Synopsis: Iterates over a CFreshTable
  163. //
  164. // History: 93-Nov-15 DwightKr Created
  165. //
  166. //--------------------------------------------------------------------------
  167. class CFreshTableIter
  168. {
  169. public:
  170. CFreshTableIter( CFreshTable const & table ) :
  171. _table ( table ),
  172. _iRow( 0 )
  173. {
  174. Advance(); // Move to the first entry
  175. }
  176. BOOL AtEnd() { return ( 0 == _pItem ); }
  177. void Advance()
  178. {
  179. if ( _iRow < _table.Count() )
  180. _pItem = & ( _table._aItems[ _iRow++ ] );
  181. else
  182. _pItem = 0;
  183. }
  184. CFreshItem * operator->() { return _pItem; }
  185. private:
  186. CFreshItem * _pItem;
  187. unsigned _iRow;
  188. CFreshTable const & _table;
  189. };