首页 > 其他 > 详细

HashTable 板子

时间:2019-09-29 22:10:15      阅读:113      评论:0      收藏:0      [点我收藏+]
struct HashTable {
    typedef ull T;
    typedef int S;
    static const int N = (int)1e6 + 7;
    static const int M = (int)1e5 + 7;
    int head[N], tot;
    struct Node {
        T fval;
        S sval;
        int nex;
    } a[M];
    void clear() {
        memset(head, -1, sizeof(head));
        tot = 0;
    }
    void insert(T fval, S sval) {
        int p = fval % N;
        a[tot].fval = fval;
        a[tot].sval = sval;
        a[tot].nex = head[p];
        head[p] = tot++;
    }
    S find(T fval) {
        int p = fval % N;
        for(int i = head[p]; ~i; i = a[i].nex) {
            if(a[i].fval == fval) return a[i].sval;
        }
        return -1;
    }
} Map;

 

HashTable 板子

原文:https://www.cnblogs.com/CJLHY/p/11609701.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!