¿Podría alguien arrojar algo de luz sobre la función/algoritmo hash que Perl utiliza para asignar una cadena a un índice? ¿Alguna lectura relevante?¿Qué función/algoritmo hash usa Perl?
9
A
Respuesta
15
PERL_HASH_INTERNAL_
, definido en hv.h
, copiado a continuación:
/* hash a key */
/* FYI: This is the "One-at-a-Time" algorithm by Bob Jenkins
* from requirements by Colin Plumb.
* (http://burtleburtle.net/bob/hash/doobs.html) */
/* The use of a temporary pointer and the casting games
* is needed to serve the dual purposes of
* (a) the hashed data being interpreted as "unsigned char" (new since 5.8,
* a "char" can be either signed or unsigned, depending on the compiler)
* (b) catering for old code that uses a "char"
*
* The "hash seed" feature was added in Perl 5.8.1 to perturb the results
* to avoid "algorithmic complexity attacks".
*
* If USE_HASH_SEED is defined, hash randomisation is done by default
* If USE_HASH_SEED_EXPLICIT is defined, hash randomisation is done
* only if the environment variable PERL_HASH_SEED is set.
* For maximal control, one can define PERL_HASH_SEED.
* (see also perl.c:perl_parse()).
*/
#define PERL_HASH_INTERNAL_(hash,str,len,internal) \
STMT_START { \
register const char * const s_PeRlHaSh_tmp = str; \
register const unsigned char *s_PeRlHaSh = (const unsigned char *)s_PeRlHaSh_tmp; \
register I32 i_PeRlHaSh = len; \
register U32 hash_PeRlHaSh = (internal ? PL_rehash_seed : PERL_HASH_SEED); \
while (i_PeRlHaSh--) { \
hash_PeRlHaSh += *s_PeRlHaSh++; \
hash_PeRlHaSh += (hash_PeRlHaSh << 10); \
hash_PeRlHaSh ^= (hash_PeRlHaSh >> 6); \
} \
hash_PeRlHaSh += (hash_PeRlHaSh << 3); \
hash_PeRlHaSh ^= (hash_PeRlHaSh >> 11); \
(hash) = (hash_PeRlHaSh + (hash_PeRlHaSh << 15)); \
} STMT_END
Cuestiones relacionadas
- 1. ¿Qué función hash usa Ruby?
- 2. ¿Qué tipo de hash usa WordPress?
- 3. ¿Qué sabor POSIX de regex usa Perl?
- 4. Constantes hash en Perl
- 5. Perl hash Data :: Dumper
- 6. Perl Hash de subfunciones
- 7. Perl, convertir hash a matriz
- 8. ¿Está% $ var desreferenciando un hash Perl?
- 9. ¿Qué shell usa una llamada a Perl system()?
- 10. ¿Por qué Perl se usa comúnmente para escribir scripts CGI?
- 11. ¿Por qué mi Perl Regex usa tanta memoria?
- 12. ¿Por qué Programming Perl usa local (no my) para filehandles?
- 13. ¿Debo usar $ hash {"string"} o $ hash {string} en Perl?
- 14. Cómo borrar un hash de Perl
- 15. En Perl, ¿cómo proceso un hash completo?
- 16. ¿Cómo reemplazar una clave hash Perl?
- 17. Perl: subprocesamiento con hash multidimensional compartido
- 18. Atravesar un hash multidimensional en Perl
- 19. ¿Perl garantiza devolución de claves hash ordenadas?
- 20. hash de construcción dinámica/recursiva en Perl?
- 21. Perl, obtenga todos los valores hash
- 22. ¿Cómo se usa SQLite en Perl 6?
- 23. ¿Cómo se usa sed de Perl?
- 24. tienda y leer hash y matriz en archivos en Perl
- 25. ¿Qué algoritmo de expresión regular usa PHP?
- 26. ¿Qué es hash exactamente?
- 27. ¿Cómo creo un hash de hashes en Perl?
- 28. ¿Usa SHA-512 y salt para hash una contraseña hash MD5?
- 29. ¿Por qué md5 todavía se usa ampliamente?
- 30. Perl ¿Cómo recupero una matriz de un hash de matrices?
¿Qué estás tratando de hacer? ¿Puedes dar un ejemplo de algún código que no funciona? –
Cualquier tecla que genere una colisión :) – Jean
No hay dos claves que siempre colisionen. El hashing se altera al azar cuando es necesario. – ikegami