128 QList<UncompressedRow> sortedTable(row_count);
130 for (
int i = 0; i < row_count; ++i)
132 int *begin = &table [i * column_count];
133 int *end = begin + column_count;
135 sortedTable [i].assign (i, begin, end);
141 int previous_zeros = INT_MAX;
143 for (
const UncompressedRow &row : std::as_const(sortedTable))
145 int zeros = row.count (0);
147 Q_ASSERT (zeros <= previous_zeros);
148 zeros = previous_zeros;
153 index.fill (-999999, row_count);
155 for (
const UncompressedRow &row : std::as_const(sortedTable))
157 int first_token = std::distance (row.begin (), row.beginNonZeros ());
158 QList<
int>::iterator pos = info.begin();
160 while (pos != info.end ())
162 if (pos == info.begin ())
165 QList<
int>::iterator pm = std::search(pos, info.end(), row.beginNonZeros(),
166 row.endNonZeros(), _PerfectMatch());
168 if (pm != info.end ())
175 pos = std::search (pos, info.end (), row.beginNonZeros (), row.endNonZeros (), _Fit ());
177 if (pos == info.end ())
180 int idx = std::distance (info.begin (), pos) - first_token;
181 bool conflict =
false;
183 for (
int j = 0; ! conflict && j < row.size (); ++j)
186 conflict |= idx + j >= 0 && check [idx + j] == j;
189 conflict |= check [idx + j] == j;
198 if (pos == info.end ())
200 int size = info.size ();
202 info.resize (info.size () + row.nonZeroElements ());
203 check.resize (info.size ());
205 std::fill (check.begin () + size, check.end (), -1);
206 pos = info.begin () + size;
209 int offset = std::distance (info.begin (), pos);
210 index [row.index ()] = offset - first_token;
212 for (
const int *it = row.beginNonZeros (); it != row.endNonZeros (); ++it, ++pos)
218 int i = row.index ();
220 for (
int j = 0; j < row.size (); ++j)
225 check [index [i] + j] = j;
230 for (
const UncompressedRow &row : std::as_const(sortedTable))
232 int i = row.index ();
233 Q_ASSERT (i < sortedTable.size ());
235 for (
int j = 0; j < row.size (); ++j)
239 Q_ASSERT (index [i] + j < 0 || check [index [i] + j] != j);
243 Q_ASSERT ( info [index [i] + j] == row.at (j));
244 Q_ASSERT (check [index [i] + j] == j);