开放地址法

在开放地址法中,所有的元素都存放在哈希表里,也就是,每个表项或包含动态集合的一个元素,或包含NIL
int locate(int s)
{
    int h;
    h=Hash(s);
    while (use[h]&&pst[h]!=s)
    {
        h++;
        if (h>=max) h-=max;
    }
    return h;
}

void insert(int s)
{
    int posi=locate(s);
    if (!use[posi])
    {
        use[posi]=1;
        pst[posi]=s;
    }
}
void delete(int s)
{
    int posi=locate(s);
    if (use[posi]&&psw[posi]==s)
        use[posi]=0;
}
bool search(int s)
{
    int posi=locate(s);
    if (use[posi]&&psw[posi]==s)
        return true;
    else
        return false;
}

ELFHash

unsigned int ELFHash(char *str)
{
	unsigned int hash = 0,x	= 0;
	while (*str)
	{
		hash = (hash << 4) + (*str++);
		if ((x = hash & 0xF0000000L) != 0)
		{
			hash ^= (x >> 24);
			hash &= ~x;
		}
	}
 
	return (hash & 0x7FFFFFFF);
}




原文地址:https://www.cnblogs.com/lgh1992314/p/5835026.html