Skip to content

Fix hash-isequal contract for SimpleEdgeIter - #523

Open
mxhbl wants to merge 1 commit into
JuliaGraphs:masterfrom
mxhbl:simpleedgeiter-hash
Open

Fix hash-isequal contract for SimpleEdgeIter#523
mxhbl wants to merge 1 commit into
JuliaGraphs:masterfrom
mxhbl:simpleedgeiter-hash

Conversation

@mxhbl

@mxhbl mxhbl commented Aug 20, 2026

Copy link
Copy Markdown
Member

Hashing and equality checks on SimpleEdgeIter do not currently not play together, which introduces correctness bugs when creating Dicts or Sets of SimpleEdgeIters; see #504.

The obstacle to simply defining hash is that == relates a SimpleEdgeIter to both an AbstractVector{SimpleEdge} and a Set{SimpleEdge} (and isequal falls back to ==). This forces hash(iter) == hash(vec) and hash(iter) == hash(set) but hash(vec) != hash(set) in Base, so no definition of hash can satisfy the contract.

This PR resolves this by

  • defining separate isequals that all evaluate to false if the container types are different. == is left unchanged.
  • Implementing a new hash(::SimpleEdgeIter) that samples about log(nv) adjacency lists with Fibonacci skips, similar to Base.hash on arrays, reading only length, first, and last from each list. We run the sampling in reverse order, since the equality check runs in forward order and can then often return early. Vertices without edges are skipped, matching the behavior of ==(::SimpleEdgeIter, ::SimpleEdgeIter).

@codecov

codecov Bot commented Aug 20, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.48%. Comparing base (356aa72) to head (aa95818).

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #523      +/-   ##
==========================================
+ Coverage   97.46%   97.48%   +0.02%     
==========================================
  Files         127      128       +1     
  Lines        7766     7831      +65     
==========================================
+ Hits         7569     7634      +65     
  Misses        197      197              

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@mxhbl
mxhbl requested a review from Krastanov August 20, 2026 06:48
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.

1 participant