-
Notifications
You must be signed in to change notification settings - Fork 91
/
simple_example.cpp
93 lines (74 loc) · 3.28 KB
/
simple_example.cpp
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
87
88
89
90
91
92
93
#include <iostream>
#include <vector>
#include "include/surf.hpp"
using namespace surf;
int main() {
std::vector<std::string> keys = {
"f",
"far",
"fast",
"s",
"top",
"toy",
"trie",
};
// basic surf
SuRF* surf = new SuRF(keys);
// use default dense-to-sparse ratio; specify suffix type and length
SuRF* surf_hash = new SuRF(keys, surf::kHash, 8, 0);
SuRF* surf_real = new SuRF(keys, surf::kReal, 0, 8);
// customize dense-to-sparse ratio; specify suffix type and length
SuRF* surf_mixed = new SuRF(keys, true, 16, surf::kMixed, 4, 4);
//----------------------------------------
// point queries
//----------------------------------------
std::cout << "Point Query Example: fase" << std::endl;
std::string key = "fase";
if (surf->lookupKey(key))
std::cout << "False Positive: "<< key << " found in basic SuRF" << std::endl;
else
std::cout << "Correct: " << key << " NOT found in basic SuRF" << std::endl;
if (surf_hash->lookupKey(key))
std::cout << "False Positive: " << key << " found in SuRF hash" << std::endl;
else
std::cout << "Correct: " << key << " NOT found in SuRF hash" << std::endl;
if (surf_real->lookupKey(key))
std::cout << "False Positive: " << key << " found in SuRF real" << std::endl;
else
std::cout << "Correct: " << key << " NOT found in SuRF real" << std::endl;
if (surf_mixed->lookupKey(key))
std::cout << "False Positive: " << key << " found in SuRF mixed" << std::endl;
else
std::cout << "Correct: " << key << " NOT found in SuRF mixed" << std::endl;
//----------------------------------------
// range queries
//----------------------------------------
std::cout << "\nRange Query Example: [fare, fase)" << std::endl;
std::string left_key = "fare";
std::string right_key = "fase";
if (surf->lookupRange(left_key, true, right_key, false))
std::cout << "False Positive: There exist key(s) within range ["
<< left_key << ", " << right_key << ") " << "according to basic SuRF" << std::endl;
else
std::cout << "Correct: No key exists within range ["
<< left_key << ", " << right_key << ") " << "according to basic SuRF" << std::endl;
if (surf_hash->lookupRange(left_key, true, right_key, false))
std::cout << "False Positive: There exist key(s) within range ["
<< left_key << ", " << right_key << ") " << "according to SuRF hash" << std::endl;
else
std::cout << "Correct: No key exists within range ["
<< left_key << ", " << right_key << ") " << "according to SuRF hash" << std::endl;
if (surf_real->lookupRange(left_key, true, right_key, false))
std::cout << "False Positive: There exist key(s) within range ["
<< left_key << ", " << right_key << ") " << "according to SuRF real" << std::endl;
else
std::cout << "Correct: No key exists within range ["
<< left_key << ", " << right_key << ") " << "according to SuRF real" << std::endl;
if (surf_mixed->lookupRange(left_key, true, right_key, false))
std::cout << "False Positive: There exist key(s) within range ["
<< left_key << ", " << right_key << ") " << "according to SuRF mixed" << std::endl;
else
std::cout << "Correct: No key exists within range ["
<< left_key << ", " << right_key << ") " << "according to SuRF mixed" << std::endl;
return 0;
}