hash.h
来自「著名的LZW压缩和解压的C++实现」· C头文件 代码 · 共 63 行
H
63 行
#ifndef HASH_H
#define HASH_H
const int D=4099;
struct part
{
int code;
unsigned long key;
};
struct element
{
int prefix;
unsigned char suffix;
};
struct hashnode
{
int code;
unsigned long key;
hashnode* link;
};
void insert(hashnode h[D],part e)
{
int i=e.key%D;
if(h[i].link==NULL)
{
h[i].link=new hashnode;
h[i].link->code=e.code;
h[i].link->key=e.key;
h[i].link->link=NULL;
}
else{
for(hashnode* p=h[i].link;p->link!=NULL;p=p->link);
p->link=new hashnode;
p->link->code=e.code;
p->link->key=e.key;
p->link->link=NULL;
}
}
bool search(hashnode h[D],unsigned long k, int &code)
{
int i=k%D;
hashnode* p=h[i].link;
while(p!=NULL)
{
if(k==p->key)
{
code=p->code;
return true;
}
p=p->link;
}
return false;
}
#endif
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?