Skip to content

Conversation

@sunav1411
Copy link

This PR introduces an optimization to the Havel-Hakimi degree sequence realization algorithm by replacing redundant sorting operations with a max-heap implementation.

Optimize degree sequence realization by avoiding repeated sorting using qsort()
Added a git fetch --tags step to the workflow after the checkout process.
This ensures that the build process can access version tags, preventing issues with missing or shallow clone history during version detecti
…sorting

Extended Description:
Replaced the repeated sorting operations with a max-heap implementation.

This improves the efficiency of the Havel-Hakimi degree sequence realization by avoiding redundant sorting steps.

The max-heap handles vertex selection efficiently, reducing the overall complexity and improving performance
with:
fetch-depth: 0

- name: Fetch tags
Copy link
Contributor

Choose a reason for hiding this comment

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

What is the reasoning for this change?

Copy link
Author

Choose a reason for hiding this comment

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

Sir, actually I added this to fetch all tags, but later realized the repo has no tags, so it's unnecessary.



// Choose vertices in the order of their IDs.
#include <queue>
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a reason this is included here instead of at the top of the file?

Copy link
Author

Choose a reason for hiding this comment

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

Sir, actually I added it here while fixing an issue, but yeah, it makes more sense to have it at the top. I'll move it.


// Choose vertices in the order of their IDs.
#include <queue>
#include <vector>
Copy link
Contributor

Choose a reason for hiding this comment

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

vector is already included

Copy link
Author

Choose a reason for hiding this comment

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

Sir, my bad! It’s my first time, so I’m still learning and made this mistake. But I’ll be more careful next time and won’t repeat it. I will remove the duplicate.

++it, ++k) {
if (--(it->degree) < 0) {
goto fail;
std::vector<VertexDeg> remainingNodes;
Copy link
Contributor

Choose a reason for hiding this comment

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

The vector should either be initialized of size degree or call reserve to prevent unnecessary reallocations.

Copy link
Author

Choose a reason for hiding this comment

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

Sir, thanks for pointing it out! I’m still learning and really appreciate the guidance. I will make sure to initialize the vector properly next time


typedef std::list<vd_pair> vlist;
vlist vertices;
typedef std::pair<igraph_integer_t, igraph_integer_t> VertexDeg; // (degree, vertex)
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is the structure an std::pair now? A type for this is already defined and was used in the line you removed. A struct with names is preferable over an std::pair. You should also use using over typedef when possible in C++.

Copy link
Author

Choose a reason for hiding this comment

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

Sir, I changed it to std::pair while refactoring, but yeah, you’re right. A struct with proper names is better. I’ll fix it. Thanks for the help and guidance.

if (vd.degree == 0) {
continue;
if (degree > maxHeap.size()) {
return IGRAPH_EINVAL; // Return error code if the sequence is invalid
Copy link
Contributor

Choose a reason for hiding this comment

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

The comment is redundant as the code clearly says the same thing. The comment here should rather say why the sequence is invalid.

Copy link
Author

Choose a reason for hiding this comment

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

I will update the comment to explain why the sequence is invalid instead of just stating the obvious.

// Connect the current vertex to its neighbors
for (igraph_integer_t i = 0; i < degree; ++i) {
if (maxHeap.empty()) {
return IGRAPH_EINVAL;
Copy link
Contributor

Choose a reason for hiding this comment

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

A comment explaining why it is invalid at this step would be useful for fresh eyes.

Copy link
Author

Choose a reason for hiding this comment

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

I will add a clear comment explaining why it’s invalid at this step to make it easier for fresh eyes.

}


int main(void) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why are all the tests deleted?

Copy link
Author

Choose a reason for hiding this comment

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

Since it is my first time, I made the mistake of deleting the tests unintentionally. I am learning from it and will be more careful moving forward.

@sunav1411 sunav1411 requested a review from Tagl March 27, 2025 10:56
@sunav1411 sunav1411 closed this Mar 27, 2025
@sunav1411 sunav1411 reopened this Mar 27, 2025
@stale
Copy link

stale bot commented Apr 26, 2025

This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 14 days if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale Issues that have been inactive for a long time; will be closed in the absence of further activity label Apr 26, 2025
@szhorvat szhorvat removed the stale Issues that have been inactive for a long time; will be closed in the absence of further activity label Apr 27, 2025
@stale stale bot added the stale Issues that have been inactive for a long time; will be closed in the absence of further activity label Jul 19, 2025
@igraph igraph deleted a comment from stale bot Jul 20, 2025
@szhorvat szhorvat removed the stale Issues that have been inactive for a long time; will be closed in the absence of further activity label Jul 20, 2025
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.

3 participants