Skip to content
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

support map.size(),map.clear(),for(var k in map) #87

Closed
liuzhangjie opened this issue Apr 21, 2018 · 3 comments
Closed

support map.size(),map.clear(),for(var k in map) #87

liuzhangjie opened this issue Apr 21, 2018 · 3 comments
Assignees

Comments

@liuzhangjie
Copy link

in smart contract,in fact,there are no methods to get the size of map,take visit to a map and delete some elements in a map.so I wish something better can occur to solve these problems.

@royshang
Copy link
Contributor

Good Suggestion. Map iterator has been included in our Go-Nebulas V1.1.0. This version will be released at the middle of May, 2018.

@ChengOrangeJu
Copy link
Contributor

@liuzhangjie Could you help update the status of this issue? Thanks!

@liuzhangjie
Copy link
Author

add a counter k-counter,initial k-counter = 0
use two maps indexMap and dataMap,as you want to use set/put method to storage the k-v,you can do like this:first indexMap.put(k-counter,key);k-counter += 1; then dataMap.put(key,value);
after you use this way to storage the k-v,you can easily get the size of the map,that is the k-counter,and use : for(var i=0;i<k-counter;i++){
var k = indexMap.get(i);
var data = dataMap.get(k);
}
to iterate the map.Also,you can use this way to clear the map

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants