checkpoint

This commit is contained in:
Ian Roddis
2021-06-05 19:56:40 -03:00
parent 43cd8b46be
commit e36b3a2012
2 changed files with 39 additions and 59 deletions

View File

@@ -7,12 +7,6 @@ Daggy is a work orchestration framework for running workflows modeled as
directed, acyclic graphs (DAGs). These are quite useful when modeling directed, acyclic graphs (DAGs). These are quite useful when modeling
data ingestion / processing pipelines. data ingestion / processing pipelines.
Requirements
==
- rapidjson
Building Building
== ==
@@ -24,3 +18,7 @@ cd build
cmake .. cmake ..
make make
``` ```
Architecture
==

View File

@@ -8,67 +8,49 @@
#include <iterator> #include <iterator>
#include <functional> #include <functional>
/*
The DAG structure in daggy is just to ensure that tasks are run
in the correct dependent order.
*/
namespace daggy { namespace daggy {
template<typename T>
class DAG {
public:
DAG() {}
void addVertex(T id); template<typename T>
void dropVertex(const T & id); class DAG {
public:
DAG() {}
void addEdge(const T & src, const T & dst); // Vertices
void dropEdge(const T & src, const T & dst); void addVertex(T id);
void dropVertex(const T & id);
void setVertexVisited(const T & id, bool visited);
void setDAGVisited(bool visited);
// Returns the path from {from} to {to} // Edges
std::deque<T> shortestPath(const T & from, const T & to); void addEdge(const T & src, const T & dst);
void dropEdge(const T & src, const T & dst);
// Traversal // Returns the path from {from} to {to}
std::deque<T> shortestPath(const T & from, const T & to);
// Traverse all nodes, calling f(id). If f() returns // Traversal
// false, stop traversing this branch. void initTraversal(std::vector<const T&> ids = {});
// Guarantees to only visit each vertex once. const T & visitNextVertex();
void traverse(std::function<bool> f);
// Same as traverse, but starts the traversal at private:
// the given id. struct Vertex {
void traverseFrom(T& id, std::function<bool> f); // It's a bit redundant to preserve both, but
// it makes it possible with and against the
// directions possible
std::unordered_set<T> parents;
std::unordered_set<T> children;
bool visited;
};
std::unordered_map<T, Vertex> vertices;
// Peek at the next node std::unordered_set<T> roots;
T & next() const; std::unordered_set<T> active_nodes;
};
// Get the next node and mark it visited
T & visit_next();
// Clear the visited flag, optionally for downstream
// vertices
void unvisit(T &id, bool cascade = true);
// Breadth First Iterator
struct Iterator {
using iterator_category = std::random_access_iterator_tag;
using difference_type = int;
using value_type = T;
using point = T*;
using reference = T&;
};
private:
struct Vertex {
// It's a bit redundant to preserve both, but
// it makes it possible with and against the
// directions possible
std::unordered_set<T> parents;
std::unordered_set<T> children;
bool visited;
};
std::unordered_map<T, Vertex> vertices;
std::unordered_set<T> roots;
};
#include "DAG.impl" #include "DAG.impl"
} }