Skip to content

Improve apyds_egg API: make repair private, add equivalence check, complete docstrings, make UnionFind generic - #152

Merged
hzhangxyz merged 3 commits into
mainfrom
copilot/fix-api-issues-in-init-py
Dec 22, 2025
Merged

Improve apyds_egg API: make repair private, add equivalence check, complete docstrings, make UnionFind generic#152
hzhangxyz merged 3 commits into
mainfrom
copilot/fix-api-issues-in-init-py

Conversation

Copilot AI commented Dec 22, 2025

Copy link
Copy Markdown
Contributor

Four API improvements to /egg/apyds_egg/__init__.py: privatize internal method, add equivalence testing, complete parameter documentation for public methods, and make UnionFind a generic data structure.

Changes

  • Made repair private: Renamed to _repair to prevent exposure as public API. This method is an internal implementation detail of rebuild().

  • Added are_equal method: New public API to check if two EClassId values belong to the same equivalence class:

    eg = EGraph()
    a = eg.add(apyds.Term("a"))
    b = eg.add(apyds.Term("b"))
    eg.merge(a, b)
    eg.are_equal(a, b)  # Returns: True
  • Completed parameter docstrings: Added Args/Returns sections to all public methods (merge, find, union, canonicalize) following Google-style format. Previously only add had complete parameter documentation.

  • Made UnionFind generic: Changed UnionFind to UnionFind(Generic[T]) to make it a reusable generic data structure that can work with any type, not just EClassId. The EGraph class now uses UnionFind[EClassId]() to explicitly specify the type parameter. This improves code reusability without breaking existing functionality.

Original prompt

This section details on the original issue you should resolve

<issue_title>更新 /egg/apyds_egg/init.py 的一些问题</issue_title>
<issue_description>1. repair 不应个暴露为公共api
2. 需要添加一个接口检测俩eclassid是否相等
3. 公共api的函数, 应该有函数参数的docstring, 目前merge看起来是缺少的</issue_description>

Comments on the Issue (you are @copilot in this section)


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

…e docstrings

Co-authored-by: hzhangxyz <11623447+hzhangxyz@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix public API exposure and add equality check for eclassid Improve apyds_egg API: make repair private, add equivalence check, complete docstrings Dec 22, 2025
Copilot AI requested a review from hzhangxyz December 22, 2025 04:33
Comment thread egg/tests/test_egraph.py
def test_egraph_are_equal_after_rebuild():
eg = EGraph()

x = eg.add(apyds.Term("x"))

@hzhangxyz hzhangxyz left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

UnionFind写成Generic[T]的吧

Co-authored-by: hzhangxyz <11623447+hzhangxyz@users.noreply.github.com>

Copilot AI commented Dec 22, 2025

Copy link
Copy Markdown
Contributor Author

UnionFind写成Generic[T]的吧

Done in 507b8d7. UnionFind is now Generic[T] and can work with any type, not just EClassId.

Copilot AI changed the title Improve apyds_egg API: make repair private, add equivalence check, complete docstrings Improve apyds_egg API: make repair private, add equivalence check, complete docstrings, make UnionFind generic Dec 22, 2025
Copilot AI requested a review from hzhangxyz December 22, 2025 04:40
@hzhangxyz
hzhangxyz marked this pull request as ready for review December 22, 2025 04:43
Copilot AI review requested due to automatic review settings December 22, 2025 04:43
@hzhangxyz
hzhangxyz merged commit afa06f9 into main Dec 22, 2025
83 checks passed

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR improves the API design of the E-graph implementation by privatizing an internal method, adding an equivalence check method, completing documentation, and making the UnionFind data structure generic for better reusability.

  • Privatized the repair method to _repair to prevent unintended external usage
  • Added a new are_equal public API method to check E-class equivalence
  • Completed parameter documentation for all public methods using Google-style docstrings
  • Converted UnionFind to a generic class UnionFind[T] for type safety and reusability

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
egg/apyds_egg/init.py Renamed repair to _repair, added are_equal method, completed docstrings for merge, find, union, and canonicalize methods, made UnionFind generic by adding Generic[T] and updated type annotations
egg/tests/test_egraph.py Added comprehensive tests for the new are_equal method, including basic equality checks and post-rebuild congruence verification

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread egg/tests/test_egraph.py
def test_egraph_are_equal_after_rebuild():
eg = EGraph()

x = eg.add(apyds.Term("x"))

Copilot AI Dec 22, 2025

Copy link

Choose a reason for hiding this comment

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

Variable x is not used.

Suggested change
x = eg.add(apyds.Term("x"))
x = eg.add(apyds.Term("x"))
assert isinstance(x, int)

Copilot uses AI. Check for mistakes.
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.

更新 /egg/apyds_egg/__init__.py 的一些问题

3 participants