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

feat(corelib): Felt252DictFromIterator #7137

Merged
merged 3 commits into from
Jan 23, 2025

Conversation

julio4
Copy link
Contributor

@julio4 julio4 commented Jan 22, 2025

Implement iter::FromIterator<Felt252Dict<T>, (felt252, T)>

Constructs a Felt252Dict<T> from an iterator of (felt252, T) key-value pairs.

Example

let mut dict: Felt252Dict<u32> = (0..5_u32).into_iter().map(|x| (x.into(), x)).collect();

assert_eq!(dict[0], 0);
assert_eq!(dict[1], 1);
assert_eq!(dict[2], 2);
assert_eq!(dict[3], 3);
assert_eq!(dict[4], 4);

@reviewable-StarkWare
Copy link

This change is Reviewable

Copy link
Collaborator

@orizi orizi left a comment

Choose a reason for hiding this comment

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

Reviewed 1 of 2 files at r1, all commit messages.
Reviewable status: 1 of 2 files reviewed, 3 unresolved discussions (waiting on @julio4)


corelib/src/dict.cairo line 270 at r1 (raw file):

    T, +Destruct<T>, +Destruct<Felt252Dict<T>>, +Felt252DictValue<T>,
> of crate::iter::FromIterator<Felt252Dict<T>, (felt252, T)> {
    /// Constructs a `Felt252Dict<T>` from an iterator of (felt252, T) key-value pairs.

also note that early repeating values are overriden.
additionally test this.


corelib/src/test/dict_test.cairo line 156 at r1 (raw file):

        .into_iter()
        .map(|x| (Into::<u32, felt252>::into(x), x))
        .collect();

should work, at least if rebased.

Suggestion:

    let mut dict: Felt252Dict<u32> = (0..5_u32).into_iter().map(|x| (x.into(), x)).collect();

corelib/src/test/dict_test.cairo line 162 at r1 (raw file):

    assert_eq!(@dict[2], @2);
    assert_eq!(@dict[3], @3);
    assert_eq!(@dict[4], @4);

Suggestion:

    assert_eq!(dict[0], 0);
    assert_eq!(dict[1], 1);
    assert_eq!(dict[2], 2);
    assert_eq!(dict[3], 3);
    assert_eq!(dict[4], 4);

@julio4 julio4 force-pushed the feat/dict_from_iterator branch from 64d1fec to 87a443a Compare January 22, 2025 14:20
Copy link
Collaborator

@orizi orizi left a comment

Choose a reason for hiding this comment

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

:lgtm:

Reviewed 2 of 2 files at r2, all commit messages.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on @julio4)


a discussion (no related file):
@gilbens-starkware

Copy link
Contributor Author

@julio4 julio4 left a comment

Choose a reason for hiding this comment

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

Reviewable status: 1 of 2 files reviewed, all discussions resolved (waiting on @orizi)


corelib/src/dict.cairo line 270 at r1 (raw file):

Previously, orizi wrote…

also note that early repeating values are overriden.
additionally test this.

done

Copy link
Collaborator

@orizi orizi left a comment

Choose a reason for hiding this comment

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

Reviewed 1 of 1 files at r3, all commit messages.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on @julio4)

Copy link
Collaborator

@orizi orizi left a comment

Choose a reason for hiding this comment

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

Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on @julio4)

Copy link
Contributor

@gilbens-starkware gilbens-starkware left a comment

Choose a reason for hiding this comment

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

:lgtm:

Reviewed 2 of 2 files at r2.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on @julio4)

@gilbens-starkware gilbens-starkware added this pull request to the merge queue Jan 23, 2025
Merged via the queue into starkware-libs:main with commit 51b323b Jan 23, 2025
47 checks passed
@julio4 julio4 deleted the feat/dict_from_iterator branch February 5, 2025 10:58
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.

4 participants