-
Notifications
You must be signed in to change notification settings - Fork 115
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
Issue: #419, Issue: #238, and Issue: #240 #422
base: master
Are you sure you want to change the base?
Conversation
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.
Please resolve the comment and we can merge it. Good Work, just some details to adjust!
std::unordered_map<CXXGraph::id_t, std::unordered_map<CXXGraph::id_t, int>> capacities; | ||
std::unordered_map<CXXGraph::id_t, std::unordered_map<CXXGraph::id_t, int>> flow; | ||
|
||
bool bfs(const CXXGraph::id_t& source, const CXXGraph::id_t& sink, std::unordered_map<CXXGraph::id_t, int>& distance) { |
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.
Why adding a new bfs implementation? can you use the provided one?
return distance[sink] != -1; | ||
} | ||
|
||
int dfs(const CXXGraph::id_t& current, const CXXGraph::id_t& sink, int flow_value, std::unordered_map<CXXGraph::id_t, int>& distance) { |
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.
Why adding a new dfs implementation? can you use the provided one?
template <typename T> | ||
class Graph { | ||
private: | ||
std::unordered_map<CXXGraph::id_t, Node<T>> nodes; |
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.
These should not be a class variable, reduce the scope of the variable to the minimum required
template <typename T> | ||
class Graph { | ||
private: | ||
std::unordered_map<CXXGraph::id_t, Node<T>> nodes; |
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.
in Graph_decl.h
we already have the node set and the adjiacency matrix, you should use them
// Other graph methods... | ||
|
||
// Function to add an edge between two nodes | ||
void addEdge(const std::string& from_id, const std::string& to_id) { |
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.
this function is a repetition of the already implemented function in Graph_impl.hpp
, you should use it
std::unordered_map<CXXGraph::id_t, std::unordered_map<CXXGraph::id_t, int>> capacities; | ||
std::unordered_map<CXXGraph::id_t, std::unordered_map<CXXGraph::id_t, int>> flow; | ||
|
||
bool bfs(const CXXGraph::id_t& source, const CXXGraph::id_t& sink, std::unordered_map<CXXGraph::id_t, int>& distance) { |
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.
Thanks for implementing bfs
and dfs
(and Dinic's!).
These actually seem generally useful. Should we consider making them public? (assuming the storage requirement would need to change given the above comment).
std::unordered_map<CXXGraph::id_t, std::unordered_map<CXXGraph::id_t, int>> capacities; | ||
std::unordered_map<CXXGraph::id_t, std::unordered_map<CXXGraph::id_t, int>> flow; |
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.
Note that this adds more storage to the graph, which makes it a larger object/heavier. Thoughts on this @sbaldu, @ZigRazor? Perhaps the relevant storage of the algorithm should be extracted elsewhere (and possibly the algorithm implementation itself) so that this storage is temporary.
There are other options, such as lazy storage creation on the heap the first time a dfs, bfs, or Dinic's is called. Although the storage for std::unordered_map
isn't wild - I do like keeping Graph
as lightweight as can possibly be done.
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.
I Agree!
bool deleteNodeById(const std::string &id) { | ||
auto it = std::find_if(nodes.begin(), nodes.end(), [&](const auto &pair) { | ||
return pair.second.getUserId() == id; | ||
}); | ||
|
||
if (it != nodes.end()) { | ||
nodes.erase(it); | ||
return true; // Node deleted successfully | ||
} | ||
return false; // Node not found | ||
} |
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.
💯 🙏
Another things, can you add tests for your algorithm implementation and for the node search by ID? |
My comments largely reflect @ZigRazor's comments, so mine can be ignored. |
bool deleteNodeById(const std::string &id) { | ||
auto it = std::find_if(nodes.begin(), nodes.end(), [&](const auto &pair) { | ||
return pair.second.getUserId() == id; | ||
}); |
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.
Need to include algorithm
in order to use std::find_if
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.
YES
template <typename T> | ||
class Graph { | ||
private: | ||
std::unordered_map<CXXGraph::id_t, Node<T>> nodes; | ||
std::unordered_map<CXXGraph::id_t, std::unordered_map<CXXGraph::id_t, int>> capacities; | ||
std::unordered_map<CXXGraph::id_t, std::unordered_map<CXXGraph::id_t, int>> flow; |
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.
Also, why is he re-declaring the Graph class? Shouldn't he simply add the declaration of the method in Graph_decl.hpp
and add a header for the implementation of the single method?
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.
I Agree!
#419
-Implemented the deleteNodeById function in the Graph class to delete a node by its ID.
-Utilized a lambda function with std::find_if to search for the node with the provided ID within the unordered map of nodes.
-If the node is found, it is erased from the map using nodes.erase(it).
-Returns true if the node is successfully deleted and false if the node is not found.
#238
#240
kragersAlgorithm
method to the Graph class.