Skip to content

Refactor AMT to use iter_mut Instead of for_each_mut #2178

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

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

Sahilgill24
Copy link

@Sahilgill24 Sahilgill24 commented May 22, 2025

This PR refactors the AMT mplementation by replacing internal iteration via for_each_mut with external iteration using iter_mut and adds a test case showing the use case of the iter_mut function .

Motivation:

Solves #1996

Progress:

  • The iter_mut function yields a Smart pointer Amtptr.
  • Amtptr can be dereferenced immutably.
  • Can be dereferenced mutably.
  • Can be deleted to yield the inner value.

Note

Instead of using the deref_mut , the get_mut function can be used instead as written in the test case and as shown
below

    for ptr in new_amt.iter_mut() {
        let current_idx = ptr.0;
        let mut val = ptr.1;
        let mut val_ref = val.get_mut();
        f(current_idx, &mut ValueMut::new(&mut *val_ref)).unwrap();
    }

@github-project-automation github-project-automation bot moved this to 📌 Triage in FilOz May 22, 2025
@Sahilgill24 Sahilgill24 marked this pull request as ready for review May 30, 2025 15:08
@Copilot Copilot AI review requested due to automatic review settings May 30, 2025 15:08
Copy link

@Copilot Copilot AI left a comment

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 refactors the AMT implementation by replacing internal mutable iteration (for_each_mut) with an external iterator (iter_mut) that yields a smart pointer (Amtptr), and adds a corresponding test case to validate the new behavior.

  • Introduces the iter_mut function in the AMT implementation which returns mutable smart- pointers (Amtptr).
  • Adds a new test ("iter_mutable") demonstrating the usage of the iter_mut function.
  • Updates related module imports and minor adjustments in the value_mut module.

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
ipld/amt/tests/amt_tests.rs New test case for iter_mutable functionality added.
ipld/amt/src/value_mut.rs Minor formatting improvement with additional import.
ipld/amt/src/amt.rs Added Amtptr struct and iter_mut function, with associated changes.

@Sahilgill24 Sahilgill24 marked this pull request as draft May 30, 2025 15:30
@github-project-automation github-project-automation bot moved this from 📌 Triage to 🎉 Done in FilOz May 30, 2025
@Sahilgill24 Sahilgill24 reopened this Jun 2, 2025
@github-project-automation github-project-automation bot moved this from 🎉 Done to 📌 Triage in FilOz Jun 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: 📌 Triage
Development

Successfully merging this pull request may close these issues.

1 participant