Если вопрос в том, как это уже где-нибудь сделано, то для строчек - вот, например, способ, которым пользуется Java (из комментариев в файле String.java):
* s[0]*31^(n-1) + s[1]*31^(n-2) + ... + s[n-1] * using int arithmetic, where s[i] is the * ith character of the string, n is the length of * the string, and ^ indicates exponentiation.
no subject
Date: 2006-02-09 07:57 pm (UTC)no subject
Date: 2006-02-09 07:57 pm (UTC)no subject
Date: 2006-02-09 07:59 pm (UTC)http://en.wikipedia.org/wiki/Hash_function
http://en.wikipedia.org/wiki/Cryptographic_hash_function
http://en.wikipedia.org/wiki/Hash_table
no subject
Date: 2006-02-09 08:06 pm (UTC)* s[0]*31^(n-1) + s[1]*31^(n-2) + ... + s[n-1]
* using
int
arithmetic, wheres[i]
is the* ith character of the string,
n
is the length of* the string, and
^
indicates exponentiation.