X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/c2dbec8adf84cdd50fddeeb88f594d5ae9e9cdec..4ca85dfa6522596c3bf8c3d79f9c98629e06d4f4:/src/kernel/resource/profile/FutureEvtSet.cpp diff --git a/src/kernel/resource/profile/FutureEvtSet.cpp b/src/kernel/resource/profile/FutureEvtSet.cpp new file mode 100644 index 0000000000..59b0bdc94c --- /dev/null +++ b/src/kernel/resource/profile/FutureEvtSet.cpp @@ -0,0 +1,53 @@ +/* Copyright (c) 2004-2019. The SimGrid Team. All rights reserved. */ + +/* This program is free software; you can redistribute it and/or modify it + * under the terms of the license (GNU LGPL) which comes with this package. */ + +#include "src/kernel/resource/profile/FutureEvtSet.hpp" + +namespace simgrid { +namespace kernel { +namespace profile { + +FutureEvtSet::FutureEvtSet() = default; +FutureEvtSet::~FutureEvtSet() +{ + while (not heap_.empty()) { + delete heap_.top().second; + heap_.pop(); + } +} + +/** @brief Schedules an event to a future date */ +void FutureEvtSet::add_event(double date, Event* evt) +{ + heap_.emplace(date, evt); +} + +/** @brief returns the date of the next occurring event (or -1 if empty) */ +double FutureEvtSet::next_date() const +{ + return heap_.empty() ? -1.0 : heap_.top().first; +} + +/** @brief Retrieves the next occurring event, or nullptr if none happens before date */ +Event* FutureEvtSet::pop_leq(double date, double* value, resource::Resource** resource) +{ + double event_date = next_date(); + if (event_date > date || heap_.empty()) + return nullptr; + + Event* event = heap_.top().second; + Profile* profile = event->profile; + DatedValue dateVal = profile->next(event); + + *resource = event->resource; + *value = dateVal.value_; + + heap_.pop(); + + return event; +} +} // namespace profile +} // namespace kernel +} // namespace simgrid \ No newline at end of file