Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Align StorageMap interface more with Rust's {Hash,BTree}Map #4839

Closed
apopiak opened this issue Feb 6, 2020 · 6 comments
Closed

Align StorageMap interface more with Rust's {Hash,BTree}Map #4839

apopiak opened this issue Feb 6, 2020 · 6 comments
Assignees
Labels
I7-refactor Code needs refactoring. Z1-easy Can be fixed primarily by duplicating and adapting code by an intermediate coder
Milestone

Comments

@apopiak
Copy link
Contributor

apopiak commented Feb 6, 2020

The interface of StorageMap mostly keeps to the interface of Rust's HashMap and BTreeMap except that it renames contains_key to exists.

I think it would make sense to either rename the function to the Rust name (contains_key) or create an alias.

@apopiak apopiak changed the title Align StorageMap interface more with Rust's {Hash, BTree}Map Align StorageMap interface more with Rust's {Hash,BTree}Map Feb 6, 2020
@bkchr bkchr added the I7-refactor Code needs refactoring. label Feb 6, 2020
@bkchr bkchr added this to the 2.0 milestone Feb 6, 2020
@bkchr bkchr added the Z1-easy Can be fixed primarily by duplicating and adapting code by an intermediate coder label Feb 6, 2020
@bkchr
Copy link
Member

bkchr commented Feb 6, 2020

Will you want to do this @apopiak? As discussed in Riot, this should be done in a timely manner.
I don't think that anyone has any problems with this change.

@apopiak
Copy link
Contributor Author

apopiak commented Feb 6, 2020

Yep, will take on.

@apopiak
Copy link
Contributor Author

apopiak commented Feb 17, 2020

I'm sorry to do this now instead of earlier, but I noticed another discrepancy:
StorageMap::take is called
HashMap::remove in the original, while StorageMap::remove doesn't really have an equivalent (you just remove and drop the value).
HashMap::take does not exist, but HashMap::drain()::take() does which could lead to confusion.

@apopiak apopiak reopened this Feb 17, 2020
@apopiak
Copy link
Contributor Author

apopiak commented Feb 17, 2020

Also it's not a huge deal, but you remove a StorageValue with kill and a StorageMap entry with remove.

@bkchr
Copy link
Member

bkchr commented Feb 17, 2020

I'm sorry to do this now instead of earlier, but I noticed another discrepancy:
StorageMap::take is called
HashMap::remove in the original, while StorageMap::remove doesn't really have an equivalent (you just remove and drop the value).
HashMap::take does not exist, but HashMap::drain()::take() does which could lead to confusion.

I think this is fine, that is just something where we diverge from a default hashmap.

Also it's not a huge deal, but you remove a StorageValue with kill and a StorageMap entry with remove.

I would expect that StorageMap::kill would remove the whole data structure (currently this function is called remove_all).

@apopiak
Copy link
Contributor Author

apopiak commented Feb 17, 2020

I think this is fine, that is just something where we diverge from a default hashmap.

ok

I would expect that StorageMap::kill would remove the whole data structure (currently this function is called remove_all).

right, makes sense

@apopiak apopiak closed this as completed Feb 17, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
I7-refactor Code needs refactoring. Z1-easy Can be fixed primarily by duplicating and adapting code by an intermediate coder
Projects
None yet
Development

No branches or pull requests

2 participants