From e36b3a20121ad237d4405a57e0499be5967f8768 Mon Sep 17 00:00:00 2001 From: Ian Roddis Date: Sat, 5 Jun 2021 19:56:40 -0300 Subject: [PATCH] checkpoint --- README.md | 10 ++--- daggy/include/daggy/DAG.hpp | 88 +++++++++++++++---------------------- 2 files changed, 39 insertions(+), 59 deletions(-) diff --git a/README.md b/README.md index 17fc663..23fac46 100644 --- a/README.md +++ b/README.md @@ -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 data ingestion / processing pipelines. - -Requirements -== - -- rapidjson - Building == @@ -24,3 +18,7 @@ cd build cmake .. make ``` + +Architecture +== + diff --git a/daggy/include/daggy/DAG.hpp b/daggy/include/daggy/DAG.hpp index b78cada..b46baf6 100644 --- a/daggy/include/daggy/DAG.hpp +++ b/daggy/include/daggy/DAG.hpp @@ -8,67 +8,49 @@ #include #include +/* + The DAG structure in daggy is just to ensure that tasks are run + in the correct dependent order. +*/ + namespace daggy { - template - class DAG { - public: - DAG() {} - void addVertex(T id); - void dropVertex(const T & id); + template + class DAG { + public: + DAG() {} - void addEdge(const T & src, const T & dst); - void dropEdge(const T & src, const T & dst); + // Vertices + 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} - std::deque shortestPath(const T & from, const T & to); + // Edges + 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 shortestPath(const T & from, const T & to); - // Traverse all nodes, calling f(id). If f() returns - // false, stop traversing this branch. - // Guarantees to only visit each vertex once. - void traverse(std::function f); + // Traversal + void initTraversal(std::vector ids = {}); + const T & visitNextVertex(); - // Same as traverse, but starts the traversal at - // the given id. - void traverseFrom(T& id, std::function f); + 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 parents; + std::unordered_set children; + bool visited; + }; - - // Peek at the next node - T & next() const; - - // 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 parents; - std::unordered_set children; - bool visited; - }; - - std::unordered_map vertices; - std::unordered_set roots; - }; + std::unordered_map vertices; + std::unordered_set roots; + std::unordered_set active_nodes; + }; #include "DAG.impl" }