Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Convert EventSet into class from typedef
authorMaxwell Pirtle <maxwellpirtle@gmail.com>
Mon, 6 Feb 2023 08:37:54 +0000 (09:37 +0100)
committerMaxwell Pirtle <maxwellpirtle@gmail.com>
Mon, 20 Feb 2023 09:43:52 +0000 (10:43 +0100)
The EventSet object was simply typedef-ed to
a std::deque<UnfoldingEvent *>. While this
worked, it caused a lot of the code in tiny-simgrid
to be a bit more difficult to read since it
required the use of a more C-like idiom of passing
`this` as an explicit argument in EvtSetTools.

Effectively, the idea to absorb all of the EvtSetTools
methods into the EventSet class directly. This will
give a more natural C++ (instead of C) look to the
resulting code in the UDPOR algorithm

src/mc/udpor_global.cpp
src/mc/udpor_global.hpp

index be3726b..b1bfb05 100644 (file)
@@ -11,23 +11,6 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(mc_udpor_global, mc, "udpor_global");
 
 namespace simgrid::mc {
 
-EventSet EvtSetTools::makeUnion(const EventSet& s1, const EventSet& s2)
-{
-  EventSet res = s1;
-  for (auto evt : s2)
-    EvtSetTools::pushBack(res, evt);
-  return res;
-}
-
-void EvtSetTools::pushBack(EventSet& events, UnfoldingEvent* e)
-{
-  if (not EvtSetTools::contains(events, e))
-    events.push_back(e);
-}
-
-bool EvtSetTools::contains(const EventSet& events, const UnfoldingEvent* e)
-{
-  return std::any_of(events.begin(), events.end(), [e](const UnfoldingEvent* evt) { return *evt == *e; });
-}
+// TODO: Implement methods on EventSet as appropriate
 
 } // namespace simgrid::mc
index 1b3e90e..154c9ba 100644 (file)
@@ -8,6 +8,7 @@
 
 #include <iostream>
 #include <queue>
+#include <set>
 #include <string_view>
 
 /* TODO: many method declared in this module are not implemented */
 namespace simgrid::mc {
 
 class UnfoldingEvent;
-using EventSet = std::deque<UnfoldingEvent*>;
+class Configuration;
+
+class EventSet {
+private:
+  std::set<UnfoldingEvent*> events_;
 
-class EvtSetTools {
 public:
-  static bool contains(const EventSet& events, const UnfoldingEvent* e);
-  static UnfoldingEvent* find(const EventSet& events, const UnfoldingEvent* e);
-  static void subtract(EventSet& events, EventSet const& otherSet);
-  static bool depends(const EventSet& events, const EventSet& otherSet);
-  static bool isEmptyIntersection(EventSet evtS1, EventSet evtS2);
-  static EventSet makeUnion(const EventSet& s1, const EventSet& s2);
-  static void pushBack(EventSet& events, UnfoldingEvent* e);
-  static void remove(EventSet& events, UnfoldingEvent* e);
-  static EventSet minus(EventSet events, UnfoldingEvent* e);
-  static EventSet plus(EventSet events, UnfoldingEvent* e);
+  EventSet()                           = default;
+  EventSet(const EventSet&)            = default;
+  EventSet& operator=(EventSet const&) = default;
+  EventSet(EventSet&&)                 = default;
+
+  void remove(UnfoldingEvent* e);
+  void subtract(const EventSet& other);
+  EventSet subtracting(const EventSet& e);
+  EventSet subtracting(const UnfoldingEvent* e);
+
+  void insert(UnfoldingEvent* e);
+  void form_union(const EventSet&);
+  EventSet make_union(const EventSet&) const;
+  EventSet make_union(const UnfoldingEvent* e) const;
+
+  bool contains(const UnfoldingEvent* e) const;
+
+  // TODO: What is this used for?
+  UnfoldingEvent* find(const UnfoldingEvent* e) const;
+
+  // TODO: What is this used for
+  bool depends(const EventSet& other) const;
+
+  // TODO: What is this used for
+  bool is_empty_intersection(EventSet evtS) const;
 };
 
 struct s_evset_in_t {
@@ -39,29 +58,31 @@ struct s_evset_in_t {
 
 class Configuration {
 public:
+  Configuration()                                = default;
+  Configuration(const Configuration&)            = default;
+  Configuration& operator=(Configuration const&) = default;
+  Configuration(Configuration&&)                 = default;
+
   EventSet events_;
   EventSet maxEvent;         // Events recently added to events_
   EventSet actorMaxEvent;    // maximal events of the actors in current configuration
   UnfoldingEvent* lastEvent; // The last added event
 
   Configuration plus_config(UnfoldingEvent*) const;
+
   void createEvts(Configuration C, EventSet& result, const std::string& trans_tag, s_evset_in_t ev_sets, bool chk,
                   UnfoldingEvent* immPreEvt);
+
   void updateMaxEvent(UnfoldingEvent*);         // update maximal events of the configuration and actors
   UnfoldingEvent* findActorMaxEvt(int actorId); // find maximal event of a Actor whose id = actorId
 
   UnfoldingEvent* findTestedComm(const UnfoldingEvent* testEvt); // find comm tested by action testTrans
-
-  Configuration()                     = default;
-  Configuration(const Configuration&) = default;
-  Configuration& operator=(Configuration const&) = default;
-  Configuration(Configuration&&)                 = default;
 };
 
 class UnfoldingEvent {
 public:
   UnfoldingEvent(unsigned int nb_events, std::string const& trans_tag, EventSet const& causes, int sid = -1);
-  UnfoldingEvent(const UnfoldingEvent&) = default;
+  UnfoldingEvent(const UnfoldingEvent&)            = default;
   UnfoldingEvent& operator=(UnfoldingEvent const&) = default;
   UnfoldingEvent(UnfoldingEvent&&)                 = default;