Hi , Can anybody explain me how map datastructure in golang is different from other programming languages.
Maybe the internals are different but the main idea is the same. A map is data structure which associate a key with a value.
You can find more information in https://blog.golang.org/go-maps-in-action
Thanks for your information,
I found some interesting thing about maps in golang in above url, i.e iteration order.
When we iterating over a map with a range loop, the iteration order is not specified and not guaranteed to be the same from one iteration to the next.
I tried below example:
Maps are hash maps in Go and like hash maps in other languages (e.g Java’s HashMap, C#'s Dictionary, Python’s dict (pre 3.6.0), C++'s hash_map, etc.) iterating over the keys and values is inherently unordered.
In many cases though, iteration order remains at least stable unless there happened writes between the reads. This is not the case for go though.
The implementation does randomize reading on purpose to “educate” the developer to not assume any order at any time.
This additional randomisation might have an impact on runtime performance compared to other languages. This is just an assumption though and nothing I were able to proof.
This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.