127 QList<UncompressedRow> sortedTable(row_count);
129 for (
int i = 0; i < row_count; ++i)
131 int *begin = &table [i * column_count];
132 int *end = begin + column_count;
134 sortedTable [i].assign (i, begin, end);
137 std::sort (sortedTable.begin (), sortedTable.end (), _SortUncompressedRow ());
140 int previous_zeros = INT_MAX;
142 for (
const UncompressedRow &row : std::as_const(sortedTable))
144 int zeros = row.count (0);
146 Q_ASSERT (zeros <= previous_zeros);
147 zeros = previous_zeros;
152 index.fill (-999999, row_count);
154 for (
const UncompressedRow &row : std::as_const(sortedTable))
156 int first_token = std::distance (row.begin (), row.beginNonZeros ());
157 QList<
int>::iterator pos = info.begin();
159 while (pos != info.end ())
161 if (pos == info.begin ())
164 QList<
int>::iterator pm = std::search(pos, info.end(), row.beginNonZeros(),
165 row.endNonZeros(), _PerfectMatch());
167 if (pm != info.end ())
174 pos = std::search (pos, info.end (), row.beginNonZeros (), row.endNonZeros (), _Fit ());
176 if (pos == info.end ())
179 int idx = std::distance (info.begin (), pos) - first_token;
180 bool conflict =
false;
182 for (
int j = 0; ! conflict && j < row.size (); ++j)
185 conflict |= idx + j >= 0 && check [idx + j] == j;
188 conflict |= check [idx + j] == j;
197 if (pos == info.end ())
199 int size = info.size ();
201 info.resize (info.size () + row.nonZeroElements ());
202 check.resize (info.size ());
204 std::fill (check.begin () + size, check.end (), -1);
205 pos = info.begin () + size;
208 int offset = std::distance (info.begin (), pos);
209 index [row.index ()] = offset - first_token;
211 for (
const int *it = row.beginNonZeros (); it != row.endNonZeros (); ++it, ++pos)
217 int i = row.index ();
219 for (
int j = 0; j < row.size (); ++j)
224 check [index [i] + j] = j;
229 for (
const UncompressedRow &row : std::as_const(sortedTable))
231 int i = row.index ();
232 Q_ASSERT (i < sortedTable.size ());
234 for (
int j = 0; j < row.size (); ++j)
238 Q_ASSERT (index [i] + j < 0 || check [index [i] + j] != j);
242 Q_ASSERT ( info [index [i] + j] == row.at (j));
243 Q_ASSERT (check [index [i] + j] == j);