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.

110 lines
2.8 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 1992.
  5. //
  6. // File: IdxLst.cxx
  7. //
  8. // Contents: Index list.
  9. //
  10. // Classes: CIndexList
  11. //
  12. // History: 04-Apr-92 BartoszM Created
  13. //
  14. //--------------------------------------------------------------------------
  15. #include <pch.cxx>
  16. #pragma hdrstop
  17. #include "idxlst.hxx"
  18. #include "index.hxx"
  19. //+---------------------------------------------------------------------------
  20. //
  21. // Member: CIndexList::Add, public
  22. //
  23. // Arguments: [pIndex] -- index pointer
  24. //
  25. // History: 04-Apr-91 BartoszM Created.
  26. //
  27. // Notes: It is a circular list, wordlist are forward from the root,
  28. // persistent indexes, from big to small, backward from
  29. // the root.
  30. //
  31. //----------------------------------------------------------------------------
  32. void CIndexList::Add ( CIndex* pIndex )
  33. {
  34. ciDebugOut (( DEB_ITRACE, "IndexList::Add %x\n", pIndex->GetId() ));
  35. // wordlists to the right
  36. if ( pIndex->IsWordlist() )
  37. {
  38. Push (pIndex);
  39. _countWl++;
  40. }
  41. else
  42. {
  43. unsigned size = pIndex->Size();
  44. // walk the list backwards from root
  45. for ( CBackIndexIter iter(*this); !AtEnd(iter); BackUp(iter) )
  46. {
  47. if ( iter->IsWordlist() || iter->Size() <= size )
  48. {
  49. pIndex->InsertAfter(iter.GetIndex());
  50. _count++;
  51. _sizeIndex += pIndex->Size();
  52. return;
  53. }
  54. }
  55. // reached the end
  56. ciAssert( AtEnd(iter) );
  57. Push (pIndex);
  58. }
  59. }
  60. //+---------------------------------------------------------------------------
  61. //
  62. // Member: CIndexList::Remove, public
  63. //
  64. // Arguments: [iid] -- index id
  65. //
  66. // Returns: pointer to the removed index
  67. //
  68. // History: 04-Apr-91 BartoszM Created.
  69. //
  70. //----------------------------------------------------------------------------
  71. CIndex* CIndexList::Remove ( INDEXID iid )
  72. {
  73. ciDebugOut (( DEB_ITRACE, "IndexList::Remove %x\n", iid ));
  74. if ( IsEmpty() )
  75. return 0;
  76. for ( CForIndexIter iter(*this); !AtEnd(iter); Advance(iter) )
  77. {
  78. ciDebugOut((DEB_CAT,"\t%x [%d]\n", iter->GetId(), iter->Size()));
  79. if ( iter->GetId() == iid )
  80. {
  81. iter->Unlink();
  82. _count--;
  83. _sizeIndex -= iter->Size();
  84. Win4Assert( (_count == 0 && _sizeIndex == 0) || (_count > 0 && _sizeIndex > 0) );
  85. if ( iter->IsWordlist() )
  86. _countWl--;
  87. break;
  88. }
  89. }
  90. if ( AtEnd(iter) )
  91. return( 0 );
  92. else
  93. return iter.GetIndex();
  94. }