Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Use std::unordered_set instead of std::set for EventSet
authorMaxwell Pirtle <maxwellpirtle@gmail.com>
Tue, 14 Feb 2023 14:04:40 +0000 (15:04 +0100)
committerMaxwell Pirtle <maxwellpirtle@gmail.com>
Mon, 20 Feb 2023 09:43:53 +0000 (10:43 +0100)
The ordering of the events in the set does not
matter in an EventSet. The std::unordered_set construct
is thus a better fit (std::set orders its elements).
While this disallows the use of the nice functions
in the standard library for forming unions etc.,
it is trivial to implement the functions `make_union()`
etc.

src/mc/explo/UdporChecker.cpp
src/mc/explo/udpor/EventSet.cpp
src/mc/explo/udpor/EventSet.hpp

index df1b429..48b2a01 100644 (file)
@@ -133,7 +133,7 @@ State& UdporChecker::get_state_referenced_by(const UnfoldingEvent& event)
   const auto wrapped_state = this->state_manager_.get_state(state_id);
   xbt_assert(wrapped_state != std::nullopt,
              "\n\n****** INVARIANT VIOLATION ******\n"
-             "To each UDPOR event corresponds a state, but state %lu does not exist. "
+             "To each UDPOR event corresponds a state, but state %llu does not exist. "
              "Please report this as a bug.\n"
              "*********************************\n\n",
              state_id);
index f67882b..d6431f9 100644 (file)
@@ -5,7 +5,6 @@
 
 #include "src/mc/explo/udpor/EventSet.hpp"
 
-#include <algorithm>
 #include <iterator>
 
 namespace simgrid::mc::udpor {
@@ -22,9 +21,11 @@ void EventSet::subtract(const EventSet& other)
 
 EventSet EventSet::subtracting(const EventSet& other) const
 {
-  std::set<UnfoldingEvent*> result;
-  std::set_difference(this->events_.begin(), this->events_.end(), other.events_.begin(), other.events_.end(),
-                      std::inserter(result, result.end()));
+  std::unordered_set<UnfoldingEvent*> result = this->events_;
+
+  for (UnfoldingEvent* e : other.events_)
+    result.erase(e);
+
   return EventSet(std::move(result));
 }
 
@@ -55,9 +56,11 @@ EventSet EventSet::make_union(UnfoldingEvent* e) const
 
 EventSet EventSet::make_union(const EventSet& other) const
 {
-  std::set<UnfoldingEvent*> result;
-  std::set_union(this->events_.begin(), this->events_.end(), other.events_.begin(), other.events_.end(),
-                 std::inserter(result, result.end()));
+  std::unordered_set<UnfoldingEvent*> result = this->events_;
+
+  for (UnfoldingEvent* e : other.events_)
+    result.insert(e);
+
   return EventSet(std::move(result));
 }
 
index 9d687f9..66dc8a5 100644 (file)
@@ -9,14 +9,14 @@
 #include "src/mc/explo/udpor/udpor_forward.hpp"
 
 #include <cstddef>
-#include <set>
+#include <unordered_set>
 
 namespace simgrid::mc::udpor {
 
 class EventSet {
 private:
-  std::set<UnfoldingEvent*> events_;
-  explicit EventSet(std::set<UnfoldingEvent*>&& raw_events) : events_(raw_events) {}
+  std::unordered_set<UnfoldingEvent*> events_;
+  explicit EventSet(std::unordered_set<UnfoldingEvent*>&& raw_events) : events_(raw_events) {}
 
 public:
   EventSet()                           = default;