-неизвестно

 -Поиск по дневнику

Поиск сообщений в ATUM

 -Подписка по e-mail

 

 -Постоянные читатели

 -Статистика

Статистика LiveInternet.ru: показано количество хитов и посетителей
Создан: 17.02.2006
Записей:
Комментариев:
Написано: 1139


hashCode

+ в цитатник

Cообщение скрыто для удобства комментирования.
Прочитать сообщение


troodon   обратиться по имени Вторник, 28 Июня 2011 г. 13:17 (ссылка)
http://www.cse.yorku.ca/~oz/hash.html
Ответить С цитатой В цитатник
troodon   обратиться по имени Вторник, 28 Июня 2011 г. 13:17 (ссылка)
sdbm

this algorithm was created for sdbm (a public-domain reimplementation of ndbm) database library. it was found to do well in scrambling bits, causing better distribution of the keys and fewer splits. it also happens to be a good general hashing function with good distribution. the actual function is hash(i) = hash(i - 1) * 65599 + str[i]; what is included below is the faster version used in gawk. [there is even a faster, duff-device version] the magic constant 65599 was picked out of thin air while experimenting with different constants, and turns out to be a prime. this is one of the algorithms used in berkeley db (see sleepycat) and elsewhere.

static unsigned long
sdbm(str)
unsigned char *str;
{
unsigned long hash = 0;
int c;

while (c = *str++)
hash = c + (hash << 6) + (hash << 16) - hash;

return hash;
}
Ответить С цитатой В цитатник
troodon   обратиться по имени Вторник, 28 Июня 2011 г. 13:18 (ссылка)
djb2

this algorithm (k=33) was first reported by dan bernstein many years ago in comp.lang.c. another version of this algorithm (now favored by bernstein) uses xor: hash(i) = hash(i - 1) * 33 ^ str[i]; the magic of number 33 (why it works better than many other constants, prime or not) has never been adequately explained.


unsigned long
hash(unsigned char *str)
{
unsigned long hash = 5381;
int c;

while (c = *str++)
hash = ((hash << 5) + hash) + c; /* hash * 33 + c */

return hash;
}
Ответить С цитатой В цитатник
Комментировать — К дневнику — Страницы: [1] [Новые]
 

Добавить комментарий:
Текст комментария: смайлики

Проверка орфографии: (найти ошибки)

Прикрепить картинку:

 Переводить URL в ссылку
 Подписаться на комментарии
 Подписать картинку