本文整理汇总了C++中SuffixTree类的典型用法代码示例。如果您正苦于以下问题:C++ SuffixTree类的具体用法?C++ SuffixTree怎么用?C++ SuffixTree使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了SuffixTree类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main() {
string s1, s2, s3;
SuffixTree<'#'> tree;
cin >> s1 >> s2 >> s3;
tree.add_string(s1);
tree.add_string(s2);
tree.add_string(s3);
tree.build_suffix_tree();
tree.solve();
/*
{
SuffixTree<'#'> tree;
tree.add_string("baab");
tree.build_suffix_tree();
tree.print_preorder();
tree.print_suffix_array();
}
{
SuffixTree<'#'> tree;
tree.add_string("banana");
tree.add_string("xana");
tree.build_suffix_tree();
tree.find_max_common_substring();
}
*/
return 0;
}
示例2: suffixTreeTest
int suffixTreeTest()
{
SuffixTree t;
string test;
//char c;
//
//for(int i = 0; i < 1000000; i++){
// c = random() % 10 + '0';
// test.append(1, c);
//}
//test.append(1, 'e');
ifstream data;
data.open("output");
getline(data, test);
cout << "str: " << test << endl;
// t.addString("abcabxabcd");
// t.addString("banana$");
// t.addString("516571614e");
t.addString(test);
// t.addString("1231241e");
// t.debugPrintEdges(NULL, 0);
// printf("pasikartojimai: \n");
t.getSeqs();
return SUCC;
}
示例3: buildTempSuffixTree
SuffixTree buildTempSuffixTree(const vector <int> &input) {
if (input.size() == 0) {
return SuffixTree();
}
if (input.size() == 1) {
SuffixTree result;
unsigned int newNodeIndex = result.newNode(result.root, 0, 1, 0);
result[result.root].push_back(newNodeIndex);
return result;
}
SuffixTree compressed = buildTempSuffixTree(compressInput(input));
decompress(compressed, input);
SuffixTree &even = compressed;
checkTree("EVEN:\n", even, input);
SuffixTree odd = buildOddSuffixTree(even, input);
checkTree("ODD:\n", odd, input);
SuffixTree almostResult = mergeTrees(even, odd, input);
checkTree("ALMOST:\n", almostResult, input);
cleanTreeDfs(almostResult.root, -1, almostResult);
checkTree("RESL:\n", almostResult, input);
return almostResult;
}
示例4: main
int main()
{
SuffixTree<std::string> tree;
tree.add_string("mississippi$");
tree.add_string("missouri$");
tree.dump_tree();
return 0;
}
示例5: correctMerge
void correctMerge(unsigned int v, unsigned int parentsPlace, SuffixTree &merged,
IndexedPair<MergeTreesStruct> &updatedTrees,
const vector <unsigned int> &trueLength, const vector <int> &input,
unsigned int copyTree
) {
if (merged[v].isHiddenInfo()) {
doSomething(updatedTrees, [&merged, &v] (MergeTreesStruct &tree) {
tree.evaluate(merged, v);
});
if (copyTree == 2 && merged[v].depth != trueLength[v]) {
unsigned int commonLength = trueLength[v]
- merged[merged[v].parent].depth;
MergeTreesStruct& donor = minimal(updatedTrees,
[&input, &commonLength] (MergeTreesStruct &tree)
-> int {
auto const &node = tree.tree[tree.info];
return input[tree.suffix[tree.info]
+ (node.parent == -1 ? 0 : tree.tree[node.parent].depth)
+ commonLength];
}
);
copyTree = donor.number;
copyNodeExceptParentAndChildren(donor.tree[donor.info], merged[v]);
unsigned int newNodeIndex = merged.splitEdge(merged[v].parent,
parentsPlace, commonLength
);
unsigned int newCopy = merged.newNode(newNodeIndex);
merged[newNodeIndex].push_back(newCopy);
MergeTreesStruct ¬Donor = *xorPointers(&donor, &updatedTrees[0],
&updatedTrees[1]
);
copyNodeExceptParentAndChildren(notDonor.tree[notDonor.info],
merged[newCopy]
);
merged[newCopy].indexOfParentEdge += commonLength;
copySubTree(notDonor.tree, merged, notDonor.info, newCopy);
} else {
MergeTreesStruct &donor = minimal(updatedTrees,
[©Tree] (MergeTreesStruct &tree) -> pair<bool, bool> {
return make_pair(copyTree == 2 || copyTree != tree.number,
!(tree.tree[tree.info].leaf != -1)
);
}
);
copyNodeExceptParentAndChildren(donor.tree[donor.info], merged[v]);
}
}
if (copyTree != 2 && merged[v].leaf != -1
&& merged[v].leaf % 2 != copyTree) {
merged[v].leaf = -1;
}
for (unsigned int i = 0; i < merged[v].size(); ++i) {
unsigned int u = merged[v][i];
correctMerge(u, i, merged, updatedTrees, trueLength, input, copyTree);
}
}
示例6: main
int main ()
{
SuffixTree tree ("bibs");
list<int> indexes = tree.search ("ib");
for (list<int>::iterator it = indexes.begin(); it != indexes.end(); it++)
{
cout << *it << endl;
}
}
示例7: main
int main(int argc, char* argv[]) {
SuffixTree tree;
// Must be called with 1 and only 1 parameter.
if (argc != 2) {
std::cout << "usage: suffixtree inputstring" << std::endl;
exit(1);
}
else {
tree.construct(argv[1]);
std::cout << tree.log_tree() << std::endl;
}
}
示例8: main
int main()
{
alphabet = "abcdefghijklmnopqrstuvwxyz1234567890-#";
alphabetSize = alphabet.length();
string s1,s2;
//cout<<"Finding longest common substring using suffix trees\n";
//cout<<"Enter 1st String: ";
cin>>s1;
// cout<<"Enter 2nd String: ";
cin>>s2;
SuffixTree st;
st.findLCS(s1, s2);
return 0;
}
示例9: main
int main() {
scanf("%s", buffer + 1);
n = strlen(buffer + 1);
SuffixTree *tree = new SuffixTree;
for (int i = 1; buffer[i]; i++) {
tree->append(buffer[i] - 'a' + 1);
} // for
tree->append(SuffixTree::EOFCHAR);
tree->sort(sa);
for (int i = 1; i <= n; i++) {
sa[i] = sa[i + 1];
} // for
for (int i = 1; i <= n; i++) {
rnk[sa[i]] = i;
} // for
int j = 0;
for (int i = 1; i <= n; i++) {
if (rnk[i] == 1)
continue;
j--;
if (j < 0)
j = 0;
while (buffer[sa[rnk[i]] + j] == buffer[sa[rnk[i] - 1] + j]) {
j++;
} // while
lcp[rnk[i]] = j;
} // for
for (int i = 1; i <= n; i++) {
printf("%d ", sa[i]);
} // for
printf("\n");
for (int i = 2; i <= n; i++) {
printf("%d ", lcp[i]);
} // for
printf("\n");
return 0;
} // function main
示例10: main
int main() {
// freopen("subst1.in", "r", stdin);
// freopen("subst1.out", "w", stdout);
scanf("%s", buf);
n = strlen(buf);
SuffixTree *tree = new SuffixTree;
for (size_t pos = 0; buf[pos]; pos++) {
tree->append(buf[pos] - 'A');
} // for
tree->append(EOFCHAR);
printf("%lld\n", tree->solve() - n - 1);
return 0;
} // function main
示例11: countSubstrings
unsigned long long countSubstrings(SuffixTree &tree, unsigned int v) {
tree.checkNode(tree[v]);
unsigned long long sum = tree[v].lengthOfEdge(tree);
for (auto const &u: tree[v]) {
sum += countSubstrings(tree, u);
}
return sum;
}
示例12: main
int main(){
std::string testString("mississippi");
std::string stringList[] = {"is", "sip", "hi", "sis"};
SuffixTree *tree = new SuffixTree(testString);
for (const auto &x : stringList){
std::vector<int> list = tree->search(x);
if (!list.empty()) {
std::cout << x << ": ";
for (const auto &y: list){
std::cout << y << " ";
}
std::cout << std::endl;
}else{
std::cout << x << ": not found" << std::endl;
}
}
}
示例13: appendCopyNode
unsigned int appendCopyNode(const SuffixTree &from, SuffixTree &to,
unsigned int toStart, unsigned int u
) {
unsigned int newStart = to.newNode(toStart);
to[toStart].push_back(newStart);
copyNodeExceptParentAndChildren(from[u], to[newStart]);
copySubTree(from, to, u, newStart);
return newStart;
}
示例14: buildSuffixTreeFromSA
SuffixTree buildSuffixTreeFromSA(vector <unsigned int> &sa,
vector <unsigned int> &lcp,
unsigned int length
) {
vector <int> tmp;
SuffixTree result = buildTempSuffixTree(tmp);
int newNodeIndex
= result.newNode(result.root, sa[0], length - sa[0], sa[0]);
result[result.root].push_back(newNodeIndex);
unsigned int current = newNodeIndex;
for (unsigned int i = 1; i < sa.size(); ++i) {
while (result[current].parent != -1
&& result[result[current].parent].depth >= lcp[i - 1]
) {
current = result[current].parent;
}
unsigned int parent;
if (result[current].parent != -1 &&
result[result[current].parent].depth == lcp[i - 1]
) {
parent = result[current].parent;
} else if (result[current].depth == lcp[i - 1]) {
parent = current;
} else {
unsigned int currentParent = result[current].parent;
parent = result.splitEdge(currentParent,
result[currentParent].size() - 1,
lcp[i - 1] - result[currentParent].depth
);
result[parent].leaf = (length - sa[i] == lcp[i - 1] ? sa[i] : -1);
}
if (lcp[i - 1] != length - sa[i]) {
newNodeIndex = result.newNode(parent, sa[i] + lcp[i - 1],
length - sa[i], sa[i]
);
result[parent].push_back(newNodeIndex);
parent = newNodeIndex;
}
current = parent;
}
return result;
}
示例15: main
int main()
{
/*char needle[1000], haystack[1000];
cin >> needle >> haystack;
cout << NaiveSearch::search(needle, strlen(needle), haystack, strlen(haystack)) << endl;
cout << BMHSearch::search(needle, strlen(needle), haystack, strlen(haystack)) << endl;*/
char *word = "What";
SuffixTree t = SuffixTree(word, 4);
t.print();
cin.ignore();
cin.clear();
cin.get();
return 0;
}