Bachelors_Thesis_Code/helper_code/fagprojekt_code/hash_table.hpp

57 lines
1.3 KiB
C++
Raw Normal View History

2021-11-14 14:35:05 +01:00
#ifndef HASH_TABLE_H
#define HASH_TABLE_H
#include "hashed_string.hpp"
#include <stdint.h>
struct Hash_function {
private:
uint64_t * seed;
uint64_t(* hash_function)(const My_string *, const uint64_t *, uint64_t *, size_t);
size_t l;
uint64_t * x;
public:
Hash_function(uint64_t * seed, uint64_t(* hash_function)(const My_string *, const uint64_t *, uint64_t *, size_t), size_t l, size_t D) {
this->seed = seed;
this->hash_function = hash_function;
this->l = l;
this->x = new uint64_t[D];
}
~Hash_function() {
delete[] x;
}
size_t get_m() {
return 1 << l;
}
uint64_t hash(const My_string * string) {
return hash_function(string, seed, x, l);
}
};
struct Hash_table {
private:
Hash_function * hash_function;
Hashed_string * words;
size_t distinct_words = 0;
size_t m;
public:
Hash_table(Hash_function * hash_function);
~Hash_table();
size_t get_distict_words();
void hash(My_string * word);
void hash(Hashed_string * hs);
void rehash(Hash_function * hash_function);
int is_time_for_rehash() {return distinct_words >= m;}
};
#endif