hash模板

打了一个最基础的hash模板

class Hash {
	static const int HASHMOD = 7679977;
	int top = 0, hash[HASHMOD + 100], value[HASHMOD + 100], stack[1 << 16];
	int locate (const int x) const {
		int h = x % HASHMOD;
		while (hash[h] != -1 && hash[h] != x) ++ h;
		return h;
	}
	public:
		Hash () : top (0) {memset (hash, 0xFF, sizeof (hash));}
		void insert (const int x, const int v) {
			const int h = locate (x);
			if (hash[h] == -1) hash[h] = x, value[h] = v, stack[++ top] = h;
		}
		int get (const int x) const {
			const int h = locate (x);
			return hash[h] == x ? value[h] : -1;
		}
		void clear () {while (top) hash[stack[top --]] = -1;}
}hash;

原文地址:https://www.cnblogs.com/binghun/p/P16281.html