12 #ifndef THRILL_EXAMPLES_SUFFIX_SORTING_CHECK_SA_HEADER 13 #define THRILL_EXAMPLES_SUFFIX_SORTING_CHECK_SA_HEADER 25 namespace suffix_sorting {
27 template <
typename InputDIA,
typename SuffixArrayDIA>
28 bool CheckSA(
const InputDIA& input,
const SuffixArrayDIA& suffix_array) {
33 using Char =
typename InputDIA::ValueType;
34 using Index =
typename SuffixArrayDIA::ValueType;
48 uint64_t input_size = input.Keep().Size();
53 .ZipWithIndex([](
const Index& sa,
const size_t& i) {
65 .ZipWithIndex([](
const IndexRank& ir,
const size_t& index) -> Index {
66 return ir.
index == Index(index) ? 0 : 1;
71 if (perm_check != Index(0)) {
72 LOG1 <<
"Error: suffix array is not a permutation of 0..n-1.";
76 using IndexPair = std::pair<Index, Index>;
81 .template FlatWindow<IndexPair>(
83 emit(IndexPair { rb[0].rank, rb[1].rank });
84 if (index == input_size - 2) {
86 emit(IndexPair { rb[1].rank, input_size });
90 [](
const std::pair<Index, Index>& isa_pair,
const Char& ch) {
91 return Index3 { isa_pair.first, isa_pair.second, ch };
94 .Sort([](
const Index3& a,
const Index3& b) {
95 return a.index < b.index;
98 char order_check_sum =
105 if (rb[0].ch > rb[1].ch) {
107 LOG1 <<
"Error: suffix array position " 108 << index <<
" ordered incorrectly.";
111 else if (rb[0].ch == rb[1].ch) {
112 if (rb[1].next == Index(input_size)) {
115 LOG1 <<
"Error: suffix array position " 116 << index <<
" ordered incorrectly.";
119 if (rb[0].next != Index(input_size) && rb[0].next > rb[1].next) {
123 LOG1 <<
"Error: suffix array position " 124 << index <<
" ordered incorrectly.";
133 return (order_check_sum == 0);
139 #endif // !THRILL_EXAMPLES_SUFFIX_SORTING_CHECK_SA_HEADER tlx::RingBuffer< Type, Allocator > RingBuffer
A ring (circular) buffer of static (non-growing) size.
auto Zip(const ZipFunction &zip_function, const DIA< FirstDIAType, FirstDIAStack > &first_dia, const DIAs &... dias)
Zips two DIAs of equal size in style of functional programming by applying zip_function to the i-th e...
bool CheckSA(const InputDIA &input, const SuffixArrayDIA &suffix_array)
struct examples::suffix_sorting::IndexRank TLX_ATTRIBUTE_PACKED