// (C) Copyright 2008-2009 SDML (www.sdml.info) // // Use, modification and distribution is subject to the Boost Software // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) #include #include #include #include #include #include #include template void print_range(T begin, T end) { for (T f = begin; f != end; ++f) { std::cout << *f; } } int main() { gpld::suffix_array test; std::cout << "Testing suffix array." << std::endl; BOOST_ASSERT(test.empty()); std::string example("Hello hello mother, hello hello father."); test = gpld::suffix_array(example); BOOST_ASSERT(test.str() == example); // print all of the positions of the suffices for (unsigned int i = 0; i < test.size(); ++i) { std::cout << i << "\t"; //std::cout << (test.str().begin() - test[i]) << "\t"; if (i > 0) { //std::cout << test.lcp(i-1, i) << "\t"; } print_range(test.at(i), test.str().end()); std::cout << std::endl; } // make sure longest common prefix is working for known values std::cout << test.lcp(9, 10) << std::endl; BOOST_ASSERT(test.lcp(9, 10) == 5); /*gpld::suffix_array::range_pair results = test.find("ello"); std::cout << "ello found in range [" << results.first << ", " << results.second << ')' << std::endl;*/ // Try something example = "jackalope kidney bean jackrabbit bean jalopy kidney jackalope"; test = gpld::suffix_array(example); // Find the longest common substring std::pair lcs; lcs = test.longest_common_substring(); // Print the longest common substring for (unsigned int i = 0; i < lcs.first; ++i) { std::cout << *(lcs.second + i); } std::cout << std::endl; return 0; }