How map in golang different from other pregramming languages

Hi , Can anybody explain me how map datastructure in golang is different from other programming languages.

1 Like

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

1 Like

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:
https://play.golang.org/p/A2Cibmo6CTj

2 Likes

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.

1 Like

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.

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.