-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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 upsert and destroy also to vector #6860
Conversation
You know what? At current gas pricing policy, I think best gas optimized way was create a trash bin, Then throw the vector to the trash bin forever, After that, Wait for a Aptos Governance Proposal to delete the trash bin. |
We have a smart vector coming that is much more gas efficient: #6823. There's some benchmarking there |
@@ -77,6 +77,38 @@ module aptos_std::simple_map { | |||
vector::push_back(&mut map.data, Element { key, value }); | |||
} | |||
|
|||
public inline fun upsert<Key: store, Value: store>( |
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.
What is the tradeoff between this vs having a non-inline function that returns the old values (as Option and Option)?
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 think key should be
drop + store
and value should also bestore + drop
. REturn an Option that is not droppable seems useless in practice. At least, this is whatTable
looks like now. - This function is so long that seems not worth an inline function.
|
||
public inline fun destroy<Key: store, Value: store>( | ||
map: SimpleMap<Key, Value>, | ||
d: |Key, Value| |
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.
What do you think about developer experience passing along a drop function? Is it weird at all?
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.
Yes, I think both functions may just want drop
kvs. for undroppable kvs, user should handle them carefully with their own logic since a lambda doesn't help much in that case.
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 think for destroy it's fine. I wrote two upserts one with drop lambda, one returning an optional
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.
How is a lambda not helping?
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 highly recommend to add type constraints with drop
and remove lambdas...
@@ -77,6 +77,38 @@ module aptos_std::simple_map { | |||
vector::push_back(&mut map.data, Element { key, value }); | |||
} | |||
|
|||
public inline fun upsert<Key: store, Value: store>( |
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 think key should be
drop + store
and value should also bestore + drop
. REturn an Option that is not droppable seems useless in practice. At least, this is whatTable
looks like now. - This function is so long that seems not worth an inline function.
|
||
public inline fun destroy<Key: store, Value: store>( | ||
map: SimpleMap<Key, Value>, | ||
d: |Key, Value| |
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.
Yes, I think both functions may just want drop
kvs. for undroppable kvs, user should handle them carefully with their own logic since a lambda doesn't help much in that case.
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.
Awesome~
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
✅ Forge suite
|
✅ Forge suite
|
✅ Forge suite
|
Description
Adding upsert to simple map. It's tricky and can only be done with inline functions and lambdas.
Also added destroy to simple map and vector
Test Plan
Unit tests should suffice here