hash table(全域散列法实现的哈希表)
利用每次重建哈希表时随机生成散列函数
#ifndef C11LEARN_HASHUNIVERSAL_H
#define C11LEARN_HASHUNIVERSAL_H
#include "Chain.h"
#include "../tools/random.h"
template<typename T>
class HashUniversal
{
protected:
Chain<T>** array;
int capacity;
long long large_prime_numbers;
long long a;
long long b;
public:
HashUniversal(int capacity = 1<<10,long long large_prime_numbers = 100001651);
HashUniversal(const HashUniversal<T>& hashUniversal);
const HashUniversal<T>& operator=(const HashUniversal<T>& hashUniversal);
~HashUniversal();
T & operator[](int key);
bool remove(int key);
protected:
virtual int hashing(int key);
void insert(Chain<T>* node);
Chain<T>*search(int key);
void clear();
void copy(const HashUniversal<T> & hashUniversal);
bool remove(Chain<T>* node);
};
template<typename T>
HashUniversal<T>::HashUniversal(int capacity,long long large_prime_numbers):capacity(capacity),large_prime_numbers(large_prime_numbers){
array = new Chain