1818
1919#include < fmt/format.h>
2020
21- #include < gsl/span>
22- #include < gsl/span_ext>
23-
2421#include < algorithm>
2522#include < cassert>
2623#include < cstdint>
@@ -48,12 +45,7 @@ struct multistage_table
4845 std::vector<Stage2ElementType> stage2; // mod
4946 std::vector<T> stage3; // values
5047
51- auto to_view () const noexcept
52- {
53- return view_type { gsl::span<Stage1ElementType const >(stage1.data (), stage1.size ()),
54- gsl::span<Stage2ElementType const >(stage2.data (), stage2.size ()),
55- gsl::span<T const >(stage3.data (), stage3.size ()) };
56- }
48+ auto to_view () const noexcept { return view_type { stage1.data (), stage2.data (), stage3.data () }; }
5749
5850 T const & get (SourceType index) const noexcept { return to_view ().get (index); }
5951};
@@ -67,20 +59,21 @@ template <typename T,
6759class multistage_table_generator
6860{
6961 public:
70- gsl::span<T const > _input;
62+ T const * _input;
63+ size_t _inputSize;
7164 multistage_table<T, SourceType, Stage1ElementType, Stage2ElementType, BlockSize, MaxValue>& _output;
7265
7366 void generate ()
7467 {
75- assert (_input. size () % BlockSize == 0 );
76- _output.stage1 .resize (_input. size () );
77- for (SourceType blockStart = 0 ; blockStart <= _input. size () - BlockSize; blockStart += BlockSize)
68+ assert (_inputSize % BlockSize == 0 );
69+ _output.stage1 .resize (_inputSize );
70+ for (SourceType blockStart = 0 ; blockStart <= _inputSize - BlockSize; blockStart += BlockSize)
7871 _output.stage1 [blockStart / BlockSize] = get_or_create_index_to_stage2_block (blockStart);
7972 }
8073
8174 void verify () const
8275 {
83- for (SourceType blockStart = 0 ; blockStart <= _input. size () - BlockSize; ++blockStart)
76+ for (SourceType blockStart = 0 ; blockStart <= _inputSize - BlockSize; ++blockStart)
8477 verify_block (blockStart / BlockSize);
8578 }
8679
@@ -124,7 +117,7 @@ class multistage_table_generator
124117 std::optional<size_t > find_same_block (size_t blockStart) const noexcept
125118 {
126119 assert (blockStart % BlockSize == 0 );
127- assert (blockStart + BlockSize <= _input. size () );
120+ assert (blockStart + BlockSize <= _inputSize );
128121
129122 for (size_t otherBlockStart = 0 ; otherBlockStart < blockStart; otherBlockStart += BlockSize)
130123 if (is_same_block (otherBlockStart, blockStart))
@@ -139,8 +132,8 @@ class multistage_table_generator
139132 {
140133 assert (a % BlockSize == 0 );
141134 assert (b % BlockSize == 0 );
142- assert (a + BlockSize <= _input. size () );
143- assert (b + BlockSize <= _input. size () );
135+ assert (a + BlockSize <= _inputSize );
136+ assert (b + BlockSize <= _inputSize );
144137
145138 for (size_t i = 0 ; i < BlockSize; ++i)
146139 if (_input[a + i] != _input[b + i])
@@ -170,12 +163,13 @@ template <typename T,
170163 SourceType BlockSize,
171164 SourceType MaxValue = std::numeric_limits<SourceType>::max()>
172165void generate (
173- gsl::span<T const > input,
166+ T const * input,
167+ size_t inputSize,
174168 multistage_table<T, SourceType, Stage1ElementType, Stage2ElementType, BlockSize, MaxValue>& output)
175169{
176170 auto builder =
177171 multistage_table_generator<T, SourceType, Stage1ElementType, Stage2ElementType, BlockSize, MaxValue> {
178- input, output
172+ input, inputSize, output
179173 };
180174 builder.generate ();
181175}
0 commit comments