On Tue, Nov 10, 2020 at 7:57 PM 'Kilos' via golang-nuts < golang-nuts@googlegroups.com> wrote:
> For Dan: > I have an idea that the cause is in the runtime function mapiternext. > The runtime calls mapiternext function to choose next bucket to iterate by > index, > if we put a key-value into a bucket which already be iterated, then the > for-range will not iterate it again, > so the new key-value will not be printed. > But I don't know this idea is true or false. > Your idea (hypothesis) is basically correct. However, note that it doesn't really matter that Go implements maps using a hash function and a list+bucket data structure or another data structure (e.g., a tree). You cannot safely iterate over a map, in any language, while concurrently mutating the map unless the implementation explicitly says that is okay and documents the semantics. Go expressly says you cannot expect predictable behavior when doing so. -- Kurtis Rader Caretaker of the exceptional canines Junior and Hank -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/CABx2%3DD__v1Bzp9jA478L-2WYqDf%2BTM2CPyT3WJQBacNEZTquTw%40mail.gmail.com.