Swift - what determines the order of a Dictionary Collection?

后端 未结 1 591
别跟我提以往
别跟我提以往 2021-01-18 18:43

When I say order - I mean the order that the compiler chooses to display the results, I know that a dictionary has no index like an array does.

I have the following

相关标签:
1条回答
  • 2021-01-18 19:25

    Dictionarys operate on Hashable keys and are implemented using a hash table, a frequently used way to represent associative arrays with O(1) lookup. Hash Tables are usually sorted by the integer value of the hash code for small numbers of key-value-pairs (below the bucket threshold), and after that in reverse insertion order. This means you cannot rely on hash tables to be sorted in any reasonable or predictable order in most cases.

    0 讨论(0)
提交回复
热议问题