Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

add iter_from to CountedMap #10524

Merged
merged 1 commit into from
Dec 21, 2021
Merged

add iter_from to CountedMap #10524

merged 1 commit into from
Dec 21, 2021

Conversation

kianenigma
Copy link
Contributor

No description provided.

@kianenigma kianenigma added A0-please_review Pull request needs code review. B3-apinoteworthy C1-low PR touches the given topic and has a low impact on builders. D3-trivial 🧸 PR contains trivial changes in a runtime directory that do not require an audit labels Dec 21, 2021
///
/// If you alter the map while doing this, you'll get undefined results.
pub fn iter_from(
starting_raw_key: Vec<u8>,
Copy link
Contributor

Choose a reason for hiding this comment

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

I just noticed this, but we really can just use &[u8] here instead of mandating a Vec here to allow for a more flexible API.

Copy link
Member

Choose a reason for hiding this comment

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

If you want to have a flexible api, you should use impl Into<Vec<u8>>

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What's the benefit compared to &[]?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

all in all though @KiChjang I think if we change the API here, we should do so as well for many other exposed functions as well in the storage API, so I'd rather do it in a separate PR. For now, I prefer staying consistent with the rest of the API.

Copy link
Member

Choose a reason for hiding this comment

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

these are zero cost abstractions right? in which case, yeah let's follow up on this

Comment on lines +416 to +417
/// Enumerate all elements in the counted map after a specified `starting_raw_key` in no
/// particular order.
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 true?

are they not ordered by key? else if they are in no particular order, why would we have a starting key as useful at all?

Copy link
Member

Choose a reason for hiding this comment

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

They are probably ordered by key, however I don't think that we want to "force" ourselves to this "promise", so keeping the api more open to future implementations.

Copy link
Member

Choose a reason for hiding this comment

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

without this constraint, the api seems useless. I get you want flexibility, but.... could just be confusing for someone who wants to use this.

Copy link
Member

Choose a reason for hiding this comment

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

Why? You probably mainly want to iterate.

As the keys are hashed, you also can not be sure that the ordering based on the "decoded" key would be different to the ordering because of hashing the keys.

Comment on lines +416 to +417
/// Enumerate all elements in the counted map after a specified `starting_raw_key` in no
/// particular order.
Copy link
Member

Choose a reason for hiding this comment

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

They are probably ordered by key, however I don't think that we want to "force" ourselves to this "promise", so keeping the api more open to future implementations.

@bkchr bkchr merged commit e2cab4e into master Dec 21, 2021
@bkchr bkchr deleted the kiz-iter-from-counted-map branch December 21, 2021 17:42
grishasobol pushed a commit to gear-tech/substrate that referenced this pull request Mar 28, 2022
ark0f pushed a commit to gear-tech/substrate that referenced this pull request Feb 27, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
A0-please_review Pull request needs code review. C1-low PR touches the given topic and has a low impact on builders. D3-trivial 🧸 PR contains trivial changes in a runtime directory that do not require an audit
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants