connected_components called on empty filtered graph

Open Beginner friendly
#231 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
68/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Quiet
Tech stack
cpp
Domain
data

Research direction

Start with the connected_components implementation and reproduce the empty filtered-graph case from the linked Compiler Explorer example. The change is complete when connected_components returns 0 for a graph whose vertices are all filtered out, while normal graph behavior remains unchanged.

Written by the indexing model from the issue text.

Description

algorithm beginner friendly priority: high

The connected_components function returns (std::numeric_limits<comp_type>::max)() + 1 when called on a filtered graph with all vertices filtered out.

An example of this problem can be found here:
https://godbolt.org/z/vWsG8j

If the line

    if (num_vertices(g) == 0) return 0;

was replaced with

   typedef typename boost::graph_traits<Graph>::vertex_iterator vi;
    std::pair<vi, vi> verts = vertices(g);
    if (verts.first == verts.second)
      return 0;

the function would work as expected.

Dominant language
C++
Stars
395
Forks
239
Avg merge
18h 50m
Merged PRs (30d)
20

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from boostorg/graph

All issues in boostorg/graph

Similar issues

More C++ issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.