-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprefix_trees.cpp
More file actions
86 lines (77 loc) · 2.85 KB
/
Copy pathprefix_trees.cpp
File metadata and controls
86 lines (77 loc) · 2.85 KB
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#include <iostream>
#include "support.cpp"
using namespace std;
class AutocompleterInterface {
public:
virtual int getLength() = 0;
virtual void insert(string, float, string) = 0;
virtual void remove(string) = 0;
virtual NodeReport* autocomplete(string) = 0;
virtual NodeReport* autocomplete(string, int) = 0;
};
class SimplePrefixTree : public AutocompleterInterface {
protected:
string _value;
float _weight;
SimplePrefixTree* _subtrees;
float* _weights;
WeightType _weightType;
virtual void insertSum(string& value, float weight, string& prefix) {
//
}
virtual float insertAverage(string& value, float weight, string& prefix) {}
virtual void removeSum(string& prefix) {}
virtual float* removeAverage(string& prefix) {}
public:
~SimplePrefixTree() = default;
explicit SimplePrefixTree(WeightType weightType) : _weightType(weightType) {
_value = nullptr;
_weight = 0;
_subtrees = nullptr;
_weights = nullptr;
_weightType = static_cast<WeightType>(NULL);
}
SimplePrefixTree(string value, float weight, SimplePrefixTree* subtrees, float* weights, WeightType weightType) {
_value = std::move(value);
_weight = weight;
_subtrees = subtrees;
_weights = weights;
_weightType = weightType;
}
bool isEmpty() {}
bool isLeaf() {}
string stringRep() {} //Returns string representation (equivalent to __str__() in Python)
void insert(string value, float weight, string prefix) override {
if (_weightType == eSum) {
insertSum(value, weight, prefix);
}
else if (_weightType == eAverage) {
insertAverage(value, weight, prefix);
}
}
void remove(string prefix) override {
if (_weightType == eSum) {
removeSum(prefix);
}
else if (_weightType == eAverage) {
removeAverage(prefix);
}
}
NodeReport* autocomplete(string prefix) override {}
NodeReport* autocomplete(string prefix, int limit) override {}
};
class CompressedPrefixTree : public SimplePrefixTree {
protected:
void insertSum(string& value, float weight, string& prefix) override {}
float insertAverage(string& value, float weight, string& prefix) override {}
void removeSum(string& prefix) override {}
float* removeAverage(string& prefix) override {}
public:
~CompressedPrefixTree() = default;
explicit CompressedPrefixTree(WeightType weightType) : SimplePrefixTree(weightType) {}
//TODO:
CompressedPrefixTree(string value, float weight, SimplePrefixTree* subtrees, float* weights,
WeightType weightType) : SimplePrefixTree(value, weight, subtrees, weights, weightType) {}
NodeReport* autocomplete(string prefix) override {}
NodeReport* autocomplete(string prefix, int limit) override {}
};