@@ -508,7 +508,7 @@ class GraphBuilder
508508 *
509509 * Sorts the edges and optionally removes duplicate edges (same start and end node indices).
510510 * Wihout dupplicate removal, multiple edges between the same nodes are allowed and the order of insertion is stable.
511- * @param make_unique If true, duplicate edges are removed. The first added edge is kept!
511+ * @param make_unique If true, duplicate edges are removed. The last added edge is kept!
512512 * @return Graph<NodePropertyT, EdgePropertyT> The constructed graph.
513513 */
514514 Graph<NodeProperty, EdgeProperty> build (bool make_unique = false )
@@ -540,42 +540,30 @@ class GraphBuilder
540540 * @brief Remove duplicate edges from a sorted edge vector.
541541 *
542542 * Copies all the unique edges to a new vector and replaces the original edge vector with it. Unique means that
543- * the start and end node indices are unique. Other edge properties are not checked and may get lost. Only the first
543+ * the start and end node indices are unique. Other edge properties are not checked and may get lost. Only the last
544544 * edge in the vector is kept.
545545 */
546546 void remove_duplicate_edges ()
547547 {
548548 std::vector<Edge<EdgePropertyT>> unique_edges;
549549 unique_edges.reserve (m_edges.size ());
550- std::ranges::unique_copy (m_edges, std::back_inserter (unique_edges), [](auto && e1 , auto && e2 ) {
550+ auto curr_elem = m_edges.begin ();
551+ auto next_elem = std::adjacent_find (curr_elem, m_edges.end (), [](auto && e1 , auto && e2 ) {
551552 return e1 .start_node_idx == e2 .start_node_idx && e1 .end_node_idx == e2 .end_node_idx ;
552553 });
553- m_edges = std::move (unique_edges);
554- }
555-
556- /* *
557- * @brief Remove duplicate edges from a sorted edge vector.
558- *
559- * Copies all the unique edges to a new vector and replaces the original edge vector with it. Unique means that
560- * the start and end node indices are unique. Other edge properties are not checked and may get lost. Only the first
561- * edge in the vector is kept.
562- */
563- void remove_double_edges ()
564- {
565- std::vector<Edge<EdgePropertyT>> unique_edges;
566- unique_edges.reserve (m_edges.size ());
567- auto curr_elem = m_edges.begin ();
568- auto next_elem = std::adjacent_find (curr_elem, m_edges.end (), is_equal);
569554 while (next_elem != m_edges.end ()) {
570555 std::copy (curr_elem, next_elem, std::back_inserter (unique_edges));
571556 curr_elem = next_elem;
572- while (is_equal (*curr_elem, *next_elem) && next_elem != m_edges.end ()) {
557+ while ((*curr_elem).start_node_idx == (*next_elem).start_node_idx &&
558+ (*curr_elem).end_node_idx == (*next_elem).end_node_idx && next_elem != m_edges.end ()) {
573559 next_elem = next (next_elem);
574560 }
575561 curr_elem = prev (next_elem);
576562 std::copy (curr_elem, next (curr_elem), std::back_inserter (unique_edges));
577563 curr_elem = next (curr_elem);
578- next_elem = std::adjacent_find (curr_elem, m_edges.end (), is_equal);
564+ next_elem = std::adjacent_find (curr_elem, m_edges.end (), [](auto && e1 , auto && e2 ) {
565+ return e1 .start_node_idx == e2 .start_node_idx && e1 .end_node_idx == e2 .end_node_idx ;
566+ });
579567 }
580568 std::copy (curr_elem, next_elem, std::back_inserter (unique_edges));
581569 m_edges = std::move (unique_edges);
0 commit comments