Hash

来源:互联网 发布:淘宝有什么好吃的水果 编辑:程序博客网 时间:2024/06/05 01:48
void Hash_table::clear()
{
for(int i=0;i<hash_size;i++)
table[i].clear();
}


Error_code Hash_table::insert(const Record &x)
{
int probe=hash(x);
for(int i=0;i<table[probe].size();i++)
{
Record temp;
table[probe].retrieve(i,temp);
if(temp==x)
return duplicate_error;
}
table[probe].insert(0,x);
return success;
}




Error_code Hash_table::retrieve(const Key &target, Record &found) const
{
int probe=hash(target);
for(int i=0;i<table[probe].size();i++)
{
Record temp;
table[probe].retrieve(i,temp);
if(temp==target)
{
found=temp;
return success;
}
}
return not_present;
}


Error_code Hash_table::remove(const Key &target, Record &found)
{
int probe=hash(target);
for(int i=0;i<table[probe].size();i++)
{
Record temp;
table[probe].retrieve(i,temp);
if(temp==target)
{
table[probe].remove(i,found);
return success;
}
return not_present;
}
}

0 0
原创粉丝点击