Branch: Tag:

2016-06-24

2016-06-24 09:49:17 by Per Hedbor <ph@opera.com>

Renamed 'hash' to 'hash_7_8'

Hopefully it will not be used now (this is triggered by yet another
person thinking it's a good string hashing function).

The function is not really suitable for use. The returned values are
higly likely to be the same for similar strings, something that is not
optimal for hashing.

Also added comments about what to use instead (hash_value or one of
the cryptographic hash functions).

It might make sense to add a hash() that actually works, perhaps
siphash?

261:    *! This function is byte-order dependant for wide strings.    *!    *! @seealso -  *! @[hash()], @[hash_7_0] +  *! @[hash_7_6()], @[hash_7_0]    */   static void f_hash_7_4(INT32 args)   {
357:    push_int( i );   }    - /*! @decl int hash(string s) -  *! @decl int hash(string s, int max) + /*! @decl int hash_7_8(string s) +  *! @decl int hash_7_8(string s, int max)    *!    *! Return an integer derived from the string @[s]. The same string    *! always hashes to the same value, also between processes,
368:    *! If @[max] is given, the result will be >= 0 and < @[max],    *! otherwise the result will be >= 0 and <= 0x7fffffff.    *! +  *! @deprecated +  *! +  *! Use @[hash_value()] for in-process hashing (eg, for implementing +  *! @[lfun::_hash()]) or one of the cryptographic hash functions. +  *!    *! @note -  +  *! This function is really bad at hashing strings. Similar string +  *! often return similar hash values. +  *! +  *! It is especially bad for url:s, paths and similarly formatted +  *! strings. +  *! +  *! @note    *! The hash algorithm was changed in Pike 7.5. If you want a hash    *! that is compatible with Pike 7.4 and earlier, use @[hash_7_4()].    *! The difference only affects wide strings.
383:    *! @seealso    *! @[hash_7_0()], @[hash_7_4()], @[hash_value]    */ - PMOD_EXPORT void f_hash(INT32 args) + PMOD_EXPORT void f_hash_7_8(INT32 args)   {    size_t i = 0;    struct pike_string *s;
437:    *! This is the hashing method used by mappings.    *!    *! @seealso -  *! @[hash()], @[lfun::__hash()] +  *! @[lfun::__hash()]    */   void f_hash_value(INT32 args)   {
9364:    OPT_TRY_OPTIMIZE);       /* function(string,int|void:int) */ -  ADD_EFUN("hash",f_hash,tFunc(tStr tOr(tInt,tVoid),tInt),OPT_TRY_OPTIMIZE); +  ADD_EFUN("hash_7_8", f_hash_7_8, +  tAttr("deprecated",tFunc(tStr tOr(tInt,tVoid),tInt)),OPT_TRY_OPTIMIZE);       ADD_EFUN("hash_7_0",f_hash_7_0, -  tFunc(tStr tOr(tInt,tVoid),tInt),OPT_TRY_OPTIMIZE); +  tAttr("deprecated",tFunc(tStr tOr(tInt,tVoid),tInt)),OPT_TRY_OPTIMIZE);       ADD_EFUN("hash_7_4",f_hash_7_4, -  tFunc(tStr tOr(tInt,tVoid),tInt),OPT_TRY_OPTIMIZE); +  tAttr("deprecated",tFunc(tStr tOr(tInt,tVoid),tInt)),OPT_TRY_OPTIMIZE);       ADD_EFUN("hash_value",f_hash_value,tFunc(tMix,tInt),OPT_TRY_OPTIMIZE);