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.

109 lines
2.8 KiB

  1. //
  2. // MODULE: NODESTATE.CPP
  3. //
  4. // PURPOSE: Implement some functions relevant to CNodeState
  5. //
  6. // PROJECT: Generic Troubleshooter DLL for Microsoft AnswerPoint
  7. //
  8. // COMPANY: Saltmine Creative, Inc. (206)-284-7511 [email protected]
  9. //
  10. // AUTHOR: Joe Mabel
  11. //
  12. // ORIGINAL DATE: 10/99
  13. //
  14. // NOTES:
  15. // 1.
  16. //
  17. // Version Date By Comments
  18. //--------------------------------------------------------------------
  19. // V3.0 10/15/99 JM original
  20. //
  21. #include "nodestate.h"
  22. #include <algorithm>
  23. // operator-= removes only identical node/state pairs.
  24. // This is the appropriate behavior if lhs represents all current node states and rhs
  25. // represents sniffed values: if the node already deviates from a sniffed value, and
  26. // we are removing sniffed values, this sniffed value is irrelevant & shouldn't be
  27. // removed from lhs.
  28. // this is an N-squared algorithm.
  29. // >>> $MAINT There might be a case for working with sorted lists and STL generic
  30. // algorithms, which could reduce this to N log N
  31. CBasisForInference& operator-=(CBasisForInference& lhs, const CBasisForInference& rhs)
  32. {
  33. CBasisForInference::iterator i = lhs.begin();
  34. while ( i != lhs.end() )
  35. {
  36. NID inid = i->nid();
  37. IST istate = i->state();
  38. bool bMatch = false;
  39. for (CBasisForInference::const_iterator j = rhs.begin(); j != rhs.end(); ++j)
  40. {
  41. if (j->nid() == inid && j->state() == istate)
  42. {
  43. bMatch = true;
  44. break;
  45. }
  46. }
  47. if (bMatch)
  48. i = lhs.erase(i);
  49. else
  50. ++i;
  51. }
  52. return lhs;
  53. }
  54. // operator+= adds only pairs for which there is no match to any node already in lhs.
  55. // This is the appropriate behavior if lhs represents node states obtained by means other
  56. // than sniffing and rhs represents re-sniffed values: if the node already has a value
  57. // assigned by other means, the sniffed values are irrelevant & shouldn't be
  58. // added to lhs.
  59. // this is an N-squared algorithm.
  60. // >>> $MAINT There might be a case for working with sorted lists and STL generic
  61. // algorithms, which could reduce this to N log N
  62. CBasisForInference& operator+=(CBasisForInference& lhs, const CBasisForInference& rhs)
  63. {
  64. for (CBasisForInference::const_iterator j = rhs.begin(); j != rhs.end(); ++j)
  65. {
  66. NID jnid = j->nid();
  67. bool bMatch = false;
  68. for (CBasisForInference::const_iterator i = lhs.begin(); i != lhs.end(); ++i)
  69. {
  70. if (i->nid() == jnid)
  71. {
  72. bMatch = true;
  73. break;
  74. }
  75. }
  76. if (!bMatch)
  77. lhs.push_back(*j);
  78. }
  79. return lhs;
  80. }
  81. vector<NID>& operator-=(vector<NID>& lhs, const CBasisForInference& rhs)
  82. {
  83. for (long i = 0; i < rhs.size(); i++)
  84. {
  85. vector<NID>::iterator found = find(lhs.begin(), lhs.end(), rhs[i].nid());
  86. if (found < lhs.end())
  87. lhs.erase(found);
  88. }
  89. return lhs;
  90. }
  91. vector<NID>& operator+=(vector<NID>& lhs, const CBasisForInference& rhs)
  92. {
  93. for (long i = 0; i < rhs.size(); i++)
  94. lhs.push_back(rhs[i].nid());
  95. return lhs;
  96. }