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.

100 lines
2.1 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1995 - 2000.
  5. //
  6. // File: pendcur.cxx
  7. //
  8. // Contents: CPendingCursor
  9. //
  10. //--------------------------------------------------------------------------
  11. #include <pch.cxx>
  12. #pragma hdrstop
  13. #include "pendcur.hxx"
  14. CPendingCursor::CPendingCursor( XArray<WORKID> & xWid, unsigned cWid )
  15. : CCursor( iidInvalid ),
  16. _iWid( 0 ),
  17. _cWid( cWid ),
  18. _aWid( xWid.Acquire() )
  19. {
  20. if( _cWid > 1 )
  21. {
  22. // loop from through all elements
  23. for( unsigned j = 1; j < _cWid; j++ )
  24. {
  25. WORKID wid = _aWid[j];
  26. // go backwards from j-1 shifting up keys greater than 'key'
  27. for ( int i = j - 1; i >= 0 && _aWid[i] > wid; i-- )
  28. {
  29. _aWid[i+1] = _aWid[i];
  30. }
  31. // found key less than or equal 'key' or hit the beginning (i == -1)
  32. // insert key in the hole
  33. _aWid[i+1] = wid;
  34. }
  35. // Remove duplicates
  36. unsigned iTarget = 0;
  37. for ( unsigned iSrc = 1; iSrc < _cWid; iSrc++)
  38. {
  39. if ( _aWid[iTarget] == _aWid[iSrc] )
  40. continue;
  41. // wid's are different
  42. // copy source to target and update target index.
  43. iTarget++;
  44. if ( iTarget != iSrc )
  45. _aWid[iTarget] = _aWid[iSrc];
  46. }
  47. _cWid = iTarget + 1; // possibly shrink array
  48. }
  49. }
  50. CPendingCursor::~CPendingCursor()
  51. {
  52. delete [] _aWid;
  53. }
  54. ULONG CPendingCursor::WorkIdCount()
  55. {
  56. return( _cWid );
  57. }
  58. WORKID CPendingCursor::WorkId()
  59. {
  60. if ( _iWid >= _cWid )
  61. return( widInvalid );
  62. else
  63. return( _aWid[_iWid] );
  64. }
  65. WORKID CPendingCursor::NextWorkId()
  66. {
  67. _iWid++;
  68. return( WorkId() );
  69. }
  70. ULONG CPendingCursor::HitCount()
  71. {
  72. return( 1 );
  73. }
  74. LONG CPendingCursor::Rank()
  75. {
  76. return( MAX_QUERY_RANK );
  77. }
  78. void CPendingCursor::RatioFinished (ULONG& denom, ULONG& num)
  79. {
  80. denom = _cWid;
  81. num = min (_iWid, _cWid);
  82. }