SuffixArray#
-
class numpy::SuffixArray#
numpy C++ class.
Example#
#include <numpy/np_ndarray.h>
using namespace numpy;
// Use SuffixArray
SuffixArray obj;
// ... operations ...
Other Methods#
Signature |
Return Type |
Location |
Example |
|---|---|---|---|
|
std::vector<size_t> |
np_string_sort.h:332 |
|
|
std::vector<size_t> |
np_string_sort.h:376 |
Code Examples#
The following examples are extracted from the test suite.
build_suffix_array (np_test_1_all.cpp:12657)
12647 // std::cout << "LSD radix sort test passed" << std::endl;
12648
12649 std::cout << " -> tests passed" << std::endl;
12650 }
12651
12652 void test_suffix_array_construction() {
12653 std::cout << "========= test_suffix_array_construction =======================";
12654
12655 std::string text = "banana";
12656 auto suffix_array = SuffixArray::build_suffix_array(text);
12657
12658 if (!(suffix_array.size() == text.size())) {
12659 std::string description = std::string("test_suffix_array_construction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(suffix_array.size() == text.size())";
12660 std::cout << std::string("[FAIL] ") + description << std::endl;
12661 throw std::runtime_error(description);
12662 }
12663
12664 // Verify suffixes are properly sorted
12665 for (size_t i = 1; i < suffix_array.size(); ++i) {
12666 std::string prev_suffix = text.substr(suffix_array[i - 1]);
find_pattern (np_test_1_all.cpp:12688)
12678 std::cout << " -> tests passed" << std::endl;
12679 }
12680
12681 void test_suffix_array_pattern_search() {
12682 std::cout << "========= test_suffix_array_pattern_search =======================";
12683
12684 std::string text = "abananabandana";
12685 auto suffix_array = SuffixArray::build_suffix_array(text);
12686
12687 // Search for pattern "ana"
12688 auto positions = SuffixArray::find_pattern(text, suffix_array, std::string("ana"));
12689
12690 // "ana" appears at positions 1, 3, 5, 9, 11 in "abananabandana"
12691 if (!(!positions.empty())) {
12692 std::string description = std::string("test_suffix_array_pattern_search():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(!positions.empty())";
12693 std::cout << std::string("[FAIL] ") + description << std::endl;
12694 throw std::runtime_error(description);
12695 }
12696
12697 // Verify found positions are correct
12698 for (size_t pos : positions) {