feat: implement entry for BTreeMap similar to std lib#420
feat: implement entry for BTreeMap similar to std lib#420hpeebles wants to merge 17 commits intodfinity:mainfrom
entry for BTreeMap similar to std lib#420Conversation
|
|
|
|
|
|
# Conflicts: # src/btreemap.rs
This allows you to lookup an entry by searching the map, then modify the value and insert it back into the map without having to search again.
The API is similar to
entryon the std libBTreeMap, but is not able to return mutable references, so you need to either useand_modifyor get the owned value, update it, then insert it back in the entry.For example in the std lib you would write this
Or using the shorthand syntax
Whereas using this new API for
StableBTreeMapyou would write it as thisOr using the shorthand syntax
I've added some benchmarks which compare using
gettheninsertvs usingentryfor 10k u32 values, from the results you can see that in this scenario usingentryis roughly 37% faster