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.9 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1991 - 1994.
  5. //
  6. // File: WORDLIST.HXX
  7. //
  8. // Contents: Volatile index
  9. //
  10. // Classes: CWordList
  11. //
  12. // History: 06-Mar-91 KyleP Created.
  13. // 04-Apr-91 BartoszM removed init
  14. // 22-May-91 Brianb changed to use own sorter
  15. // 04-Jun-91 BartoszM rewrote it.
  16. // 19-Jun-91 reviewed
  17. //----------------------------------------------------------------------------
  18. #pragma once
  19. #include "index.hxx"
  20. #include "partn.hxx"
  21. #include "sort.hxx"
  22. //+---------------------------------------------------------------------------
  23. //
  24. // Class: CWordList (wl)
  25. //
  26. // Purpose: Volatile, in-memory index
  27. //
  28. // History:
  29. // 06-Mar-91 KyleP Created.
  30. // 15-Apr-91 KyleP Added QueryCursor
  31. // 12-Jun-91 BartoszM Refitted to use sorts
  32. // 27-Jan-92 AmyA Implemented QueryRangeCursor
  33. // 31-Jan-92 AmyA Added QuerySynCursor
  34. // 07-Feb-92 AmyA Added CreateRange
  35. // 14-Feb-92 AmyA Moved CreateRange to CSortChunk
  36. // 18-Mar-93 AmyA Move entry buffer code to entrybuf.hxx
  37. //
  38. // Notes: In the best case, all wordlists should be in physical
  39. // memory. If there is not enough memory, the goal
  40. // is to avoid thrashing. This is achieved by ensuring
  41. // locality of memory references during wordlist
  42. // creation, sorting, seeking, and querying.
  43. //
  44. // Creation: Keys are inserted in consecutive positions
  45. // into the entry buffer that fits in physical memory.
  46. // Sorting: The buffer is sorted in-memory (quicksort)
  47. // The buffer is then copied into a sort chunk.
  48. // There can be several sort chunks in a single wordlist.
  49. // Seeking: The seek has to be done in all the sort chunks.
  50. // Sort chunks are divided into blocks. The header
  51. // of the sort chunk contains a directory of blocks,
  52. // so that the correct block in every chunk can be located
  53. // without touching any other blocks.
  54. // Querying: If there are n sort chunks in a wordlist,
  55. // only n blocks have to be in memory during query.
  56. // They are accessed by n cursors (one per chunk).
  57. //
  58. // For best performance the buffer should fit in physical
  59. // memory (for quicksort not to thrash). The sort chunks
  60. // should be several pages long.
  61. //
  62. //----------------------------------------------------------------------------
  63. const LONGLONG eSigWordList = 0x5453494c44524f57i64;
  64. class CWordList : public CIndex
  65. {
  66. DECLARE_UNWIND
  67. public:
  68. CWordList( INDEXID iid, WORKID widMax );
  69. ~CWordList();
  70. virtual void Remove() {}
  71. void AddWid( WORKID wid, VOLUMEID volumeId )
  72. {
  73. WORKID fakeWid = _widTable.WidToFakeWid( wid );
  74. _widTable.SetVolumeId( fakeWid, volumeId );
  75. }
  76. CKeyCursor * QueryCursor();
  77. CKeyCursor * QueryKeyCursor( CKey const * pKey );
  78. COccCursor * QueryCursor( const CKey * pkey, BOOL isRange, ULONG & cMaxNodes );
  79. COccCursor * QueryRangeCursor( const CKey * pkey,
  80. const CKey * pkeyEnd,
  81. ULONG & cMaxNodes );
  82. COccCursor * QuerySynCursor( CKeyArray & keyArr,
  83. BOOL isRange,
  84. ULONG & cMaxNodes );
  85. unsigned Size () const;
  86. inline BOOL IsEmpty() const;
  87. BOOL MakeChunk( const BYTE * pEntryBuf, ULONG cb );
  88. void Done();
  89. void DeleteWidData( unsigned iDoc )
  90. { _widTable.InvalidateWid( iDocToFakeWid(iDoc) ); }
  91. void MarkWidUnfiltered( unsigned iDoc )
  92. { _widTable.MarkWidUnfiltered( iDocToFakeWid(iDoc) ); }
  93. void GetDocuments( CDocList & doclist );
  94. #if CIDBG==1
  95. BOOL IsWorkIdPresent( WORKID wid ) const
  96. {
  97. return _widTable.IsWorkIdPresent(wid);
  98. }
  99. #endif // CIDBG==1
  100. #ifdef CIEXTMODE
  101. void CiExtDump(void *ciExtSelf);
  102. #endif
  103. private:
  104. const LONGLONG _sigWordList; // "WORDLIST"
  105. unsigned _count; // Count of chunks
  106. CSortChunk* _chunks; // Chunks
  107. CMaxOccTable _maxOccTable; // Max occurrences of wids
  108. CWidTable _widTable; // Wid-to-fake-wid mapping
  109. BOOL _fUnfiltered; // TRUE if there are unfiltered wids
  110. };
  111. inline BOOL CWordList::IsEmpty() const
  112. {
  113. return( _count == 0 && !_fUnfiltered );
  114. }
  115. //+---------------------------------------------------------------------------
  116. //
  117. // Class: PWordList
  118. //
  119. // Purpose: Smart Pointer to word list
  120. //
  121. // History:
  122. // 31-Dec-91 BartoszM Created
  123. //
  124. //----------------------------------------------------------------------------
  125. class PWordList
  126. {
  127. public:
  128. PWordList ()
  129. {
  130. _pWordList = 0;
  131. }
  132. ~PWordList () { delete _pWordList; }
  133. CWordList* operator-> () { return _pWordList; }
  134. CWordList& operator * () { return *_pWordList; }
  135. BOOL IsNull() { return( _pWordList == 0 ); }
  136. void Transfer ( CPartition* pPart )
  137. {
  138. pPart->AddIndex ( _pWordList );
  139. _pWordList = 0;
  140. }
  141. void Initialize ( INDEXID iid, WORKID widMax )
  142. {
  143. Win4Assert ( _pWordList == 0 );
  144. _pWordList = new CWordList ( iid, widMax );
  145. }
  146. void Delete ()
  147. {
  148. delete _pWordList;
  149. _pWordList = 0;
  150. }
  151. private:
  152. CWordList* _pWordList;
  153. };