Counter Strike : Global Offensive Source Code
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.

91 lines
3.4 KiB

  1. //===--- DeltaAlgorithm.h - A Set Minimization Algorithm -------*- C++ -*--===//
  2. //
  3. // The LLVM Compiler Infrastructure
  4. //
  5. // This file is distributed under the University of Illinois Open Source
  6. // License. See LICENSE.TXT for details.
  7. //===----------------------------------------------------------------------===//
  8. #ifndef LLVM_ADT_DELTAALGORITHM_H
  9. #define LLVM_ADT_DELTAALGORITHM_H
  10. #include <set>
  11. #include <vector>
  12. namespace llvm {
  13. /// DeltaAlgorithm - Implements the delta debugging algorithm (A. Zeller '99)
  14. /// for minimizing arbitrary sets using a predicate function.
  15. ///
  16. /// The result of the algorithm is a subset of the input change set which is
  17. /// guaranteed to satisfy the predicate, assuming that the input set did. For
  18. /// well formed predicates, the result set is guaranteed to be such that
  19. /// removing any single element would falsify the predicate.
  20. ///
  21. /// For best results the predicate function *should* (but need not) satisfy
  22. /// certain properties, in particular:
  23. /// (1) The predicate should return false on an empty set and true on the full
  24. /// set.
  25. /// (2) If the predicate returns true for a set of changes, it should return
  26. /// true for all supersets of that set.
  27. ///
  28. /// It is not an error to provide a predicate that does not satisfy these
  29. /// requirements, and the algorithm will generally produce reasonable
  30. /// results. However, it may run substantially more tests than with a good
  31. /// predicate.
  32. class DeltaAlgorithm {
  33. public:
  34. typedef unsigned change_ty;
  35. // FIXME: Use a decent data structure.
  36. typedef std::set<change_ty> changeset_ty;
  37. typedef std::vector<changeset_ty> changesetlist_ty;
  38. private:
  39. /// Cache of failed test results. Successful test results are never cached
  40. /// since we always reduce following a success.
  41. std::set<changeset_ty> FailedTestsCache;
  42. /// GetTestResult - Get the test result for the \p Changes from the
  43. /// cache, executing the test if necessary.
  44. ///
  45. /// \param Changes - The change set to test.
  46. /// \return - The test result.
  47. bool GetTestResult(const changeset_ty &Changes);
  48. /// Split - Partition a set of changes \p S into one or two subsets.
  49. void Split(const changeset_ty &S, changesetlist_ty &Res);
  50. /// Delta - Minimize a set of \p Changes which has been partioned into
  51. /// smaller sets, by attempting to remove individual subsets.
  52. changeset_ty Delta(const changeset_ty &Changes,
  53. const changesetlist_ty &Sets);
  54. /// Search - Search for a subset (or subsets) in \p Sets which can be
  55. /// removed from \p Changes while still satisfying the predicate.
  56. ///
  57. /// \param Res - On success, a subset of Changes which satisfies the
  58. /// predicate.
  59. /// \return - True on success.
  60. bool Search(const changeset_ty &Changes, const changesetlist_ty &Sets,
  61. changeset_ty &Res);
  62. protected:
  63. /// UpdatedSearchState - Callback used when the search state changes.
  64. virtual void UpdatedSearchState(const changeset_ty &Changes,
  65. const changesetlist_ty &Sets) {}
  66. /// ExecuteOneTest - Execute a single test predicate on the change set \p S.
  67. virtual bool ExecuteOneTest(const changeset_ty &S) = 0;
  68. public:
  69. virtual ~DeltaAlgorithm();
  70. /// Run - Minimize the set \p Changes by executing \see ExecuteOneTest() on
  71. /// subsets of changes and returning the smallest set which still satisfies
  72. /// the test predicate.
  73. changeset_ty Run(const changeset_ty &Changes);
  74. };
  75. } // end namespace llvm
  76. #endif