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

Add a method to collection views to return the number of items #2952

Open
jvff opened this issue Nov 25, 2024 · 0 comments
Open

Add a method to collection views to return the number of items #2952

jvff opened this issue Nov 25, 2024 · 0 comments
Labels
enhancement New feature or request
Milestone

Comments

@jvff
Copy link
Contributor

jvff commented Nov 25, 2024

Motivation

In some views, the only way to discover the amount of items in them is to use for_each_key and count them. This pattern is common enough that it could be a method in the views themselves.

Proposal

Add a helper method to the views that store multiple items, and name it

  • len if the number of items is obtained O(1) (e.g. it is persisted in storage)
  • count if it needs to be calculated in O(n) (e.g., with the for_each_key described above)
@jvff jvff added the enhancement New feature or request label Nov 25, 2024
@jvff jvff added this to the Mainnet milestone Nov 25, 2024
@jvff jvff added this to Storage Nov 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Status: No status
Development

No branches or pull requests

1 participant