@@ -481,10 +481,13 @@ void Graph<T>::setNodeData(std::map<std::string, T> &dataMap) {
481481template <typename T>
482482const std::optional<shared<const Edge<T>>> Graph<T>::getEdge(
483483 const std::string &edgeUserId) const {
484- for (const auto &it : edgeSet) {
485- if (it->getUserId () == edgeUserId) {
486- return it;
487- }
484+ const auto &edgeSet = this ->getEdgeSet ();
485+ auto it = std::find_if (edgeSet.begin (), edgeSet.end (),
486+ [&edgeUserId](const auto &edge) {
487+ return edge->getUserId () == edgeUserId;
488+ });
489+ if (it != edgeSet.end ()) {
490+ return *it;
488491 }
489492
490493 return std::nullopt ;
@@ -493,10 +496,12 @@ const std::optional<shared<const Edge<T>>> Graph<T>::getEdge(
493496template <typename T>
494497const std::optional<shared<const Edge<T>>> Graph<T>::getEdge(
495498 const CXXGraph::id_t edgeId) const {
496- for (const auto &it : edgeSet) {
497- if (it->getId () == edgeId) {
498- return it;
499- }
499+ const auto &edgeSet = this ->getEdgeSet ();
500+ auto it = std::find_if (
501+ edgeSet.begin (), edgeSet.end (),
502+ [edgeId](const auto &edge) { return edge->getId () == edgeId; });
503+ if (it != edgeSet.end ()) {
504+ return *it;
500505 }
501506
502507 return std::nullopt ;
@@ -505,10 +510,13 @@ const std::optional<shared<const Edge<T>>> Graph<T>::getEdge(
505510template <typename T>
506511const std::optional<shared<const Node<T>>> Graph<T>::getNode(
507512 const std::string &nodeUserId) const {
508- for (const auto &it : getNodeSet ()) {
509- if (it->getUserId () == nodeUserId) {
510- return it;
511- }
513+ const auto &nodeSet = this ->getNodeSet ();
514+ auto it = std::find_if (nodeSet.begin (), nodeSet.end (),
515+ [&nodeUserId](const auto &node) {
516+ return node->getUserId () == nodeUserId;
517+ });
518+ if (it != nodeSet.end ()) {
519+ return *it;
512520 }
513521
514522 return std::nullopt ;
@@ -517,10 +525,12 @@ const std::optional<shared<const Node<T>>> Graph<T>::getNode(
517525template <typename T>
518526const std::optional<shared<const Node<T>>> Graph<T>::getNode(
519527 const CXXGraph::id_t nodeId) const {
520- for (const auto &it : getNodeSet ()) {
521- if (it->getId () == nodeId) {
522- return it;
523- }
528+ const auto &nodeSet = this ->getNodeSet ();
529+ auto it = std::find_if (
530+ nodeSet.begin (), nodeSet.end (),
531+ [nodeId](const auto &node) { return node->getId () == nodeId; });
532+ if (it != nodeSet.end ()) {
533+ return *it;
524534 }
525535
526536 return std::nullopt ;
@@ -538,7 +548,7 @@ std::unordered_set<shared<Node<T>>, nodeHash<T>> Graph<T>::nodeSet() {
538548 nodeSet.insert (std::const_pointer_cast<Node<T>>(adjListOutIt.first ));
539549 }
540550
541- for (auto &isNodeIt : isolatedNodesSet) {
551+ for (const auto &isNodeIt : isolatedNodesSet) {
542552 nodeSet.insert (std::const_pointer_cast<Node<T>>(isNodeIt));
543553 }
544554
0 commit comments