Files
Raptor/src/PIM/Dialect/Spatial/DCPGraph/Task.cpp
NiccoloN 9e0d31af50
All checks were successful
Validate Operations / validate-operations (push) Successful in 18m22s
automatic code-reformat
2026-04-09 14:27:23 +02:00

48 lines
1.4 KiB
C++

#include <optional>
#include "Graph.hpp"
#include "Task.hpp"
#include "Uniqueworklist.hpp"
std::optional<Edge_t> TaskDCP::addChild(TaskDCP* child, Weight_t weight) {
std::optional<Edge_t> oldEdge = std::nullopt;
auto founded_element =
std::find_if(childs.begin(), childs.end(), [child](Edge_t element) { return child == element.first; });
if (founded_element != childs.end()) {
oldEdge = *founded_element;
fastRemove(childs, founded_element);
}
childs.emplace_back(child, weight);
return oldEdge;
}
std::optional<Edge_t> TaskDCP::addParent(TaskDCP* parent, Weight_t weight) {
std::optional<Edge_t> oldEdge = std::nullopt;
auto founded_element =
std::find_if(parents.begin(), parents.end(), [parent](Edge_t element) { return parent == element.first; });
if (founded_element != parents.end()) {
oldEdge = *founded_element;
fastRemove(parents, founded_element);
}
parents.emplace_back(parent, weight);
return oldEdge;
}
bool TaskDCP::hasDescendent(TaskDCP* child) {
UniqueWorkList<std::vector<TaskDCP*>> worklist;
worklist.reserve(32);
worklist.push_back(this);
while (!worklist.empty()) {
TaskDCP* task = worklist.back();
worklist.pop_back();
if (task == child)
return true;
for (auto c : task->childs)
worklist.push_back(c.first);
}
return false;
}
// TODO fare qualcosa di sensato
int TaskDCP::computeWeight(GraphDCP* graph, CPU cpu) { return orig_weight; }