-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBSTreeDict.h
54 lines (41 loc) · 982 Bytes
/
BSTreeDict.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
48
49
50
51
52
53
54
#ifndef BSTREEDICT_H
#define BSTREEDICT_H
#include <ostream>
#include <stdexcept>
#include "Dict.h"
#include "BSTree.h"
#include "TableEntry.h"
template <typename V>
class BSTreeDict: public Dict<V>{
private:
BSTree<TableEntry<V>>* tree;
public:
BSTreeDict(){
tree = new BSTree<TableEntry<V>>();
}
~BSTreeDict(){
delete tree;
}
friend std::ostream& operator<<(std::ostream &out, const BSTreeDict<V> &bs){
out << *(bs.tree) << std::endl;
return out;
}
V operator[](std::string key){
return tree->search(TableEntry<V>(key)).value;
}
void insert(std::string key, V value) override{
tree->insert(TableEntry<V>(key, value));
}
V search(std::string key) override{
return tree->search(TableEntry<V>(key)).value;
}
V remove(std::string key) override{
V value = tree->search(TableEntry<V>(key)).value;
tree->remove(TableEntry<V>(key));
return value;
}
int entries() override{
return tree->size();
}
};
#endif