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.

183 lines
5.8 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1991 - 1998.
  5. //
  6. // File: ENTRYBUF.HXX
  7. //
  8. // Contents: CEntryBuffer and associated classes to prepare keys to be
  9. // passed to the volatile index
  10. //
  11. // Classes: CEntryBuffer, CEntryBufferHandler
  12. //
  13. // History: 18-Mar-93 AmyA Created.
  14. //
  15. //----------------------------------------------------------------------------
  16. #pragma once
  17. #include <pfilter.hxx>
  18. #include <entry.hxx>
  19. #include <kvec.hxx>
  20. class CSimplePidRemapper;
  21. const WORKID maxFakeWid = CI_MAX_DOCS_IN_WORDLIST;
  22. //+---------------------------------------------------------------------------
  23. //
  24. // Class: CEntryBuffer
  25. //
  26. // Purpose: A buffer for storing entries created by the filter
  27. //
  28. // Notes: Variable size entries are stored starting from
  29. // the beginning of the buffer. Pointers to these
  30. // entries are stored at the end of the buffer
  31. // growing in the opposite direction (CKeyVector
  32. // encapsulates this). When they meet, WillFit returns
  33. // FALSE.
  34. // _pWidSingle always points to the end of the vector
  35. // array, where a WORKID is stored, followed by space for an
  36. // int, which holds the offset for the beginning of the vector
  37. // array.
  38. //
  39. // History: 28-May-92 KyleP Single WorkId Detection
  40. // 12-Jun-91 BartoszM Created
  41. // 18-Mar-93 AmyA Moved from sort.hxx
  42. // 22-Feb-96 SrikantS Pass buffer as a parameter to ~ctor
  43. // instead of allocating everytime.
  44. //
  45. //----------------------------------------------------------------------------
  46. class CEntryBuffer
  47. {
  48. public:
  49. CEntryBuffer( ULONG cb, BYTE * buf );
  50. void ReInit();
  51. void Done();
  52. inline unsigned Count () const;
  53. inline BOOL WillFit ( unsigned cbKey ) const;
  54. inline void Advance();
  55. void AddEntry ( unsigned cb, const BYTE * key, PROPID pid,
  56. WORKID wid, OCCURRENCE occ);
  57. void AddSentinel() { _keyVec.Sentinel ( (CEntry*) _buf ); }
  58. void Sort ();
  59. inline WORKID SingleWid() const { return *_pWidSingle; }
  60. BYTE * GetBuffer() const { return _buf; }
  61. unsigned GetSize() const { return _cb; }
  62. private:
  63. CEntry * _curEntry;
  64. unsigned _bufSize; // this is the size of the buffer up until
  65. // _pWidSingle
  66. BYTE * _buf;
  67. unsigned _cb; // this is the size of the whole buffer,
  68. // including the WORKID and int at the end.
  69. CKeyVector _keyVec;
  70. //
  71. // *_pWidSingle is set to a specific WorkId if that is the
  72. // *only* workid that shows up in this entrybuffer. Otherwise
  73. // it is set to widInvalid;
  74. //
  75. WORKID * _pWidSingle;
  76. };
  77. //+-------------------------------------------------------------------------
  78. //
  79. // Member: CEntry::Next, public
  80. //
  81. // Synopsis: Moves to next entry
  82. //
  83. // Returns: Pointer to next entry
  84. //
  85. // History: 03-Jun-93 KyleP Fixed for MIPS (dword align)
  86. //
  87. // Notes: Entry buffers must be pointer aligned
  88. //
  89. //--------------------------------------------------------------------------
  90. inline ULONG Roundup( ULONG x, ULONG ulAlign )
  91. {
  92. return x + (ulAlign-1) & ~(ulAlign-1);
  93. }
  94. inline CEntry * CEntry::Next () const
  95. {
  96. //
  97. // Each entry must be dword aligned to avoid faults on MIPS
  98. //
  99. ULONG cb = sizeof CEntry + _cb - 1;
  100. cb = Roundup( cb, sizeof PROPID );
  101. return (CEntry *) ( (BYTE *) this + cb );
  102. }
  103. //+---------------------------------------------------------------------------
  104. //
  105. // Member: CEntryBuffer::Count, public
  106. //
  107. // Synopsis: calculate the count of entries
  108. //
  109. // Returns: Number of entries not counting sentinels
  110. //
  111. // History: 07-Jun-91 BartoszM Created
  112. //
  113. //----------------------------------------------------------------------------
  114. inline unsigned CEntryBuffer::Count() const
  115. {
  116. // get count by taking size of the array of offsets, then subtracting space
  117. // for the two sentinel entries.
  118. // Note: _pWidSingle points to the end of the key vector array as well as
  119. // to a WORKID.
  120. return (unsigned)((CEntry**)_pWidSingle - _keyVec.GetVector()) - 2;
  121. }
  122. //+---------------------------------------------------------------------------
  123. //
  124. // Member: CEntryBuffer::WillFit, public
  125. //
  126. // Synopsis: Check if a key of size cbKey will fit into the buffer
  127. //
  128. // Arguments: [cbKey] -- size of key in bytes
  129. //
  130. // History: 07-Jun-91 BartoszM Created
  131. //
  132. //----------------------------------------------------------------------------
  133. inline BOOL CEntryBuffer::WillFit ( unsigned cbKey ) const
  134. {
  135. unsigned freeSpace = (unsigned)(_keyVec.GetCurPos() - (BYTE*)_curEntry);
  136. // space for entry, key, pointer, and last sentinel
  137. return (
  138. freeSpace >= sizeof ( CEntry ) + cbKey + 2 * sizeof ( CEntry * )
  139. + sizeof(ULONG) - 1 ); // dword alignment
  140. }
  141. //+---------------------------------------------------------------------------
  142. //
  143. // Member: CEntryBuffer::Advance, public
  144. //
  145. // Synopsis: Advances cursor to next entry, stores pointer to
  146. // previous entry in the key vector
  147. //
  148. // History: 07-Jun-91 BartoszM Created
  149. //
  150. //----------------------------------------------------------------------------
  151. inline void CEntryBuffer::Advance()
  152. {
  153. _keyVec.Add ( _curEntry );
  154. _curEntry = _curEntry->Next();
  155. }