Skip to content
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

Modernize graph_ops.hpp #711

Merged
merged 1 commit into from
Oct 1, 2024
Merged

Modernize graph_ops.hpp #711

merged 1 commit into from
Oct 1, 2024

Conversation

elazarg
Copy link
Collaborator

@elazarg elazarg commented Oct 1, 2024

Summary by CodeRabbit

  • New Features

    • Introduced a constant for invalid vertex identifiers to enhance code clarity and reduce errors.
    • Updated graph operation methods to use the new constant for improved consistency.
  • Bug Fixes

    • Streamlined logic in various methods to ensure robust handling of invalid vertices.
  • Documentation

    • Refined comments for better clarity and understanding of the code.
  • Chores

    • Cleaned up unnecessary preprocessor directives for improved code maintenance.

Signed-off-by: Elazar Gershuni <[email protected]>
Copy link

coderabbitai bot commented Oct 1, 2024

Walkthrough

The changes involve modifications to the src/crab_utils/graph_ops.hpp file, focusing on the handling of graph operations. A new constant invalid_vert has been introduced to replace the use of -1 for invalid vertex identifiers. The GraphPerm class constructor and various methods have been updated to utilize this constant, enhancing code clarity and consistency. Additionally, comments have been refined, and unnecessary preprocessor directives have been removed, contributing to a cleaner codebase.

Changes

File Path Change Summary
src/crab_utils/graph_ops.hpp Introduced constexpr static vert_id invalid_vert for invalid vertex identifiers. Updated GraphPerm constructor and methods to use invalid_vert instead of -1. Refined comments and removed unnecessary preprocessor directives.

Poem

In the code where rabbits hop,
invalid_vert will never stop.
With clarity and care, we now can see,
Graphs are tidy, wild, and free!
So let’s rejoice, with a joyful cheer,
For cleaner code, we hold so dear! 🐇✨


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

📜 Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE

📥 Commits

Files that changed from the base of the PR and between 6d84933 and ae162d4.

📒 Files selected for processing (1)
  • src/crab_utils/graph_ops.hpp (31 hunks)
🔇 Additional comments (49)
src/crab_utils/graph_ops.hpp (49)

25-25: Excellent use of a constant for invalid vertex identifiers!

Introducing the invalid_vert constant to replace the use of -1 for invalid vertex identifiers enhances code clarity and reduces potential errors. Great improvement!


32-35: LGTM!

The check against invalid_vert is now used consistently for invalid vertices.


87-91: LGTM!

The iterator increment and decrement operators are implemented correctly.


99-102: LGTM!

The vert_const_range constructor and iterator methods are implemented correctly.


126-126: LGTM!

The use of invalid_vert for skipping invalid vertices in the iterator comparison is correct.


152-152: LGTM!

The use of invalid_vert for skipping invalid vertices in the edge iterator comparison is correct.


179-185: LGTM!

The changes to use invalid_vert and ItG::empty_iterator() in the adj_list class are correct.


190-190: LGTM!

The use of invalid_vert for checking invalid vertices in the mem method is correct.


219-225: LGTM!

The changes to use invalid_vert and ItG::empty_iterator() in the const_adj_list class are correct.


230-230: LGTM!

The use of invalid_vert for checking invalid vertices in the mem method is correct.


248-251: LGTM!

The use of invalid_vert for checking invalid vertices in the succs method is correct.


254-257: LGTM!

The use of invalid_vert for checking invalid vertices in the preds method is correct.


261-264: LGTM!

The use of invalid_vert for checking invalid vertices in the e_succs method is correct.


267-270: LGTM!

The use of invalid_vert for checking invalid vertices in the e_preds method is correct.


292-292: LGTM!

The elem method implementation is correct.


294-294: LGTM!

The lookup method implementation is correct.


Line range hint 554-564: LGTM!

The grow_scratch function implementation looks good. The exponential growth strategy and initialization of new elements are handled correctly.


595-595: LGTM!

The use of std::max to compute the maximum edge weight during the join operation is correct.


650-653: LGTM!

The strong_connect function implementation looks good. The logic for computing strongly connected components is correct.


669-669: LGTM!

The use of gsl::narrow for narrowing conversion is appropriate here.


674-677: LGTM!

The logic for generating strongly connected components when a root node is found is correct.


681-681: LGTM!

The use of bitwise AND to clear the visited flag is correct.


687-688: LGTM!

The compute_sccs function implementation looks good. It correctly initializes the scratch space and calls strong_connect for each unvisited vertex.


696-697: LGTM!

The initialization of the stack and index variables is correct.


709-709: LGTM!

The select_potentials function implementation looks good. It correctly computes strongly connected components and runs the Bellman-Ford algorithm on each SCC.


730-730: LGTM!

The loop over strongly connected components in reverse topological order is correct.


741-741: LGTM!

The increment of the queue tail pointer is correct.


744-745: LGTM!

The loop over vertices in the current strongly connected component is correct.


760-760: LGTM!

The increment of the next queue tail pointer is correct.


774-775: LGTM!

The loop for checking the feasibility of the current strongly connected component is correct.


794-794: LGTM!

The close_after_meet function implementation looks good. It correctly partitions edges and runs the chromatic Dijkstra variant on each source vertex.


919-924: LGTM!

The dijkstra_recover function implementation looks good. It correctly runs Dijkstra's algorithm while avoiding the expansion of stable vertices.


993-993: LGTM!

The repair_potential function implementation looks good. It correctly initializes the distances and runs Dijkstra's algorithm to repair the potential.


1045-1045: LGTM!

The close_after_widen function implementation looks good. It correctly marks stable vertices and calls dijkstra_recover for unstable vertices.


1069-1072: LGTM!

The AdjCmp struct implementation looks good. It correctly compares vertices based on their slack values.


1077-1077: LGTM!

The NegP struct implementation looks good. It correctly returns the negated potential value for a given vertex.


1083-1085: LGTM!

The close_after_assign_fwd function implementation looks good. It correctly computes the transitive closure of edges reachable from a given vertex.


1102-1103: LGTM!

The increment of the adjacent tail pointer is correct.


1106-1106: LGTM!

The sorting of immediate edges by increasing slack using AdjCmp is correct.


1109-1109: LGTM!

The loop over adjacent vertices is correct.


1120-1120: LGTM!

The increment of the reachable tail pointer is correct.


1129-1129: LGTM!

The loop for collecting adjacencies and clearing vertex flags is correct.


1198-1199: LGTM!

The close_after_assign function implementation looks good. It correctly calls close_after_assign_fwd for both forward and reverse directions.


1211-1212: LGTM!

The use of GraphRev to compute the closure in the reverse direction is correct.


109-109: 🧹 Nitpick (assertive)

Use vert_id for consistency and consider renaming the parameter.

For consistency with the rest of the codebase, use vert_id instead of vert_id for the after parameter. Additionally, consider renaming after to a more descriptive name, such as last_vert, to clarify its purpose.

-   vert_const_range verts() const { return vert_const_range(gsl::narrow<vert_id>(perm.size())); }
+   vert_const_range verts() const { return vert_const_range(gsl::narrow<vert_id>(perm.size())); }

Likely invalid or redundant comment.


623-623: 🧹 Nitpick (assertive)

Consider using const auto& for function parameters.

To avoid unnecessary copying and maintain const-correctness, consider using const auto& for the l and r parameters in the widen function.

-   static graph_t widen(const auto& l, const auto& r, std::unordered_set<vert_id>& unstable) {
+   static graph_t widen(const auto& l, const auto& r, std::unordered_set<vert_id>& unstable) {

Likely invalid or redundant comment.


603-603: 🧹 Nitpick (assertive)

Consider using const auto& for function parameters.

To avoid unnecessary copying and maintain const-correctness, consider using const auto& for the l and r parameters in the meet function.

-   static graph_t meet(const auto& l, const auto& r, bool& is_closed) {
+   static graph_t meet(const auto& l, const auto& r, bool& is_closed) {

Likely invalid or redundant comment.


84-85: 🧹 Nitpick (assertive)

Consider using vert_id type for consistency.

For consistency with the rest of the codebase, consider using the vert_id type instead of vert_id for the constructor parameter and the operator* return type.

-           explicit iterator(const vert_id _v) : v{_v} {}
+           explicit iterator(vert_id _v) : v{_v} {}
-           vert_id operator*() const { return v; }
+           vert_id operator*() const { return v; }

Likely invalid or redundant comment.


30-30: Verify that all uses of -1 for invalid vertices have been replaced.

The constructor now initializes the inv vector with invalid_vert instead of -1, which is a positive change. However, please ensure that all other occurrences of -1 used for invalid vertices throughout the codebase have been consistently replaced with invalid_vert.

src/crab_utils/graph_ops.hpp Show resolved Hide resolved
src/crab_utils/graph_ops.hpp Show resolved Hide resolved
src/crab_utils/graph_ops.hpp Show resolved Hide resolved
@coveralls
Copy link

Coverage Status

coverage: 90.395% (-0.005%) from 90.4%
when pulling ae162d4 on modernize-graph_ops
into 6d84933 on main.

@elazarg elazarg merged commit 23e8382 into main Oct 1, 2024
15 checks passed
@elazarg elazarg deleted the modernize-graph_ops branch October 1, 2024 21:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants