Skip to content
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

Improvements to MerkleList and Iterator #1562

Merged
merged 28 commits into from
Apr 18, 2024
Merged

Improvements to MerkleList and Iterator #1562

merged 28 commits into from
Apr 18, 2024

Conversation

Trivo25
Copy link
Member

@Trivo25 Trivo25 commented Apr 11, 2024

  • startIteratingFromOldest() to add an iterator which iterates from oldest to newest elements (n_i to n_0), helpful for reducer-like applications that need to iterate through historical data
  • add MerkleList.fromReverse creates a MerkleList from an array but reverses it internally
  • demonstrates how to use an iterator for actions and reducers that reduce historical data

src/lib/provable/merkle-list.ts Outdated Show resolved Hide resolved
src/lib/provable/merkle-list.ts Outdated Show resolved Hide resolved
@Trivo25 Trivo25 marked this pull request as ready for review April 14, 2024 11:25
Copy link
Member

@mitschabaude mitschabaude left a comment

Choose a reason for hiding this comment

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

I think you also have to replace next() with previous() and startIterating() with startIteratingFromLast() in all of our library code

src/lib/provable/merkle-list.ts Show resolved Hide resolved
src/lib/provable/merkle-list.ts Outdated Show resolved Hide resolved
src/lib/provable/merkle-list.ts Show resolved Hide resolved
src/lib/provable/merkle-list.ts Outdated Show resolved Hide resolved
describe('pop and previous should behave the same', () => {
it('empty hash', () => {
let l1 = List.from([Field(1), Field(2)]);
let l2 = l1.clone();
Copy link
Member

Choose a reason for hiding this comment

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

is this cloning necessary 🤔

Copy link
Member Author

Choose a reason for hiding this comment

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

yea, otherwise pop would literally steal the elements form the iterator :D I could have also just initiated a second array, but I thought I would clone it to make sure it actually does clone

src/lib/provable/test/merkle-list.test.ts Show resolved Hide resolved
@Trivo25 Trivo25 merged commit f66233b into main Apr 18, 2024
14 checks passed
@Trivo25 Trivo25 deleted the breaking-reducer branch April 18, 2024 12:10
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.

2 participants