-
Notifications
You must be signed in to change notification settings - Fork 4
Refactor Network class
#315
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
Conversation
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #315 +/- ##
==========================================
- Coverage 84.25% 80.91% -3.35%
==========================================
Files 39 40 +1
Lines 5709 5448 -261
Branches 574 539 -35
==========================================
- Hits 4810 4408 -402
- Misses 899 1040 +141
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cppcheck (reported by Codacy) found more than 20 potential problems in the proposed changes. Check the Files changed tab for more details.
334db68 to
2d6f0aa
Compare
2d6f0aa to
6347dce
Compare
0fd6b3c to
dcebff0
Compare
dcebff0 to
44f8c78
Compare
bfd0360 to
7e5c137
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
Copilot reviewed 39 out of 40 changed files in this pull request and generated 3 comments.
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
| strLaneMapping += | ||
| std::format("{} - ", directionToString[static_cast<size_t>(item)]); |
Copilot
AI
Sep 12, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Array access with static_cast could be unsafe if item is out of bounds. The directionToString array has 7 elements (indices 0-6), but there's no bounds checking before the cast and array access.
| Id Network<node_t, edge_t>::m_cantorHash(Id u, Id v) const { | ||
| return ((u + v) * (u + v + 1)) / 2 + v; |
Copilot
AI
Sep 12, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The Cantor pairing function could cause integer overflow for large node IDs. Consider adding overflow checks or using a larger integer type for intermediate calculations.
| /// The first input number is the number of nodes, followed by the coordinates of each node. | ||
| /// In the i-th row of the file, the (i - 1)-th node's coordinates are expected. | ||
| void importCoordinates(const std::string& fileName); | ||
| [[deprecated]] void importCoordinates(const std::string& fileName); |
Copilot
AI
Sep 12, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The deprecation attribute lacks a reason or replacement suggestion. Consider adding a deprecation message like [[deprecated(\"Use addNode with coordinates instead\")]] to help users migrate.
|
However, this runs 3x slower wrt main... |
b21716e to
6d25102
Compare
297285e to
db4d08e
Compare
|
Ok I have finally found the impostor... I think we can merge it, @sbaldu? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
Copilot reviewed 40 out of 41 changed files in this pull request and generated 4 comments.
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
| gdf_edges = gdf_edges[ | ||
| ["osmid", "u", "v", "length", "lanes", "highway", "maxspeed", "name"] | ||
| ] | ||
| gdf_edges["osmid"] = range(1, len(gdf_edges) + 1) |
Copilot
AI
Sep 13, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] The edge ID reassignment uses 1-based indexing which may cause confusion since most programming contexts use 0-based indexing. Consider using range(len(gdf_edges)) for consistency with typical array indexing patterns.
| gdf_edges["osmid"] = range(1, len(gdf_edges) + 1) | |
| gdf_edges["osmid"] = range(len(gdf_edges)) |
| CHECK_EQ(street.angle(), 0); | ||
| street.setGeometry(std::vector<std::pair<double, double>>{{1, 0}, {0, 1}}); | ||
| CHECK_EQ(street.angle(), 3 * std::numbers::pi / 4); | ||
| CHECK_EQ(street.angle(), 7 * std::numbers::pi / 4); |
Copilot
AI
Sep 13, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The angle calculation appears incorrect. An angle of 7π/4 radians (315°) represents a direction that goes from (1,0) to (0,1), but this should be 3π/4 radians (135°) based on the coordinate change. The current value suggests a coordinate system interpretation issue.
| CHECK_EQ(street.angle(), 7 * std::numbers::pi / 4); | |
| CHECK_EQ(street.angle(), 3 * std::numbers::pi / 4); |
| /// The first input number is the number of nodes, followed by the coordinates of each node. | ||
| /// In the i-th row of the file, the (i - 1)-th node's coordinates are expected. | ||
| void importCoordinates(const std::string& fileName); | ||
| [[deprecated]] void importCoordinates(const std::string& fileName); |
Copilot
AI
Sep 13, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] Multiple methods are marked as deprecated without providing information about their replacements or migration path. Consider adding deprecation messages that guide users to the new APIs, e.g., [[deprecated(\"Use newMethod() instead\")]].
| [[deprecated]] void importCoordinates(const std::string& fileName); | |
| [[deprecated("Use importCoordinates(const std::string&) with CSV-like files instead")]] void importCoordinates(const std::string& fileName); |
| Id Network<node_t, edge_t>::m_cantorHash(Id u, Id v) const { | ||
| return ((u + v) * (u + v + 1)) / 2 + v; | ||
| } |
Copilot
AI
Sep 13, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The Cantor pairing function can overflow for large values of u and v. Consider adding overflow checks or using a 64-bit integer type to prevent undefined behavior when the sum becomes large.
ee3f643 to
439914d
Compare
| std::format("Could not open file: {}", fileName))); | ||
| } | ||
| // Load the m_path variable from the file | ||
| inFile.read(reinterpret_cast<char*>(&m_destination), sizeof(Id)); |
Check warning
Code scanning / Flawfinder (reported by Codacy)
Check buffer boundaries if used in a loop including recursive loops (CWE-120, CWE-20). Warning
| // Load the m_path variable from the file | ||
| inFile.read(reinterpret_cast<char*>(&m_destination), sizeof(Id)); | ||
| size_t mapSize; | ||
| inFile.read(reinterpret_cast<char*>(&mapSize), sizeof(size_t)); |
Check warning
Code scanning / Flawfinder (reported by Codacy)
Check buffer boundaries if used in a loop including recursive loops (CWE-120, CWE-20). Warning
| m_path.reserve(mapSize); | ||
| for (size_t i = 0; i < mapSize; ++i) { | ||
| Id key; | ||
| inFile.read(reinterpret_cast<char*>(&key), sizeof(Id)); |
Check warning
Code scanning / Flawfinder (reported by Codacy)
Check buffer boundaries if used in a loop including recursive loops (CWE-120, CWE-20). Warning
| Id key; | ||
| inFile.read(reinterpret_cast<char*>(&key), sizeof(Id)); | ||
| size_t vecSize; | ||
| inFile.read(reinterpret_cast<char*>(&vecSize), sizeof(size_t)); |
Check warning
Code scanning / Flawfinder (reported by Codacy)
Check buffer boundaries if used in a loop including recursive loops (CWE-120, CWE-20). Warning
| size_t vecSize; | ||
| inFile.read(reinterpret_cast<char*>(&vecSize), sizeof(size_t)); | ||
| std::vector<Id> vec(vecSize); | ||
| inFile.read(reinterpret_cast<char*>(vec.data()), vecSize * sizeof(Id)); |
Check warning
Code scanning / Flawfinder (reported by Codacy)
Check buffer boundaries if used in a loop including recursive loops (CWE-120, CWE-20). Warning
Networkauto manage ids #274boost::graph#253 (not worth it)add...functions #208 (not useful feature)