Loading…
![]() String updated in the repository |
|
![]() Translation changed |
|
![]() String updated in the repository |
|
![]() String updated in the repository |
|
Precisely, dictionaries use a [i]hashing algorithm[/i]. Hashing algorithms convert one value into another.
In this case, hashing consists of converting a given key into a unique whole number. The dictionary then uses that number as an array's index!
That's how a dictionary works: when you give it a key, it converts it into a unique index and uses that index to retrieve the corresponding value in the computer's memory.
That's also why you can't have the same key twice: it would map to the same array index, causing you to overwrite an existing value.
ados o [i]associative arrays[/i]. Umatrices asociativas[/i]. Bajo el capó, utilizan matrices y varias funciones para almacenar y recuperar de forma eficiente valoresden matricesde forma eficiente.Precisamente, los diccionarios utilizan un [i]
hashing algorithmalgoritmo hash[/i]. Los algoritmosdehashingconvierten un valor en otro.En este caso, el [i]hashing[/i] consiste en convertir una clave dada en un número entero único.
A continuación, e¡El diccionario luego utiliza ese número como índice de una matriz.!Así es como funciona un diccionario: cuando le das una clave, la convierte en un índice único y utiliza ese índice para recuperar el valor correspondiente en la memoria de
l ordenla computadora.Por eso no seEsa es también la razón por la que no puedes tener la misma clave dos veces: seasignmapearía al mismo índice de matrizy, lo que haría que se sobrescribiería un valor existente.