Article From:

Why is the set function sorted when the number is smaller? Is set not a disorder?

    {1, 3, 4, 5}

    {0, 2, 4, 6, 9}

>> set([9,4,7,2,23,7,99])
    {2, 99, 4, 7, 9, 23}

Answer 0:

PythonThe dictionary and collection are all implemented based on hash table technology.
I tried it. According to the result, I guess:
Create a collection. When the number of elements is not more than 32, the hash function iskey mod 32(The number is used as hash address, then the open address method is used to resolve the conflict. Therefore, as long as the figure is less than 32, it will be orderly.
——Split line –
The initial hash table is 32. When the load factor exceeds 2/3, that is, the number of elements is more than 20, the larger hash table is automatically replaced. Here I try to extend the length to 128, and the hash functions seem to be allkey mod n,The N here is the length of the Hash list.

Leave a Reply

Your email address will not be published. Required fields are marked *