Skip to content

Hash Table based RzGraph - #6152

Merged
notxvilka merged 19 commits into
devfrom
dist-rz_graph_refactor
Apr 7, 2026
Merged

Hash Table based RzGraph#6152
notxvilka merged 19 commits into
devfrom
dist-rz_graph_refactor

Conversation

@Rot127

@Rot127 Rot127 commented Apr 4, 2026

Copy link
Copy Markdown
Member

Your checklist for this pull request

  • I've read the guidelines for contributing to this repository.
  • I made sure to follow the project's coding style.
  • I've documented every RZ_API function and struct this PR changes.
  • I've added tests that prove my changes are effective (required for changes to RZ_API).
  • I've updated the Rizin book with the relevant information (if needed).
  • I've used AI tools to generate fully or partially these code changes and I'm sure the changes are not copyrighted by somebody else.

Detailed description

  • Open issues about missing hash functions of all the graphs in rz_core_graph().
    • once defined the RZ_DEPRECATED functions can be removed.

Test plan

...

Closing issues

...

@notxvilka notxvilka 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.

Please fix the failing CI jobs (except old Debians - this seems unrelated to these changes)

@Rot127

Rot127 commented Apr 4, 2026

Copy link
Copy Markdown
Member Author

Yes, I still work on moving the private structures to a private header and add getters for the struct members.
Then do the type problems.

Comment thread librz/util/graph_impl.c
Comment on lines +1639 to +1659
/**
* \brief Returns the index of the node in the internal vector.
*
* DO NOT USE!
*
* It only exists for compatibility reasons and because refactoring is
* more effort than currently acceptable.
*
* Justification:
* The old implementations had exactly two identifiers for nodes.
* The pointer to the node itself, or its index into the internal list storing it.
* I skip the part how what a not good design decision this was.
* But in the new graph this data is considered private (index into lists/hash table)
* or are not expected by the graph user to be tracked (the individual node pointers).
*
* Sadly the json output of the graph still uses the vector indices as "ids".
* We can't replace them with the actual hash_id of a node. Because most graphs don't implement a hash function.
* For these cases the pointer is used internally as node hash.
* And printing it in json output would not be stable.
* Hence this hack.
*/

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

@notxvilka Resolve here? Or open an issue about it and fix later?

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.

@Rot127 depends on the effort needed. If it's something that could be done quickly - here, if not - in a separate PRs.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Let's better do it in a separated PR.
The fix requires all the graphs we have (see rz_core_graph()) to define a hash function.
This affects some tests and is hence easier to review in isolation.

@Rot127

This comment was marked as resolved.

@notxvilka

Copy link
Copy Markdown
Contributor

If we still want the type annotations we should have it of the form /*<NodeType, EdgeType>*/. Otherwise it doesn't make sense.

Good idea, but it requires the change in rz-bindgen

@Rot127 Rot127 changed the title Hash Table base RzGraph Hash Table based RzGraph Apr 4, 2026
@Rot127

Rot127 commented Apr 4, 2026

Copy link
Copy Markdown
Member Author

Also useful for HtPP hash tables

Heersin added 6 commits April 7, 2026 13:01
Add comments

Basic support for list and matrix based graph refactor

Add rz_graph_*_new node and edge API

Modify calling for rz graph edge data

Add dfs and visitor mode

Add new get nth neighbours

Add unit test and wrapper for get edges

Bug fixed and unit test

Solve TODO about better semantic of get nodes

Doc RZ_API and other functions, split impl to new files

[cannot build] remove old graph impl and rename new graph API
Update Wrapper for graph identifier

Ordered Nodes in graph drawable

Fix icfg and several agraph refactor issues

Use kahn to get topo sort in assign_layers

Introduce khan for assign_layer and find DAG cycle and backedges in algorithm
@Rot127
Rot127 force-pushed the dist-rz_graph_refactor branch from 04febc0 to 9e8d29e Compare April 7, 2026 11:02
@Rot127
Rot127 force-pushed the dist-rz_graph_refactor branch from 9e8d29e to 6a64b2a Compare April 7, 2026 11:36
@notxvilka
notxvilka merged commit b11bb9d into dev Apr 7, 2026
94 of 102 checks passed
@codecov

codecov Bot commented Apr 7, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 58.29866% with 902 lines in your changes missing coverage. Please review.
✅ Project coverage is 48.24%. Comparing base (4ad23db) to head (6a64b2a).
⚠️ Report is 2 commits behind head on dev.

Files with missing lines Patch % Lines
librz/core/agraph.c 57.22% 198 Missing and 160 partials ⚠️
librz/util/graph_impl.c 58.13% 177 Missing and 129 partials ⚠️
librz/util/graph_algorithm.c 61.14% 64 Missing and 51 partials ⚠️
librz/il/il_graph.c 28.43% 73 Missing ⚠️
librz/util/graph_drawable.c 79.24% 17 Missing and 5 partials ⚠️
librz/core/cmd/cmd_debug.c 15.00% 15 Missing and 2 partials ⚠️
librz/core/cagraph.c 11.11% 8 Missing ⚠️
librz/core/cgraph.c 94.82% 3 Missing ⚠️
Additional details and impacted files
Files with missing lines Coverage Δ
librz/arch/class.c 65.61% <100.00%> (ø)
librz/bin/p/bin_mach0.inc 71.47% <100.00%> (ø)
librz/core/core_private.h 100.00% <ø> (ø)
librz/diff/diff.c 48.97% <ø> (ø)
librz/include/rz_analysis.h 77.77% <ø> (ø)
librz/core/cgraph.c 53.77% <94.82%> (+0.06%) ⬆️
librz/core/cagraph.c 44.26% <11.11%> (-0.74%) ⬇️
librz/core/cmd/cmd_debug.c 27.60% <15.00%> (-0.11%) ⬇️
librz/util/graph_drawable.c 60.77% <79.24%> (+7.98%) ⬆️
librz/il/il_graph.c 26.72% <28.43%> (ø)
... and 3 more

... and 12 files with indirect coverage changes


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 4ad23db...6a64b2a. Read the comment docs.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@notxvilka
notxvilka deleted the dist-rz_graph_refactor branch April 7, 2026 20:01
Farhan-25 pushed a commit to Farhan-25/rizin that referenced this pull request Jun 19, 2026
* Basic implement of list based and matrix based graph

Add comments

Basic support for list and matrix based graph refactor

Add rz_graph_*_new node and edge API

Modify calling for rz graph edge data

Add dfs and visitor mode

Add new get nth neighbours

Add unit test and wrapper for get edges

Bug fixed and unit test

Solve TODO about better semantic of get nodes

Doc RZ_API and other functions, split impl to new files

[cannot build] remove old graph impl and rename new graph API

* Rewrite and replace agrach, cgraph, drawable_graph, il_graph with new API

* Refactor graph API and fix unit test and multiple leaks

Update Wrapper for graph identifier

Ordered Nodes in graph drawable

Fix icfg and several agraph refactor issues

Use kahn to get topo sort in assign_layers

Introduce khan for assign_layer and find DAG cycle and backedges in algorithm

* Fix self loop and update db test

* Solve request changes

* Fix cbpf db

* Fix test graph warning in testing NULL deletion

* Fix mismatched rz_agraph_compute_layout nonnull

* Fix memleak

* Clean and fix code

* Fix memleak in graph free

* Fix memleak in matrix implement

* Add bindgen doc

* Fix memleak in early exit

* Fix rz-bindgen warning comments

* Make graph structures private.

* Fix Windows C2036

* Fix typo in type annotation.

* Add new type annotations for RzGraph and HtPP

---------

Co-authored-by: Heersin <teablearcher@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants