hash小模板

#define MAX 1000010
struct
{
    int next,value,num;
}edge[MAX]; int e=0; int num=0;
int head[MAX]; 

int hash(int x)
{
    int h = x % MAX;
    for(int i = head[h]; i != -1; i = edge[i].next)
    {
        if(x == edge[i].value)
            return edge[i].num;
    }
    edge[e].value = x;
    edge[e].num = num++;
    edge[e].next = head[h];
    head[h] = e++;
    return (num - 1);
}

你可能感兴趣的:(hash小模板)