ref-fvm icon indicating copy to clipboard operation
ref-fvm copied to clipboard

Refactor AMT to use iter_mut Instead of for_each_mut

Open Sahilgill24 opened this issue 6 months ago • 0 comments

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:

  • [x] The iter_mut function yields a Smart pointer Amtptr.
  • [x] Amtptr can be dereferenced immutably.
  • [x] 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();
    }

Sahilgill24 avatar May 22 '25 18:05 Sahilgill24