Unknown World
Never Give Up
条新通知
登录
注册
欢迎
退出
我的博客
配置
写文章
文章管理
博客首页
全站
当前博客
空间
博客
好友
相册
留言
用户操作
[留言]
[发消息]
[加为好友]
订阅我的博客
[编辑]
skywalker_nick的公告
<DIV><EMBED src=http://media.bbn.com.cn/ztzj/061230/三国演义.mp3 width=0 height=0 type=audio/mpeg loop=\"-1\" autostart=\"true\"></EMBED></DIV>
[编辑]
文章分类
Algorithms
Desktop Linux
Flex 1.5
Java Server Page
Linux系统开发
QT GUI
编程技巧
嵌入式系统开发(Linux+ARM)
数据结构及应用
数据库原理与开发
杂七杂八
[编辑]
All about Linux
IBM的Linux文档库
Linux Kernel Cross Reader
Linux Kernel Documentation Project
Linux Kernel Map
Linux初始内核学习
Linux大学在线系统资源
The Linux Kernel API
内核之旅
[编辑]
Bibs and Bobs
ARM Information Center
Datasheet Search
嵌入式导航
类Unix系统发行检索
存档
2009年09月(1)
2009年06月(1)
2009年01月(1)
2008年12月(10)
2008年11月(6)
2008年08月(4)
2008年03月(2)
2008年01月(3)
2007年12月(1)
2007年11月(3)
2007年10月(9)
2007年09月(8)
2007年08月(1)
2007年07月(4)
2007年06月(12)
2005年12月(6)
Hash Functions
收藏
public
class
AdditiveFunction
implements
HashFunction {
/* (non-Javadoc)
* @see spellChecker.util.hash.HashFunction#getHashCode(java.lang.Object)
*/
@Override
public
int
getHashCode(Object obj) {
// TODO Auto-generated method stub
if
(!(obj
instanceof
char
[])) {
return
0
;
}
char
[] key = (
char
[])obj;
int
hash =
0
;
for
(
int
i =
0
; i < key.length; i++) {
hash += i * key[i];
}
return
hash;
}
}
public
class
APFunction
implements
HashFunction {
/* (non-Javadoc)
* @see spellChecker.util.hash.HashFunction#getHashCode(java.lang.Object)
*/
@Override
public
int
getHashCode(Object obj) {
// TODO Auto-generated method stub
if
(!(obj
instanceof
char
[])) {
return
0
;
}
char
[] key = (
char
[])obj;
int
hash =
0xAAAAAAAA
;
for
(
int
i =
0
; i < key.length; i++) {
if
((i &
1
) ==
0
) {
hash ^= ((hash <<
7
) ^ key[i] ^ (hash >>
3
));
}
else
{
hash ^= (~((hash <<
11
) ^ key[i] ^ (hash >>
5
)));
}
}
return
hash;
}
}
public
class
BKDRFunction
implements
HashFunction {
/* (non-Javadoc)
* @see spellChecker.util.hash.HashFunction#getHashCode(java.lang.Object)
*/
@Override
public
int
getHashCode(Object obj) {
// TODO Auto-generated method stub
if
(!(obj
instanceof
char
[])) {
return
0
;
}
char
[] key = (
char
[])obj;
int
seed =
131
;
//31 131 1313 13131 131313 etc..
int
hash =
0
;
for
(
int
i =
0
; i < key.length; i++) {
hash = hash * seed + key[i];
}
return
hash;
}
}
public
class
DEKFunction
implements
HashFunction {
/* (non-Javadoc)
* @see spellChecker.util.hash.HashFunction#getHashCode(java.lang.Object)
*/
@Override
public
int
getHashCode(Object obj) {
// TODO Auto-generated method stub
if
(!(obj
instanceof
char
[])) {
return
0
;
}
char
[] key = (
char
[])obj;
int
hash = key.length;
for
(
int
i =
0
; i < key.length; i++) {
hash = ((hash <<
5
) ^ (hash >>
27
)) ^ key[i];
}
return
hash;
}
}
public
class
DJBFunction
implements
HashFunction {
/* (non-Javadoc)
* @see spellChecker.util.hash.HashFunction#getHashCode(java.lang.Object)
*/
@Override
public
int
getHashCode(Object obj) {
// TODO Auto-generated method stub
if
(!(obj
instanceof
char
[])) {
return
0
;
}
char
[] key = (
char
[])obj;
int
hash =
5381
;
for
(
int
i =
0
; i < key.length; i++) {
hash += (hash <<
5
) + key[i];
}
return
hash;
}
}
public
class
ELFFunction
implements
HashFunction {
/* (non-Javadoc)
* @see spellChecker.util.hash.HashFunction#getHashCode(java.lang.Object)
*/
@Override
public
int
getHashCode(Object obj) {
// TODO Auto-generated method stub
if
(!(obj
instanceof
char
[])) {
return
0
;
}
char
[] key = (
char
[])obj;
int
hash =
0
;
long
x =
0
;
for
(
int
i =
0
; i < key.length; i++) {
hash = (hash <<
4
) + key[i];
if
((x = hash & 0xF0000000L) !=
0
) {
hash ^= (x >>
24
);
hash &= ~x;
}
}
return
hash;
}
}
public
class
JSFunction
implements
HashFunction {
/* (non-Javadoc)
* @see spellChecker.util.hash.HashFunction#getHashCode(java.lang.Object)
*/
@Override
public
int
getHashCode(Object obj) {
// TODO Auto-generated method stub
if
(!(obj
instanceof
char
[])) {
return
0
;
}
char
[] key = (
char
[])obj;
int
hash =
1315423911
;
for
(
int
i =
0
; i < key.length; i++) {
hash ^= ((hash <<
5
) + key[i] + (hash >>
2
));
}
return
hash;
}
}
public
class
PJWFunction
implements
HashFunction {
/*
* (non-Javadoc)
*
* @see spellChecker.util.hash.HashFunction#getHashCode(java.lang.Object)
*/
@Override
public
int
getHashCode(Object obj) {
// TODO Auto-generated method stub
if
(!(obj
instanceof
char
[])) {
return
0
;
}
char
[] key = (
char
[])obj;
int
BitsInUnignedInt =
32
;
int
ThreeQuarters = (
int
)((BitsInUnignedInt *
3
) /
4
);
int
OneEighth = (
int
)(BitsInUnignedInt /
8
);
int
HighBits = (
int
)(
0xFFFFFFFF
) << (BitsInUnignedInt - OneEighth);
int
hash =
0
;
int
test =
0
;
for
(
int
i =
0
; i < key.length; i++) {
hash = (hash << OneEighth) + key[i];
if
((test = hash & HighBits) !=
0
)
{
hash = ((hash ^ (test >> ThreeQuarters)) & (~HighBits));
}
}
return
hash;
}
}
public
class
RSFunction
implements
HashFunction {
/* (non-Javadoc)
* @see spellChecker.util.hash.HashFunction#getHashCode(java.lang.Object)
*/
@Override
public
int
getHashCode(Object obj) {
// TODO Auto-generated method stub
int
b =
378551
;
int
a =
63689
;
int
hash =
0
;
if
(!(obj
instanceof
char
[])) {
return
0
;
}
char
[] key = (
char
[])obj;
for
(
int
i =
0
; i < key.length; i++) {
hash = hash * a + key[i];
a = a * b;
}
return
hash;
}
}
public
class
SDBMFunction
implements
HashFunction {
/* (non-Javadoc)
* @see spellChecker.util.hash.HashFunction#getHashCode(java.lang.Object)
*/
@Override
public
int
getHashCode(Object obj) {
// TODO Auto-generated method stub
if
(!(obj
instanceof
char
[])) {
return
0
;
}
char
[] key = (
char
[])obj;
int
hash =
0
;
for
(
int
i =
0
; i < key.length; i++) {
hash = key[i] + (hash <<
6
) + (hash <<
16
) - hash;
}
return
hash;
}
}
发表于 @ 2008年12月16日 03:48:00 |
评论(
loading...
)
|
编辑
|
举报
|
收藏
旧一篇:Levenshtein Distance
|
新一篇:Linux内核编译选项
查看最新精华文章 请访问博客首页
相关文章
发表评论
表 情:
评论内容:
用 户 名:
登录
注册
匿名评论
验 证 码:
重新获得验证码