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.

121 lines
3.0 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1991 - 1998.
  5. //
  6. // File: keycur.hxx
  7. //
  8. // Contents: Key cursor classes
  9. //
  10. // Classes: CKeyCursor - 'The mother of all key cursors'
  11. //
  12. // History: 15-Apr-91 KyleP Created.
  13. // 26-Sep-91 BartoszM Made it a subclass
  14. // 18-Feb-92 AmyA Changed from CIndexCursor to
  15. // CKeyCursor.
  16. //
  17. //----------------------------------------------------------------------------
  18. #pragma once
  19. #include <misc.hxx>
  20. #include <ocursor.hxx>
  21. class CKeyBuf;
  22. //+---------------------------------------------------------------------------
  23. //
  24. // Class: CKeyCursor
  25. //
  26. // Purpose: The root class for all key cursors
  27. //
  28. // Interface:
  29. //
  30. // History: 15-Apr-91 KyleP Created.
  31. // 22-Jul-92 BartoszM added weight, rank, and max wid
  32. // 23-Jun-94 SitaramR removed _widMax.
  33. //
  34. //----------------------------------------------------------------------------
  35. class CKeyCursor : public COccCursor
  36. {
  37. public:
  38. CKeyCursor ( INDEXID iid, WORKID widMax )
  39. : COccCursor(iid, widMax),
  40. _lStatWeight( 0xffffffff ) {}
  41. CKeyCursor () {}
  42. virtual const CKeyBuf * GetKey() = 0;
  43. // GetNextKey should always update _pid!
  44. // and _lStatWeight
  45. virtual const CKeyBuf * GetNextKey() = 0;
  46. virtual ULONG OccurrenceCount() { return(0); }
  47. virtual WORKID MaxWorkId() { return(_widMax); }
  48. virtual LONG Rank()
  49. {
  50. LONG rank;
  51. //
  52. // Only string keys really have a rank with any meaning.
  53. //
  54. if ( GetKey()->IsValue() )
  55. {
  56. rank = MAX_QUERY_RANK;
  57. }
  58. else
  59. {
  60. OCCURRENCE maxOcc = MaxOccurrence();
  61. Win4Assert( maxOcc > 0 );
  62. Win4Assert( 0xffffffff != _lStatWeight );
  63. rank = RANK_MULTIPLIER * HitCount() * _lStatWeight / maxOcc;
  64. #if CIDBG == 1
  65. if ( rank < 0 )
  66. ciDebugOut(( DEB_WARN,
  67. "keycur rank 0x%x, maxOcc 0x%x, _lStatWeight 0x%x, HitCount 0x%x\n",
  68. rank, maxOcc, _lStatWeight, HitCount() ));
  69. #endif
  70. if (rank > MAX_QUERY_RANK)
  71. rank = MAX_QUERY_RANK;
  72. }
  73. return rank;
  74. }
  75. virtual void FreeStream() {}
  76. virtual void RefillStream() {}
  77. void RatioFinished ( ULONG& denom, ULONG& num )
  78. {
  79. Win4Assert ( !"RatioFinished called for random CKeyCursor" );
  80. }
  81. #ifdef CIEXTMODE
  82. void CiExtDump(void *ciExtSelf);
  83. #endif
  84. protected:
  85. void UpdateWeight()
  86. {
  87. ULONG widCount = WorkIdCount();
  88. if ( widCount == 0 )
  89. _lStatWeight = 0;
  90. else
  91. _lStatWeight = Log2(_widMax / widCount);
  92. }
  93. LONG _lStatWeight; // statistical weight for current key
  94. };