Skip to content

Commit 53b9961

Browse files
committed
Add API to remove nodes from CXXGraph by id
Issue: ZigRazor#419
1 parent 11e80f2 commit 53b9961

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

include/CXXGraph/Node/Node_decl.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ class Node {
4949
const std::string &getUserId() const;
5050
const T &getData() const;
5151
void setData(T &&new_data);
52+
5253
// operator
5354
bool operator==(const Node<T> &b) const;
5455
bool operator<(const Node<T> &b) const;

include/CXXGraph/Node/Node_impl.hpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,18 @@ void Node<T>::setData(T &&new_data) {
7070
this->data = std::move(new_data);
7171
}
7272

73+
bool deleteNodeById(const std::string &id) {
74+
auto it = std::find_if(nodes.begin(), nodes.end(), [&](const auto &pair) {
75+
return pair.second.getUserId() == id;
76+
});
77+
78+
if (it != nodes.end()) {
79+
nodes.erase(it);
80+
return true; // Node deleted successfully
81+
}
82+
return false; // Node not found
83+
}
84+
7385
// The data type T must have an overload of the equality operator
7486
template <typename T>
7587
bool Node<T>::operator==(const Node<T> &b) const {

0 commit comments

Comments
 (0)