-
Notifications
You must be signed in to change notification settings - Fork 23
semester_tasks #13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
semester_tasks #13
Changes from 23 commits
f0bd3c8
1d846ff
d3602f6
22ffad7
3709d12
e3e497c
75d57fa
0c36f3e
3fe4cd4
22d90b8
e1ce917
310e284
4eb21cb
c84a76b
e2f2f28
7a6280a
4f1a34d
4246f4b
8c0bdf5
faa6e67
d545794
d4966ea
6aa324c
474f6a6
158b669
e202e3d
b5c3636
8221b80
d861367
1d2d204
85afe6b
ad12812
0d34e44
b7cce0e
3bf6e15
e417c49
a1bdeff
1375f5d
c3f6de7
1ea4514
89105a3
238a5a3
a91e0b3
5deaffe
8bd78f8
cdb6dd5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,8 +14,6 @@ jobs: | |
|
|
||
| - uses: ZedThree/[email protected] | ||
| with: | ||
| apt_packages: libgtest-dev | ||
| clang_tidy_version: 18 | ||
| clang_tidy_checks: '-*,performance-*,bugprone-*,clang-analyzer-*,cppcoreguidelines-*,mpi-*,misc-*,-cppcoreguidelines-avoid-non-const-global-variables,-cppcoreguidelines-avoid-magic-numbers,-clang-diagnostic-error,-misc-no-recursion,-cppcoreguidelines-owning-memory,-bugprone-narrowing-conversions,-bugprone-easily-swappable-parameters,-misc-non-private-member-variables-in-classes,-cppcoreguidelines-pro-bounds-pointer-arithmetic,-cppcoreguidelines-special-member-functions,-cppcoreguidelines-init-variables,-misc-include-cleaner' | ||
| split_workflow: true | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,187 @@ | ||
| #pragma once | ||
|
|
||
| #include <algorithm> | ||
| #include <iostream> | ||
| #include <memory> | ||
| #include <set> | ||
| #include <vector> | ||
|
|
||
| /// @brief Graphs vertex | ||
| /// @tparam T | ||
| template <typename T> | ||
| struct Vertex { | ||
| Vertex(const T &d) : data(d) {} | ||
|
|
||
| T data; | ||
| std::set<std::shared_ptr<Vertex<T>>> adjacent; | ||
| }; | ||
|
|
||
| /// @brief Basic graph | ||
| /// @tparam T | ||
| template <typename T> | ||
| class Graph { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: constructor does not initialize these fields: vertices_ [cppcoreguidelines-pro-type-member-init] lib/src/graph.hpp:209: - std::vector<std::shared_ptr<VertexType>> vertices_;
+ std::vector<std::shared_ptr<VertexType>> vertices_{};There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: destructor of 'Graph' is public and non-virtual [cppcoreguidelines-virtual-class-destructor] class Graph {
^Additional contextlib/src/graph.hpp:27: make it public and virtual class Graph {
^ |
||
| public: | ||
| /** | ||
| * @brief | ||
| * Add a new vertex to the graph | ||
| * @param data | ||
| */ | ||
| void AddVertex(const T &data) { | ||
| vertices_.push_back(std::make_shared<Vertex<T>>(data)); | ||
| }; | ||
|
|
||
| std::shared_ptr<Vertex<T>> operator[](size_t index) { | ||
| return vertices_[index]; | ||
| } | ||
|
|
||
| const std::shared_ptr<Vertex<T>> operator[](size_t index) const { | ||
| return vertices_[index]; | ||
| } | ||
|
|
||
| /** | ||
| * @brief | ||
| * Find vertexes index | ||
| * @param vertex | ||
| * @return size_t | ||
| */ | ||
| size_t Find(const std::shared_ptr<Vertex<T>> &vertex) const { | ||
| return std::find(vertices_.begin(), vertices_.end(), vertex) - | ||
| vertices_.begin(); | ||
| }; | ||
|
|
||
| /** | ||
| * @brief | ||
| * Remove a vertex from the graph | ||
| * @param vertex | ||
| */ | ||
| void RemoveVertex(std::shared_ptr<Vertex<T>> vertex) { | ||
| // Find the vertex in the graph | ||
| auto it = std::find(vertices_.begin(), vertices_.end(), vertex); | ||
| if (it == vertices_.end()) { | ||
| // Vertex not found | ||
| return; | ||
| } | ||
|
|
||
| // Remove edges pointing to the vertex | ||
| for (auto &v : vertices_[it - vertices_.begin()]->adjacent) { | ||
| RemoveEdge(v, vertices_[it - vertices_.begin()]); | ||
| } | ||
| // Remove the vertex from the graph | ||
| vertices_.erase(it); | ||
| } | ||
|
|
||
| /** | ||
| * @brief | ||
| * Returns the number of vertices in the graph | ||
| * @return size_t | ||
| */ | ||
| size_t Size() const { return vertices_.size(); } | ||
|
|
||
| /** | ||
| * @brief | ||
| * Add a directed edge between two vertices via indices | ||
| * @param source_id | ||
| * @param target_id | ||
| */ | ||
| void AddDirEdge(size_t source_id, size_t target_id) { | ||
| operator[](source_id)->adjacent.insert(operator[](target_id)); | ||
| } | ||
|
|
||
| /** | ||
| * @brief | ||
| * Add a directed edge between two vertices | ||
| * @param source | ||
| * @param target | ||
| */ | ||
| void AddDirEdge(std::shared_ptr<Vertex<T>> source, | ||
| std::shared_ptr<Vertex<T>> target) { | ||
| source->adjacent.insert(target); | ||
| } | ||
|
|
||
| /** | ||
| * @brief | ||
| * Remove a directed edge between two vertices via indices | ||
| * @param source_id | ||
| * @param target_id | ||
| */ | ||
| void RemoveDirEdge(size_t source_id, size_t target_id) { | ||
| operator[](source_id)->adjacent.erase(*std::find( | ||
| operator[](source_id)->adjacent.begin(), | ||
| operator[](source_id)->adjacent.end(), operator[](target_id))); | ||
| } | ||
|
|
||
| /** | ||
| * @brief | ||
| * Remove a directed edge between two vertices | ||
| * @param source | ||
| * @param target | ||
| */ | ||
| void RemoveDirEdge(std::shared_ptr<Vertex<T>> source, | ||
| std::shared_ptr<Vertex<T>> target) { | ||
| source->adjacent.erase( | ||
| *std::find(source->adjacent.begin(), source->adjacent.end(), target)); | ||
| } | ||
|
|
||
| /** | ||
| * @brief | ||
| * Add a non-directed edge between two vertices via indices | ||
| * @param first_id | ||
| * @param second_id | ||
| */ | ||
| void AddEdge(size_t first_id, size_t second_id) { | ||
| AddDirEdge(first_id, second_id); | ||
| AddDirEdge(second_id, first_id); | ||
| } | ||
|
|
||
| /** | ||
| * @brief | ||
| * Add a non-directed edge between two vertices | ||
| * @param vertex_1 | ||
| * @param vertex_2 | ||
| */ | ||
| void AddEdge(std::shared_ptr<Vertex<T>> vertex_1, | ||
| std::shared_ptr<Vertex<T>> vertex_2) { | ||
| AddDirEdge(vertex_1, vertex_2); | ||
| AddDirEdge(vertex_2, vertex_1); | ||
| } | ||
|
|
||
| /** | ||
| * @brief | ||
| * Remove a non-directed edge between two vertices via indices | ||
| * @param first_id | ||
| * @param second_id | ||
| */ | ||
| void RemoveEdge(size_t first_id, size_t second_id) { | ||
| RemoveDirEdge(first_id, second_id); | ||
| RemoveDirEdge(second_id, first_id); | ||
| } | ||
|
|
||
| /** | ||
| * @brief | ||
| * Remove a non-directed edge between two vertices | ||
| * @param vertex_1 | ||
| * @param vertex_2 | ||
| */ | ||
| void RemoveEdge(std::shared_ptr<Vertex<T>> vertex_1, | ||
| std::shared_ptr<Vertex<T>> vertex_2) { | ||
| RemoveDirEdge(vertex_1, vertex_2); | ||
| RemoveDirEdge(vertex_2, vertex_1); | ||
| } | ||
|
|
||
| /** | ||
| * @brief | ||
| * Print the adjacency list of the graph | ||
| */ | ||
| void PrintGraph() const { | ||
| for (const auto &vertex : vertices_) { | ||
| std::cout << vertex->data << " -> "; | ||
| for (const auto &neighbor : vertex->adjacent) { | ||
| std::cout << neighbor->data << " "; | ||
| } | ||
| std::cout << std::endl; | ||
| } | ||
| } | ||
|
|
||
| protected: | ||
| std::vector<std::shared_ptr<Vertex<T>>> vertices_; | ||
|
||
| }; | ||
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| #include "utils.hpp" |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1 +1,23 @@ | ||||||||||||||||||||||||||
| int main() { return 0; } | ||||||||||||||||||||||||||
| #include "packman.hpp" | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| int main() { | ||||||||||||||||||||||||||
| DependencyGraph dg_1; | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| dg_1.AddVertex("Lib_1"); | ||||||||||||||||||||||||||
| dg_1.AddVertex("Lib_2"); | ||||||||||||||||||||||||||
| dg_1.AddVertex("Lib_3"); | ||||||||||||||||||||||||||
| dg_1.AddVertex("Lib_4"); | ||||||||||||||||||||||||||
| dg_1.AddVertex("Lib_5"); | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| dg_1.AddDirEdge(0, 1); | ||||||||||||||||||||||||||
| dg_1.AddDirEdge(0, 2); | ||||||||||||||||||||||||||
| dg_1.AddDirEdge(2, 3); | ||||||||||||||||||||||||||
| dg_1.AddDirEdge(3, 1); | ||||||||||||||||||||||||||
| dg_1.AddDirEdge(0, 3); | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| PackageManager packman_1(dg_1); | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
| PackageManager packman_1(dg_1); | |
| PackageManager const packman_1(dg_1); |
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
warning: variable 'packman_1' of type 'PackageManager' can be declared 'const' [misc-const-correctness]
| PackageManager packman_1(dg_1); | |
| PackageManager const packman_1(dg_1); |
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
warning: variable 'packman_1' of type 'PackageManager' can be declared 'const' [misc-const-correctness]
| PackageManager packman_1(dg_1); | |
| PackageManager const packman_1(dg_1); |
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
warning: variable 'packman_1' of type 'PackageManager' can be declared 'const' [misc-const-correctness]
| PackageManager packman_1(dg_1); | |
| PackageManager const packman_1(dg_1); |
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
warning: variable 'packman_1' of type 'PackageManager' can be declared 'const' [misc-const-correctness]
| PackageManager packman_1(dg_1); | |
| PackageManager const packman_1(dg_1); |
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
warning: variable 'packman_1' of type 'PackageManager' can be declared 'const' [misc-const-correctness]
| PackageManager packman_1(dg_1); | |
| PackageManager const packman_1(dg_1); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| #include "packman.hpp" | ||
|
|
||
| void PackageManager::FindingOrderStep( | ||
| std::shared_ptr<Vertex<std::string>> target) { | ||
| is_visited_[dependencies_.Find(target)] = true; | ||
|
|
||
| for (auto& neighbor : target->adjacent) { | ||
| if (!is_visited_[dependencies_.Find(neighbor)]) { | ||
| FindingOrderStep(neighbor); | ||
| } | ||
| } | ||
|
|
||
| reverse_order_.push(target->data); | ||
| } | ||
|
|
||
| std::vector<std::string> PackageManager::FindDownloadingOrder(/* | ||
| std::shared_ptr<Vertex<std::string>> target*/) { | ||
| is_visited_.resize(dependencies_.Size()); | ||
| for (size_t i = 0; i < is_visited_.size(); ++i) is_visited_[i] = false; | ||
|
|
||
| for (size_t i = 0; i < dependencies_.Size(); ++i) | ||
| if (!is_visited_[i]) FindingOrderStep(dependencies_[i]); | ||
|
|
||
| std::vector<std::string> order; | ||
|
|
||
| std::cout << "Downloading Order for " | ||
| << /*target->data <<*/ " is:" << std::endl; | ||
| while (reverse_order_.size() > 0) { | ||
| order.push_back(reverse_order_.top()); | ||
| std::cout << reverse_order_.top() << " "; | ||
| reverse_order_.pop(); | ||
| } | ||
| std::cout << std::endl; | ||
| return order; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| #include <stack> | ||
| #include <string> | ||
|
|
||
| #include "graph.hpp" | ||
|
|
||
| /// @brief Graph of dependencies between libraries | ||
| /// The "parent" libraries should be installed before thier children | ||
| class DependencyGraph : public Graph<std::string> {}; | ||
|
|
||
| /// @brief Packman basic algorithm | ||
| class PackageManager { | ||
| public: | ||
| PackageManager() = delete; | ||
| PackageManager(DependencyGraph& dep_graph) : dependencies_{dep_graph} {} | ||
|
|
||
| /** | ||
| * @brief | ||
| * Finds the right order to install libraries in | ||
| * with respect to dependencies | ||
| * @param target Needed library | ||
| * @return std::vector<std::string> | ||
| */ | ||
| std::vector<std::string> FindDownloadingOrder(/* | ||
| std::shared_ptr<Vertex<std::string>> target*/); | ||
|
|
||
| private: | ||
| void FindingOrderStep(std::shared_ptr<Vertex<std::string>> target); | ||
| DependencyGraph& dependencies_; | ||
| std::vector<bool> is_visited_; | ||
| std::stack<std::string> reverse_order_; | ||
| }; |
Uh oh!
There was an error while loading. Please reload this page.