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.

192 lines
5.1 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1991 - 1998.
  5. //
  6. // File: FRETABLE.CXX
  7. //
  8. // Contents: Fresh table
  9. //
  10. // Classes: CFreshTable
  11. //
  12. // History: 15-Oct-91 BartoszM created
  13. // 5-Dec-97 dlee rewrote as simple sorted array
  14. //
  15. //--------------------------------------------------------------------------
  16. #include <pch.cxx>
  17. #pragma hdrstop
  18. #include <fretable.hxx>
  19. //+-------------------------------------------------------------------------
  20. //
  21. // Method: CFreshTable::Add, public
  22. //
  23. // Synopsis: Adds an entry to the table
  24. //
  25. // Arguments: [wid] -- work id
  26. // [iid] -- index id
  27. //
  28. // History: 5-Dec-97 dlee created
  29. //
  30. //--------------------------------------------------------------------------
  31. void CFreshTable::Add( WORKID wid, INDEXID iid )
  32. {
  33. //
  34. // The most typical case is that items arrive sorted. Use Get() instead
  35. // of operator [] since Add isn't const.
  36. //
  37. ULONG cItems = _aItems.Count();
  38. ULONG index;
  39. if ( 0 == cItems )
  40. index = 0;
  41. else if ( wid > _aItems.Get( cItems - 1 )._wid )
  42. index = cItems;
  43. else
  44. {
  45. CSortable<CFreshItem,WORKID> sort( _aItems );
  46. // duplicates are not expected here
  47. Win4Assert( !sort.Search( wid ) );
  48. index = sort.FindInsertionPoint( wid );
  49. ciDebugOut(( DEB_ITRACE, "insert, count %d index %d\n",
  50. cItems, index ));
  51. }
  52. CFreshItem itemTmp;
  53. itemTmp._wid = wid;
  54. itemTmp._iid = iid;
  55. _aItems.Insert( itemTmp, index );
  56. } //Add
  57. //+-------------------------------------------------------------------------
  58. //
  59. // Method: CFreshTable::AddReplace, public
  60. //
  61. // Synopsis: Either updates the iid of an existing item, or adds the item
  62. //
  63. // Arguments: [wid] -- work id
  64. // [iid] -- index id
  65. //
  66. // History: 5-Dec-97 dlee created
  67. //
  68. //--------------------------------------------------------------------------
  69. INDEXID CFreshTable::AddReplace( WORKID wid, INDEXID iid )
  70. {
  71. CFreshItem * p = Find( wid );
  72. INDEXID iidOld;
  73. if ( 0 == p )
  74. {
  75. iidOld = iidInvalid;
  76. Add( wid, iid );
  77. }
  78. else
  79. {
  80. iidOld = p->_iid;
  81. p->_iid = iid;
  82. }
  83. return iidOld;
  84. } //AddReplace
  85. //+-------------------------------------------------------------------------
  86. //
  87. // Method: CFreshTable::CFreshTable, public
  88. //
  89. // Synopsis: Constructs a fresh table
  90. //
  91. // Arguments: [freshTable] -- Table from which a copy is made
  92. //
  93. // History: 5-Dec-97 dlee created
  94. //
  95. //--------------------------------------------------------------------------
  96. CFreshTable::CFreshTable(
  97. CFreshTable & freshTable ) :
  98. _aItems( freshTable._aItems,
  99. freshTable._aItems.Count() + CI_MAX_DOCS_IN_WORDLIST )
  100. {
  101. //
  102. // the CI_MAX_DOCS_IN_WORDLIST above is a hint that up to 16 items may
  103. // be added to the test, so that much space should be reserved now.
  104. //
  105. } //CFreshTable
  106. //+-------------------------------------------------------------------------
  107. //
  108. // Method: CFreshTable::CFreshTable, public
  109. //
  110. // Synopsis: Constructs a fresh table
  111. //
  112. // Arguments: [freshTable] -- Table from which a copy is made
  113. // [subst] -- Index substitution object for new table
  114. //
  115. // History: 5-Dec-97 dlee created
  116. //
  117. //--------------------------------------------------------------------------
  118. CFreshTable::CFreshTable(
  119. CFreshTable const & freshTable,
  120. CIdxSubstitution const & subst) :
  121. _aItems( freshTable._aItems.Count() )
  122. {
  123. for ( unsigned i = 0; i < freshTable._aItems.Count(); i++ )
  124. {
  125. CFreshItem const & item = freshTable._aItems[i];
  126. if (subst.IsMaster())
  127. {
  128. // skip old deleted and old indexes
  129. if ( item._iid != subst.IidOldDeleted() &&
  130. !subst.Find( item._iid) )
  131. Add( item._wid, item._iid );
  132. }
  133. else
  134. {
  135. // replace source indexes with the new index id
  136. INDEXID iid = item._iid;
  137. if ( subst.Find( iid ) )
  138. iid = subst.IidNew();
  139. Add( item._wid, iid );
  140. }
  141. }
  142. } //CFreshTable
  143. //+-------------------------------------------------------------------------
  144. //
  145. // Method: CFreshTable::ModificationsComplete, public
  146. //
  147. // Synopsis: Called when updates to the table have completed, so memory
  148. // usage can be trimmed if possible.
  149. //
  150. // History: 5-Dec-97 dlee created
  151. //
  152. //--------------------------------------------------------------------------
  153. void CFreshTable::ModificationsComplete()
  154. {
  155. // Make sure we're really sorted
  156. CSortable<CFreshItem,WORKID> sort( _aItems );
  157. Win4Assert( sort.IsSorted() );
  158. // save memory if the size is much larger than the count
  159. if ( _aItems.Size() > ( _aItems.Count() + 100 ) )
  160. _aItems.Shrink();
  161. } //ModificationsComplete