-
Notifications
You must be signed in to change notification settings - Fork 431
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
Provide a StorageVec
datastructure
#1995
Conversation
Signed-off-by: Cyrill Leutwiler <[email protected]>
Signed-off-by: Cyrill Leutwiler <[email protected]>
Signed-off-by: xermicus <[email protected]>
Signed-off-by: xermicus <[email protected]>
Signed-off-by: Cyrill Leutwiler <[email protected]>
Signed-off-by: Cyrill Leutwiler <[email protected]>
Signed-off-by: Cyrill Leutwiler <[email protected]>
Signed-off-by: xermicus <[email protected]>
Signed-off-by: xermicus <[email protected]>
Signed-off-by: xermicus <[email protected]>
Signed-off-by: xermicus <[email protected]>
Signed-off-by: xermicus <[email protected]>
Signed-off-by: xermicus <[email protected]>
Signed-off-by: Cyrill Leutwiler <[email protected]>
Signed-off-by: Cyrill Leutwiler <[email protected]>
Signed-off-by: Cyrill Leutwiler <[email protected]>
Signed-off-by: Cyrill Leutwiler <[email protected]>
Codecov ReportAttention:
Additional details and impacted files@@ Coverage Diff @@
## master #1995 +/- ##
==========================================
+ Coverage 53.37% 53.84% +0.47%
==========================================
Files 220 221 +1
Lines 6884 6957 +73
Branches 0 3068 +3068
==========================================
+ Hits 3674 3746 +72
- Misses 3210 3211 +1 ☔ View full report in Codecov by Sentry. |
🦑 📈 ink! Example Contracts ‒ Changes Report 📉 🦑These are the results when building the
Link to the run | Last update: Thu Nov 30 13:09:55 CET 2023 |
Signed-off-by: Cyrill Leutwiler <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I prefer this proposal over #1997 too. Simpler, smaller code size, and in line with the philosophy of Mapping
and Lazy
(thin wrappers around storage access).
I agree with Andrew, and I like this approach more than a Rust-like vector with caching inside. |
Signed-off-by: Cyrill Leutwiler <[email protected]>
Signed-off-by: Cyrill Leutwiler <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Signed-off-by: Cyrill Leutwiler <[email protected]>
Signed-off-by: Cyrill Leutwiler <[email protected]>
Yeah why not, 🪓 it |
Signed-off-by: Cyrill Leutwiler <[email protected]>
Signed-off-by: Cyrill Leutwiler <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! Just a small nit
crates/storage/src/lazy/vec.rs
Outdated
pub fn len(&self) -> u32 { | ||
debug_assert!(self.len_cached.is_none() || self.len.get() == self.len_cached); | ||
|
||
self.len_cached |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My understanding here is that subsequent calls of len()
will still call uncached len
? Why not cache it here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For that, and all other getters it would need a &mut self
receiver.
Maybe could get around that with interior mutability to remove the inefficiency.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah I missed that. Easy to do with a Cell
though
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@SkymanOne added it together with a test
crates/ink/tests/ui/contract/fail/constructor-return-result-non-codec-error.stderr
Outdated
Show resolved
Hide resolved
…s for the caching to work Signed-off-by: Cyrill Leutwiler <[email protected]>
Signed-off-by: Cyrill Leutwiler <[email protected]>
Signed-off-by: Cyrill Leutwiler <[email protected]>
Signed-off-by: Cyrill Leutwiler <[email protected]>
Signed-off-by: Cyrill Leutwiler <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe it makes sense to add a new method like swap_and_remove(index: usize)
that swaps the element at index
with the last element and removes it(via pop
). It is very popular method to remove elements from the vector in Solidity
Co-authored-by: Green Baneling <[email protected]>
Signed-off-by: Cyrill Leutwiler <[email protected]>
@xgreenx I see, Just merged it to get it into the RC, but can do a follow up for adding a swap remove API anytime :) |
Summary
Provide a vector like data structure, built on top of
Mapping
.This allows to retrieve elements from the vector and grow the vector without loading and pushing all elements.
Description
Alternative: #1997
I favor this implementation slightly over #1997. It is less code and adds less contract size. The drawback is that here we have no iterators and no
Index
. However, I don't think iterators are really required. Also, #1997 provides binary search, however the vector needs to be sorted and this is kind of impossible if it grows too large.Checklist before requesting a review
CHANGELOG.md