-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathNaive.cpp
40 lines (36 loc) · 894 Bytes
/
Naive.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
#include "Naive.h"
bool Naive::addStringFromFile(std::string fileName)
{
if (numStrings + 1 > 1)
return false;
SuffixArray::addStringFromFile(fileName);
return true;
}
bool Naive::addString(std::string inputString)
{
if (numStrings + 1 > 1)
return false;
SuffixArray::addString(inputString);
return true;
}
void Naive::makeSuffixArray()
{
std::stringstream ss;
for(auto it = string->begin(); it != string->end(); ++it )
{
ss << (unsigned char)*it;
}
std::string s = ss.str();
s.append(" ");
std::vector<std::string> suffixes;
for (int i = 0 ; i < s.length(); i++)
{
suffixes.push_back(s.substr(i, s.length()));
}
std::sort(suffixes.begin(), suffixes.end());
for (auto& suffix : suffixes)
{
int offset = s.length() - suffix.length();
suffixArray->push_back(offset);
}
}