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

fix: Hierarchy descendants return root siblings #178

Merged
merged 2 commits into from
Jan 20, 2025

Conversation

aborgna-q
Copy link
Collaborator

Closes #177

@aborgna-q aborgna-q requested a review from lmondada January 20, 2025 16:28
@aborgna-q aborgna-q changed the title fix: Hierarchy descendants returning root siblings fix: Hierarchy descendants return root siblings Jan 20, 2025
Copy link

codecov bot commented Jan 20, 2025

Codecov Report

Attention: Patch coverage is 84.21053% with 3 lines in your changes missing coverage. Please review.

Project coverage is 83.27%. Comparing base (fbd65b7) to head (d1b03e1).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
src/hierarchy.rs 84.21% 3 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main     #178   +/-   ##
=======================================
  Coverage   83.27%   83.27%           
=======================================
  Files          24       24           
  Lines        6104     6117   +13     
  Branches     6104     6117   +13     
=======================================
+ Hits         5083     5094   +11     
- Misses        945      947    +2     
  Partials       76       76           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Contributor

@lmondada lmondada left a comment

Choose a reason for hiding this comment

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

I suggest you turn child_queue and root into a sum type, but if you think it's more hassle than it's worth, then this is fine by me.

@@ -635,6 +636,8 @@ pub struct Descendants<'a> {
/// For each region, we point to a child node that has not been visited yet.
/// When a region is visited, we move to the next child node and queue its children region at the end of the queue.
child_queue: VecDeque<NodeIndex>,
/// The root node we are iterating over.
root: NodeIndex,
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I let you be the judge of whether this is worth it, but in principle I'd much prefer something like:

enum NextStates {
    Root(NodeIndex),
    Children(VecDeque<NodeIndex>),
}

pub struct Descendants<'a> {
    /// The hierarchy this iterator is iterating over.
    layout: &'a Hierarchy,
    /// A queue of regions to visit.
    ///
    /// For each region, we point to a child node that has not been visited yet.
    /// When a region is visited, we move to the next child node and queue its children region at the end of the queue.
    next_states: NextStates,
}

It would make it clearer what the purpose of each field is, and will also make the Default implementation more sane.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Sure, makes sense.

@aborgna-q aborgna-q added this pull request to the merge queue Jan 20, 2025
Merged via the queue into main with commit da7a040 Jan 20, 2025
12 checks passed
@aborgna-q aborgna-q deleted the ab/fix-hierarchy-descendants branch January 20, 2025 17:53
@hugrbot hugrbot mentioned this pull request Jan 20, 2025
github-merge-queue bot pushed a commit that referenced this pull request Jan 20, 2025
## 🤖 New release
* `portgraph`: 0.13.0 -> 0.13.1 (✓ API compatible changes)

<details><summary><i><b>Changelog</b></i></summary><p>

<blockquote>

## [0.13.1](v0.13.0...v0.13.1)
- 2025-01-20

### Bug Fixes

- Mermaid render of graph views was empty (#175)
- Hierarchy descendants return root siblings (#178)
</blockquote>


</p></details>

---
This PR was generated with
[release-plz](https://github.com/release-plz/release-plz/).
@hugrbot hugrbot mentioned this pull request Feb 3, 2025
github-merge-queue bot pushed a commit to CQCL/tket2 that referenced this pull request Feb 5, 2025
#753)

Currently waiting for the package releases.

Requires the fix in CQCL/portgraph#178.

BREAKING CHANGE: Bumped `hugr` dependency to `0.15`

---------

Co-authored-by: Douglas Wilson <[email protected]>
Co-authored-by: Douglas Wilson <[email protected]>
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.

Hierarchy::descendants returns siblings of the root
2 participants