资源简介
Hash函数集合,包含主流的hash函数: nginx_hash算法,OpenSSL_hash算法,RSHash,JSHash,PJWHash,ELFHash,BKDRHash,DJBHash,DEKHash,APHash等等!
代码片段和文件信息
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
Copyright 2008-2015 www.ku6.com
File name : HashFunction.h
Author :
Version : V00R001
Date :
Description : Hash函数集合,包含主流的hash函数
Struct List :
Function list:
History :
1. Date : 2008-10-25
Create :
Modification : create
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
#include “HashFunction.h“
#define ngx_hash(key c) ((u_int) key * 31 + c)
unsigned int ngx_hash_key(const std::string& data)
{
size_t len = data.size();
unsigned int i key;
key = 0;
for (i = 0; i < len; i++) {
key = ngx_hash(key data[i]);
}
return key;
}
//经典字符串Hash函数
unsigned int pub_inthash(const char *str)
{
register unsigned int h;
register unsigned char *p;
for(h=0 p = (unsigned char *)str; *p ; p++)
h = 31 * h + *p;
return h;
}
//PHP中出现的字符串Hash函数
unsigned long php_longhashpjw(const char* str)
{
unsigned long h = 0 g;
char *p;
for(h=0 p = (char *)str; *p ; p++)
{
h = (h << 4) + *p++;
if ((g = (h & 0xF0000000)))
{
h = h ^ (g >> 24);
h = h ^ g;
}
}
return h;
}
//OpenSSL中出现的字符串Hash函数
unsigned int OpenSSL_strhash1(const char *str)
{
int il;
unsigned int ret=0;
unsigned short *s;
if (str == NULL) return(0);
l=(strlen(str)+1)/2;
s=(unsigned short *)str;
for (i=0; i ret^=(s[i]<<(i&0x0f));
return(ret);
}
//MySql中出现的字符串Hash函数
unsigned int mysql_hashnr1(const char *keyunsigned int length)
{
register unsigned int nr=1 nr2=4;
while (length--)
{
nr^= (((nr & 63)+nr2)*((unsigned int) (unsigned char) *key++))+ (nr << 8);
nr2+=3;
}
return((unsigned int) nr);
}
unsigned int mysql_hashnr_caseup1(const char *keyunsigned int length)
{
register unsigned int nr=1 nr2=4;
while (length--)
{
nr^= (((nr & 63)+nr2)*((unsigned int) (unsigned char) toupper(*key++)))+ (nr << 8);
nr2+=3;
}
return((unsigned int) nr);
}
unsigned int mysql_hashnr2(const char *key unsigned int len)
{
const char *end=key+len;
unsigned int hash;
for (hash= 0; key < end; key++)
{
hash*= 16777619;
hash^= (unsigned int) *(unsigned char*) key;
}
return (hash);
}
unsigned int mysql_hashnr_caseup2(const char *key unsigned int len)
{
const char *end=key+len;
unsigned int hash;
for (hash= 0; key < end; key++)
{
hash*= 16777619;
hash^= (unsigned int) (unsigned char) toupper(*key);
}
return (hash);
}
/**
* 加法hash
* @param key 字符串
* @param prime 一个质数
* @return hash结果
*/
int additiveHash(const std::string& key int prime)
{
unsigned int ha
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 2171 2009-10-26 14:30 HashFunction.h
文件 7891 2009-10-26 14:30 HashFunction.cpp
----------- --------- ---------- ----- ----
10062 2
- 上一篇:HisiGpio.cpp
- 下一篇:二维码驱动C语言
评论
共有 条评论