-
Notifications
You must be signed in to change notification settings - Fork 1
/
hashtable.h
47 lines (42 loc) · 1.25 KB
/
hashtable.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/* Remi Trettin COP4530 Assignment 5 */
#ifndef HASHTABLE_H
#define HASHTABLE_H
#include <iostream>
#include <fstream>
#include <sstream>
#include <vector>
#include <list>
#include <string>
#include <utility>
#include <algorithm>
namespace cop4530 {
static const unsigned int max_prime = 1301081;
static const unsigned int default_capacity = 11;
template <typename K, typename V>
class HashTable {
public:
HashTable(std::size_t n = 101);
~HashTable();
bool contains(const K &k) const;
bool match(const std::pair<K, V> &kv) const;
bool insert(const std::pair<K, V> & kv);
bool insert(std::pair<K, V> && kv);
bool remove(const K & x);
void clear();
bool load(const char *filename);
void dump() const;
bool write_to_file(char *filename);
std::size_t size() const;
private:
std::size_t currentSize;
std::vector<std::list<std::pair<K, V>>> bucketVector;
void makeEmpty();
void rehash();
std::size_t myhash(const K &k) const;
unsigned long prime_below(unsigned long);
void setPrimes(std::vector<unsigned long> &);
bool rehashinsert(const std::pair<K, V> & kv);
};
#include "hashtable.hpp"
}
#endif