SegWord::IHash
来源:互联网 发布:简单重复的工作 知乎 编辑:程序博客网 时间:2024/05/08 16:41
#ifndef __IHASH_H__
#define __IHASH_H__
#include "../../include/UString.h"
using namespace UStr;
/*
* IHash接口及其默认实现:ELFhash算法(默认hash算法)
*************************************************************************/
const unsigned long MAX_HASHTABLE_SIZE = 100000; //默认hash表最大元素数
class IHash
{
public:
virtual void init(unsigned long MaxHashTableSize) = 0;
virtual unsigned long operator ()(UString& Str, Section& StrSect) = 0;
};
class ELFHash
:public IHash
{
public:
ELFHash()
{
_hashTableSize = MAX_HASHTABLE_SIZE;
}
void init(unsigned long MaxHashTableSize)
{
_hashTableSize = MaxHashTableSize;
if( 0 == _hashTableSize )
_hashTableSize = MAX_HASHTABLE_SIZE;
}
unsigned long operator ()(UString& Str, Section& StrSect)
{
register unsigned long h = 0, g = 0;
if( Str.length() < StrSect._sect._begin+StrSect._sect._length )
return h;//所给区间错误
wchar_t* pStr = Str.u_str()+StrSect._sect._begin;
unsigned int length = StrSect._sect._length;
unsigned int pos = 0;
while( *pStr && pos < length )
{
pos ++;
h = (h << 4) + *pStr++;
g = h & 0xF
if( g )
h ^= g>>24;
h &= ~g;
}
return h%_hashTableSize;
}
private:
unsigned long _hashTableSize;
};
#endif //__IHAS_H__
- SegWord::IHash
- SegWord项目介绍
- SegWord项目规划初稿
- SegWord讨论大本营
- 项目SegWord文件目录说明
- SegWord 的进展--词库结构
- SegWord中需要讨论的问题(1)
- SegWord中需要讨论的问题(2)
- SegWord::UString的待完全测试代码
- ASP.NET配置文件Web.config
- Global.asax以及Web应用的生命周期
- oracle数据安全面面观
- XML 问题: 超越 DOM
- 如何读取保存在数据库中的图片显示在DataGrid中
- SegWord::IHash
- 《多挣了三五千》
- Understand memory access characteristics of motion estimation algorithms
- 碰撞和卷轴
- 一步步教你如何编写Shell扩展
- 发一个仿QQ菜单的JS
- 三级下拉菜单 (通用版):
- 湖滨东路杀人事件
- 城里人和农村人