Source code of Windows XP (NT5)
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.

179 lines
4.1 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1995 - 1998
  5. //
  6. // File: RowHeap.hxx
  7. //
  8. // Contents: Heap of rowsets.
  9. //
  10. // Classes: CRowHeap
  11. //
  12. // History: 05-Jun-95 KyleP Created
  13. //
  14. //----------------------------------------------------------------------------
  15. #pragma once
  16. #include "rowcomp.hxx"
  17. #include "pcache.hxx"
  18. //+---------------------------------------------------------------------------
  19. //
  20. // Class: CRowHeap
  21. //
  22. // Purpose: Heap of rowsets.
  23. //
  24. // History: 05-Jun-95 KyleP Created.
  25. //
  26. // Notes: This heap implementation has two unusual characteristics:
  27. // a) It can return it's 'nth' element. This is used
  28. // to choose a likely centerpoint for approximate positioning.
  29. // b) It can be reinitialized. Used after positioning cursors
  30. // through some means external to the heap implementation.
  31. //
  32. //----------------------------------------------------------------------------
  33. class CRowHeap
  34. {
  35. public:
  36. CRowHeap( unsigned cCursor );
  37. void Init( CRowComparator * _pComparator,
  38. PMiniRowCache ** apCursor );
  39. void ReInit( int cValid );
  40. ~CRowHeap() {}
  41. //
  42. // Iteration
  43. //
  44. PMiniRowCache::ENext Next( int iDir = 1 );
  45. inline BOOL IsHeapEmpty();
  46. //
  47. // Member access
  48. //
  49. inline PMiniRowCache * Top();
  50. inline PMiniRowCache * RemoveTop();
  51. void NthToTop( unsigned n );
  52. //
  53. // Miscellaneous.
  54. //
  55. PMiniRowCache::ENext Validate();
  56. void AdjustCacheSize( ULONG cRows );
  57. inline HROW const * TopHROWs();
  58. private:
  59. void Add( PMiniRowCache * pCursor );
  60. void MakeHeap( int cValid );
  61. void Reheap();
  62. # if CIDBG == 1
  63. void AssertCursorArrayIsValid();
  64. # endif // CIDBG
  65. inline unsigned Count();
  66. CRowComparator * _pComparator; // Compares two rows
  67. XArray<HROW> _ahrowTop; // Top HROW for each child. Used for bookmarks.
  68. int _iEnd; // Index to last valid cursor in _apCursor
  69. int _cCursor; // Number of elements in _apCursor.
  70. PMiniRowCache ** _apCursor; // One fat cursor per child (max).
  71. };
  72. inline HROW const * CRowHeap::TopHROWs()
  73. {
  74. return _ahrowTop.GetPointer();
  75. }
  76. //+---------------------------------------------------------------------------
  77. //
  78. // Member: CRowHeap::Top, public
  79. //
  80. // Returns: Rowcache with smallest element.
  81. //
  82. // History: 05-Jun-95 KyleP Created.
  83. //
  84. //----------------------------------------------------------------------------
  85. inline PMiniRowCache * CRowHeap::Top()
  86. {
  87. Win4Assert( -1 != _iEnd );
  88. return( _apCursor[0] );
  89. }
  90. //+---------------------------------------------------------------------------
  91. //
  92. // Member: CRowHeap::RemoveTop, public
  93. //
  94. // Synopsis: 'Removes' row cache, by placing it beyond end of maintained
  95. // heap.
  96. //
  97. // Returns: Element which was 'removed'.
  98. //
  99. // History: 05-Jun-95 KyleP Created.
  100. //
  101. //----------------------------------------------------------------------------
  102. inline PMiniRowCache * CRowHeap::RemoveTop()
  103. {
  104. Win4Assert( -1 != _iEnd );
  105. _ahrowTop[_apCursor[0]->Index()] = (HROW)-1;
  106. PMiniRowCache * pTemp = _apCursor[0];
  107. _apCursor[0] = _apCursor[_iEnd];
  108. _apCursor[_iEnd] = pTemp;
  109. _iEnd--;
  110. return( pTemp );
  111. }
  112. //+---------------------------------------------------------------------------
  113. //
  114. // Member: CRowHeap::IsHeapEmpty, public
  115. //
  116. // Returns: TRUE if heap is empty.
  117. //
  118. // History: 05-Jun-95 KyleP Created.
  119. //
  120. //----------------------------------------------------------------------------
  121. inline BOOL CRowHeap::IsHeapEmpty()
  122. {
  123. return (_iEnd == -1);
  124. }
  125. //+---------------------------------------------------------------------------
  126. //
  127. // Member: CRowHeap::Count, public
  128. //
  129. // Returns: Number of elements in heap.
  130. //
  131. // History: 05-Jun-95 KyleP Created.
  132. //
  133. //----------------------------------------------------------------------------
  134. inline unsigned CRowHeap::Count()
  135. {
  136. return( _iEnd + 1 );
  137. }