
01.04.2008, 21:49
|
|
Участник форума
Регистрация: 07.06.2006
Сообщений: 146
Провел на форуме: 1652093
Репутация:
490
|
|
Пример вычисления хэшей
Код:
#include <stdio.h>
#include <string.h>
static inline long hash_php5(char *arKey, int nKeyLength)
{
long h = 5381;
char *arEnd = arKey + nKeyLength;
while (arKey < arEnd) {
h += (h << 5);
h += (long) *arKey++;
}
return h;
}
static inline long hash_php4(char *arKey, int nKeyLength)
{
long h = 5381;
char *arEnd = arKey + nKeyLength;
while (arKey < arEnd) {
h += (h << 5);
h ^= (long) *arKey++;
}
return h;
}
int main()
{
char *chr = "GALLERY_BASEDIR";
int len = strlen(chr)+1;
printf("%ld\n", hash_php5(chr, len));
printf("%ld\n", hash_php4(chr, len));
}
|
|
|