SuffixArray =========== .. cpp:class:: numpy::SuffixArray numpy C++ class. Example ------- .. code-block:: cpp #include using namespace numpy; // Use SuffixArray SuffixArray obj; // ... operations ... Other Methods ------------- .. list-table:: :widths: 40 20 15 25 :header-rows: 1 * - Signature - Return Type - Location - Example * - ``static std::vector build_suffix_array(const StringType& text)`` - std::vector - np_string_sort.h:332 - :ref:`View ` * - ``static std::vector find_pattern(const StringType& text, const std::vector& suffix_array, const StringType& pattern)`` - std::vector - np_string_sort.h:376 - :ref:`View ` Code Examples ------------- The following examples are extracted from the test suite. .. _example-suffixarray-build_suffix_array-0: .. dropdown:: build_suffix_array (np_test_1_all.cpp:12657) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 12647 :emphasize-lines: 11 // std::cout << "LSD radix sort test passed" << std::endl; std::cout << " -> tests passed" << std::endl; } void test_suffix_array_construction() { std::cout << "========= test_suffix_array_construction ======================="; std::string text = "banana"; auto suffix_array = SuffixArray::build_suffix_array(text); if (!(suffix_array.size() == text.size())) { std::string description = std::string("test_suffix_array_construction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(suffix_array.size() == text.size())"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // Verify suffixes are properly sorted for (size_t i = 1; i < suffix_array.size(); ++i) { std::string prev_suffix = text.substr(suffix_array[i - 1]); .. _example-suffixarray-find_pattern-1: .. dropdown:: find_pattern (np_test_1_all.cpp:12688) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 12678 :emphasize-lines: 11 std::cout << " -> tests passed" << std::endl; } void test_suffix_array_pattern_search() { std::cout << "========= test_suffix_array_pattern_search ======================="; std::string text = "abananabandana"; auto suffix_array = SuffixArray::build_suffix_array(text); // Search for pattern "ana" auto positions = SuffixArray::find_pattern(text, suffix_array, std::string("ana")); // "ana" appears at positions 1, 3, 5, 9, 11 in "abananabandana" if (!(!positions.empty())) { std::string description = std::string("test_suffix_array_pattern_search():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(!positions.empty())"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // Verify found positions are correct for (size_t pos : positions) {