#define NIL 0
#define ll long long
const int M=1046527;
ll T[M];//记得初始化
ll h1(ll key)
{
return key%M;
}
ll h2(ll key)
{
return 1+(key%(M-1));
}
ll h(ll key,ll i)
{
return (h1(key)+i*h2(key))%M;
}
void insert(string s)
{
ll i=0;
ll key=getKey(s);
while(true)
{
ll j=h(key,i);
if(T[j]==NIL)
{
T[j]=key;
return ;
}
else
{
i++;
}
}
}
ll search(string s)
{
ll i=0;
ll key=getKey(s);
while(true)
{
ll j=h(key,i);
if(T[j]==key)
{
return 1;
}
else if(T[j]==NIL||i>=M)
{
return 0;
}
else
{
i++;
}
}
}
C++ 关流:
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);