哈希表

#define ll long long
#define N 1000007

const unsigned long long SMod=1000007;
struct hashmap{
    struct Edge
    {
        long long num;
        int next;
    }edges[2*N];
    int tot;
    int head[SMod+100];

    void init(){
        memset(head,-1,sizeof(head));
        tot=0;
    }

    void insert(long long num){
        int start=num%SMod;
        edges[tot].next=head[start];
        edges[tot].num=num;
        head[start]=tot++;
    }

    int Find(long long num){
        int start=num%SMod;
        int ind;
        for(ind=head[start]; ind!=-1; ind=edges[ind].next){
            if(edges[ind].num==num)break;
        }
        return ind;
    }
}ST;

你可能感兴趣的:(哈希表)