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.

181 lines
4.9 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1991 - 1992.
  5. //
  6. // File: SET.CXX
  7. //
  8. // Contents: Bit set
  9. //
  10. // Classes: CSimpleSet, CSet
  11. //
  12. // History: 01-Nov-91 BartoszM Created.
  13. //
  14. //----------------------------------------------------------------------------
  15. #include <pch.cxx>
  16. #pragma hdrstop
  17. #include "set.hxx"
  18. //
  19. // CSimpleSet
  20. //
  21. //
  22. // LowestBit [x] = position of lowest bit in byte x
  23. // EOS if set exhaused.
  24. //
  25. #define EMPTY 16
  26. // 0 1 2 3 4 5 6 7 8 9 a b c d e f
  27. static const char LowestBit[] = {
  28. EMPTY, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,
  29. 4, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,
  30. 5, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,
  31. 4, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,
  32. 6, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,
  33. 4, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,
  34. 5, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,
  35. 4, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,
  36. 7, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,
  37. 4, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,
  38. 5, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,
  39. 4, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,
  40. 6, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,
  41. 4, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,
  42. 5, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,
  43. 4, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0
  44. };
  45. //+---------------------------------------------------------------------------
  46. //
  47. // Member: CSimpleSet::FirstElement, public
  48. //
  49. // Synopsis: Returns the first element in the set
  50. //
  51. // History: 01-Nov-91 BartoszM Created.
  52. //
  53. //----------------------------------------------------------------------------
  54. int CSimpleSet::FirstElement() const
  55. {
  56. unsigned char* pb = (unsigned char*) &_bitset;
  57. for ( unsigned i = 0; i < sizeof ( set_t ); i++ )
  58. {
  59. if ( pb[i] != 0 )
  60. return LowestBit [ pb[i] ] + i * 8;
  61. }
  62. return EOS;
  63. }
  64. //
  65. // CSet
  66. //
  67. //+---------------------------------------------------------------------------
  68. //
  69. // Member: CSet::CSet, public
  70. //
  71. // Synopsis: Copy constructor
  72. //
  73. // Arguments: [s] -- source set
  74. //
  75. // History: 01-Nov-91 BartoszM Created.
  76. //
  77. //----------------------------------------------------------------------------
  78. CSet::CSet ( CSet& s )
  79. {
  80. memcpy ( _aSimpleSet, s._aSimpleSet, sizeof _aSimpleSet );
  81. }
  82. //+---------------------------------------------------------------------------
  83. //
  84. // Member: CSet:operator=, public
  85. //
  86. // History: 01-Nov-91 BartoszM Created.
  87. //
  88. //----------------------------------------------------------------------------
  89. CSet& CSet::operator= ( CSet& s )
  90. {
  91. memcpy ( _aSimpleSet, s._aSimpleSet, sizeof _aSimpleSet );
  92. return *this;
  93. }
  94. //+---------------------------------------------------------------------------
  95. //
  96. // Member: CSet::IsEmpty, public
  97. //
  98. // Synopsis: Checks if the set is empty
  99. //
  100. // History: 01-Nov-91 BartoszM Created.
  101. //
  102. //----------------------------------------------------------------------------
  103. BOOL CSet::IsEmpty() const
  104. {
  105. for ( int i = 0; i < SET_ENTRIES; i++ )
  106. {
  107. if ( ! _aSimpleSet[i].IsEmpty() )
  108. return FALSE;
  109. }
  110. return TRUE;
  111. }
  112. //+---------------------------------------------------------------------------
  113. //
  114. // Member: CSet::FirstElement, public
  115. //
  116. // Synopsis: Returns the first element
  117. //
  118. // History: 01-Nov-91 BartoszM Created.
  119. //
  120. //----------------------------------------------------------------------------
  121. int CSet::FirstElement() const
  122. {
  123. int i = 0;
  124. while ( _aSimpleSet[i].IsEmpty() )
  125. {
  126. if ( ++i == SET_ENTRIES )
  127. return EOS;
  128. }
  129. return i * SIMPLE_SET_SIZE + _aSimpleSet[i].FirstElement();
  130. }
  131. //+---------------------------------------------------------------------------
  132. //
  133. // Member: CSet::Clear, public
  134. //
  135. // Synopsis: Removes all elements from set
  136. //
  137. // History: 01-Nov-91 BartoszM Created.
  138. //
  139. //----------------------------------------------------------------------------
  140. void CSet::Clear()
  141. {
  142. for ( int i = 0; i < SET_ENTRIES; i++ )
  143. _aSimpleSet[i].Clear();
  144. }
  145. //+---------------------------------------------------------------------------
  146. //
  147. // Member: CSet::Fill, public
  148. //
  149. // Synopsis: Fill the set
  150. //
  151. // History: 01-Nov-91 BartoszM Created.
  152. //
  153. //----------------------------------------------------------------------------
  154. void CSet::Fill()
  155. {
  156. for ( int i = 0; i < SET_ENTRIES; i++ )
  157. _aSimpleSet[i].Fill();
  158. }