-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.cpp
93 lines (80 loc) · 4.66 KB
/
main.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
// Implemented by Maxim Tishkov
//
// Created using ERA paper
// http://www.vldb.org/pvldb/vol5/p049_essammansour_vldb2012.pdf
// Essam Mansour, Amin Allam, Spiros Skiadopoulos, Panos Kalnis
//
#include <iostream>
#include <memory>
#include <string>
#include <thread>
#include "SuffixTree.hpp"
#include "utils/MemoryLeakDatabase.hpp"
#include "utils/StringVector.hpp"
int main() {
for (uint64 i = 0; i < 1000000; i++) {
// std::string str = "ewrqwewqeqwerqweerrqwwewrewewrweqweerqwr"
// "eqwweeerqewerqweeqweqrweqwerqweqeweqwreqweeqeeqwqqweerqwreqeweqrweqw"
// "erqwewrqwewqeqwerqweerrqwwewrewewrweqweerqwreqwweeerqewerqweeqweqrweq"
// "werqweqeweqwreqweeqeeqwqqweerqwreqeweqrweqwerqwewrqwewqeqwerqweerrqwwe"
// "wrewewrweqweerqwreqwweeerqewerqweeqweqrweqwerqweqeweqwreqweeqeeqwqqwee"
// "rqwreqeweqrweqwerqwewrqwewqeqwerqweerrqwwewrewewrweqweerqwreqwweeerqewe"
// "rqweeqweqrweqwerqweqeweqwreqweeqeeqwqqweerqwreqeweqrweqwerqwewrqwewqeqwe"
// "rqweerrqwwewrewewrweqweerqwreqwweeerqewerqweeqweqrweqwerqweqeweqwreqweeqe"
// "eqwqqweerqwreqeweqrweqwerqwewrqwewqeqwerqweerrqwwewrewewrweqweerqwreqwweee"
// "rqewerqweeqweqrweqwerqweqeweqwreqweeqeeqwqqweerqwreqeweqrweqwerqw";
std::string str = "sdfasdfadadgadfgaergdlkfgdslkgjdfgljdfs;kgldfg"
"aefjseghdfghdszfgasfhawgerawevwetvwertvert"
"weafhasifashfiuawehfuyszfgsudyifbfdfhbdfsjhgjhkguyifytfvytfvtuyrvrtudfytbd"
"hyfttctryxytdcturdcytrfuytfvhuyguigouymsfnfkjhsdlfkhaefhaerhgsdlfjg"
"fjaefuehfoiuwefhsizofhfdgjdfhgkszjdfhgfsdkjgbseiutgersuifbdfjkvdfxgbdfgsdzf"
"dsfaewfhawuifhzsdfhzsofuzebfhzawfalkfdsnfkajsldfsadjfasd"
"afsdfjaweioufhweirwearweirewrwerwewrwerwerewrwewr"
"rwearwerwerwerewewrewrewrwerewrewrwerwersadfasdnfsdjkfsdaf"
"asdfsadfjasifhaweiufhasfgasuiyfegwarwaerawerewarwer"
"werewrewewrweretertertwertrewtwertewtwyeetrouierwtwer"
"twerterwtuiwerterwuterwutewryterwytrweterwt"
"ewrterwterwterwtrewtwtrweterwtertertreterterttretretrere"
"tertreterreterterererytuertuyeritwertywereywuruywtwe"
"rwertewuyrtwerewryewureuwtrutewurwetrtuweutyrwe"
"werwerewtrewuwetewuyrtyewtruewuytrtuewyutryeuyewutrwe"
"ewrweryewrtwertweturewyrutweyruyewtyrweurtweur"
"werwertweurtyewtyrtuwtrewreuytweutruyewuyweyutryutwetr"
"ewrwertwetrwetruweyrtwetrtyweyuruytwtyetwetewrrwerwerew"
"rweretewrterwterwtwertwerterwterewrwerwerwer"
"ewtwertewrtrewterwterwtwertefusebfzskefbzskefhjsdbfkzhjsdfd"
"ertewrterwtewrytierwtyweurtweurewrwertweurwearwerwearwaerwaerewartertertert"
"wertweruywteurwetuyirqweuyryutqwetirqwuertqweutrtqweutruqtwiertyiqwtuert"
"rqwerwertewuqrtqwyuertquweyrtqweurtweqiruqwtertuqwetrtuyqweyrttwqyeurtyeuwtrquywe"
"wqerqwerwertwqeuruwteqrtuwquetrtweetwrutqywretwqutrytweuytruytweuytruywertew"
"rwertweryweurtweuyrtuetuewtwretuyewyturtywertwetyrytweryutewtyrtyweytrewtyryt"
"wrweirewtrytwetrewytuweruyteutyrweytrtuywertuyewtwetettrutwetrtywetrszfftyivuygugb"
"vgfuytfybiuuybitot78ttiytyutityutuyyututyuytaertae tesrts dfg sdfg sadf aerf sdzg f";
// std::string str = "TGGTGGTGGTGCGGTGATGGTGC";
auto dataSource = std::make_shared<StringDataSource>(str);
// items per virtual tree / per thread & items per read
auto config = std::make_shared<SuffixTreeConfig>(100, 100);
auto builder = SuffixTreeBuilder(dataSource, config);
auto res = builder.build();
std::cout << "Found leaves:" << std::endl;
for (auto it = res->getRootNode()->leavesBegin(); it != res->getRootNode()->leavesEnd(); it++) {
std::cout << it->getPath() << std::endl;
}
std::cout << "Follow path res: " << std::endl;
// Append $ to get leaf
std::string findingStr = "urtweurewrwertweurw";
auto result = res->getRootNode()->followPath(StringVector(findingStr).getVector());
if (result != nullptr) {
std::cout << result->getPath() << std::endl;
std::cout << "Is Leaf: " << result->isLeaf() << std::endl;
} else {
std::cout << "Not Found" << std::endl;
}
// Edges sometimes start with the same prefix
// So that check is disabled
res->getInfo()->check();
std::this_thread::sleep_for(std::chrono::milliseconds(1000));
}
MemoryLeakDatabase::dump();
return 0;
}