Original implementation in Java.
Referencing with C++ implementation (suffix tree on
one string).
All-in-one header: SuffixTree.h
.
put(list, value)
: adds alist
associated with avalue
.value
will be returned at later retrievals.search(sub-list)
: returns a std::set ofvalues
of the lists containingsub-list
.
More examples in main.cpp
.
vector<string> words = {"qwe", "rtyr", "uio", "pas", "dfg", "hjk", "lzx", "cvb", "bnm"};
SuffixTree<string, int> tree;
for (int idx = 0; idx < words.size(); idx++) {
tree.put(words[idx], idx);
}
for (int idx = 0; idx < words.size(); idx++) {
set result = tree.search(word[idx].substr(1, 2));
// found!
assert(result.find(idx) != result.end());
}
- Allow any type of
sequence container
aslist
, if:- Typename
value_type
(type of list elements),size_type
andconst_iterator
are public. begin
andend
iterator must meetLegacyInputIterator
at minimum.
- Typename
- Allow custom type as list element if
< operator
is defined.
- Allow custom type as
value
if< operator
is defined.
-
DO NOT DESTROY the lists. They are only stored as begin and end iterators in the tree.
-
Requires C++11 at minimum.
-
This template is originally created to help perform search queries in a dictionary.