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]>
|
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]>
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]>
SkymanOne
left a comment
There was a problem hiding this comment.
LGTM! Just a small nit
| 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.
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.
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.
Yeah I missed that. Easy to do with a Cell though
There was a problem hiding this comment.
@SkymanOne added it together with a test
…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]>
xgreenx
left a comment
There was a problem hiding this comment.
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