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.

139 lines
3.5 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1991 - 2000.
  5. //
  6. // File: entry.hxx
  7. //
  8. // Contents: Class for an entry in the entry buffer
  9. //
  10. // Classes: CEntry
  11. //
  12. // History: 12-Jun-91 BartoszM Created
  13. // 18-Mar-93 AmyA Moved from sort.hxx
  14. //
  15. //----------------------------------------------------------------------------
  16. //+---------------------------------------------------------------------------
  17. //
  18. // Class: CEntry
  19. //
  20. // Purpose: An encapsulation of variable size structure
  21. // to be stored in the entry buffer
  22. //
  23. // History: 12-Jun-91 BartoszM Created
  24. // 18-Mar-93 AmyA Moved from sort.hxx
  25. //
  26. //----------------------------------------------------------------------------
  27. #pragma once
  28. inline int CompareULONG( ULONG a, ULONG b )
  29. {
  30. // Empirical evidence shows that checking in this order is most optimal
  31. if ( a == b )
  32. return 0;
  33. if ( a > b )
  34. return 1;
  35. return -1;
  36. }
  37. class CEntry
  38. {
  39. public:
  40. CEntry() {}
  41. int Compare( const CEntry * pe2 ) const
  42. {
  43. //
  44. // note: pe2's pid, occ, and wid can all be 0xffffffff in
  45. // the daemon, and wid for "this" can be 0xffffffff in cisvc.
  46. // This means we have to use ::Compare instead of subtraction.
  47. //
  48. Win4Assert ( 0 != this );
  49. Win4Assert ( 0 != pe2 );
  50. int cb2 = pe2->_cb;
  51. int cbMin = ( _cb <= cb2 ) ? _cb : cb2;
  52. int c = memcmp( GetKeyBuf(), pe2->GetKeyBuf(), cbMin );
  53. if ( 0 == c )
  54. {
  55. c = _cb - cb2;
  56. if ( 0 == c )
  57. {
  58. // strings are equal length and compare ok
  59. // pids are almost always contents, so check == first
  60. if ( _pid == pe2->_pid )
  61. {
  62. c = CompareULONG( _wid, pe2->_wid );
  63. if ( 0 == c )
  64. c = CompareULONG( _occ, pe2->_occ );
  65. }
  66. else
  67. return _pid > pe2->_pid ? 1 : -1;
  68. }
  69. }
  70. return c;
  71. }
  72. // increment taking into account variable size
  73. inline CEntry * Next () const;
  74. // Compression and decompression
  75. void SetWid ( WORKID wid )
  76. {
  77. Win4Assert( wid <= CI_MAX_DOCS_IN_WORDLIST ||
  78. wid == widInvalid );
  79. if ( widInvalid == wid )
  80. _wid = 0xff;
  81. else
  82. _wid = (BYTE) wid;
  83. }
  84. void SetPid ( PROPID pid ) { _pid = pid; }
  85. void SetOcc ( OCCURRENCE occ ) { _occ = occ; }
  86. void SetCount ( unsigned cb )
  87. {
  88. Win4Assert( cb <= 0xff );
  89. _cb = (BYTE)cb;
  90. }
  91. OCCURRENCE Occ() const { return _occ; }
  92. PROPID Pid() const { return _pid; }
  93. WORKID Wid() const
  94. {
  95. if ( 0xff == _wid )
  96. return widInvalid;
  97. return _wid;
  98. }
  99. unsigned Count() const { return _cb; }
  100. BYTE * GetKeyBuf() const { return (BYTE *)_key; }
  101. BOOL IsValue() const { return ( _key[0] != STRING_KEY ); }
  102. private:
  103. // We could compress _pid better.
  104. PROPID _pid;
  105. OCCURRENCE _occ;
  106. BYTE _wid; // fake wid <= 0x10
  107. BYTE _cb; // # of bytes in _key
  108. BYTE _key[1]; // variable size key
  109. };