A Simple Hash Class(one)
来源:互联网 发布:淘宝评价是显示几个月 编辑:程序博客网 时间:2024/06/06 09:35
/**//*
Name: hash class
Copyright: all right reserved @ lizuding@gmail.com
Author: lizuding@gmail.com
Date: 23-01-08 14:25
Description: hash class
*/
class Hash
...{
public:
Hash();
~Hash();
void add(string key);
int find(string key);
protected:
static const int DEFAULT_SIZE = 10;
int hash(const string & key);
int rehash(const int pseudo_pos);
private:
string *m_pData;
};
Hash::Hash() ...{
m_pData = new string[DEFAULT_SIZE];
for (int i = 0; i < DEFAULT_SIZE; ++ i)
m_pData[i] = "";
}
Hash::~Hash() ...{ delete[] m_pData; }
void Hash::add(string key) ...{
int pos = hash(key);
if ( m_pData[pos] != "" )
pos = rehash(pos);
m_pData[pos] = key;
}
int Hash::find(string key) ...{
int pos = hash(key);
while ( m_pData[pos] != key )
pos = ++pos % DEFAULT_SIZE;
return pos;
}
int Hash::hash(const string & key) ...{
return key.c_str()[0] - 'A';
}
int Hash::rehash(int pseudo_pos) ...{
do ...{
pseudo_pos = ++ pseudo_pos % DEFAULT_SIZE;
}while (m_pData[pseudo_pos] != "");
return pseudo_pos;
}
Name: hash class
Copyright: all right reserved @ lizuding@gmail.com
Author: lizuding@gmail.com
Date: 23-01-08 14:25
Description: hash class
*/
class Hash
...{
public:
Hash();
~Hash();
void add(string key);
int find(string key);
protected:
static const int DEFAULT_SIZE = 10;
int hash(const string & key);
int rehash(const int pseudo_pos);
private:
string *m_pData;
};
Hash::Hash() ...{
m_pData = new string[DEFAULT_SIZE];
for (int i = 0; i < DEFAULT_SIZE; ++ i)
m_pData[i] = "";
}
Hash::~Hash() ...{ delete[] m_pData; }
void Hash::add(string key) ...{
int pos = hash(key);
if ( m_pData[pos] != "" )
pos = rehash(pos);
m_pData[pos] = key;
}
int Hash::find(string key) ...{
int pos = hash(key);
while ( m_pData[pos] != key )
pos = ++pos % DEFAULT_SIZE;
return pos;
}
int Hash::hash(const string & key) ...{
return key.c_str()[0] - 'A';
}
int Hash::rehash(int pseudo_pos) ...{
do ...{
pseudo_pos = ++ pseudo_pos % DEFAULT_SIZE;
}while (m_pData[pseudo_pos] != "");
return pseudo_pos;
}
- A Simple Hash Class(one)
- A simple perl class
- A simple Complex class
- A simple C++ complex class
- A simple IOCP Server/Client Class
- A simple C# generic singleton class
- A simple IOCP Server/Client Class
- A simple IOCP Server/Client Class
- 《A Simple IOCP Server/Client Class》整改
- 《A Simple IOCP Server/Client Class》整改
- A simple IOCP Server/Client Class
- A simple IOCP Server/Client Class
- A simple IOCP Server/Client Class(转)
- A Simple Win32 Window Wrapper Class
- A simple IOCP Server/Client Class
- A simple IOCP Server/Client Class
- A simple IOCP Server/Client Class
- A simple IOCP Server/Client Class
- 串口通讯程序(中断方式)
- 数据结构——基本数据结构之有根树
- CEO、COO、CFO、CTO是什么意思
- ASP.net中动态加载控件时一些问题的总结
- 模拟 Tapestry 3.0 Application 运行
- A Simple Hash Class(one)
- 新年感恩,35G海量资源共享!(Maze系统不稳,暂停共享,见谅)
- 博客开通了!!!!!
- 转载:Socket I/O模型全接触
- [ASP.NET2.0]二个自己定义控件之间的传值
- 守好最后防线 企业电子文档加密系统综述
- 关闭dwr日志
- Eclipse中起动Weblogic 报错 java.lang.OutOfMemoryError
- C++中的重载、覆盖(override,改写)与隐藏(遮蔽)