Skip to content

Commit 423b1bf

Browse files
committed
check for exceeded order
1 parent 548c25b commit 423b1bf

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

test_data/queries.not_found

+3
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,6 @@ identified, been then
99
(XMM vector registers
1010
are...
1111
programmers software of to some
12+
appendix at www.agner.org/optimize/cppexamples.zip for how for how
13+
appendix at www.agner.org/optimize/cppexamples.zip for how for how appendix should
14+
appendix at www.agner.org/optimize/cppexamples.zip for how for how appendix should for how for how appendix should

trie_count_lm.hpp

+5-6
Original file line numberDiff line numberDiff line change
@@ -268,28 +268,27 @@ namespace tongrams {
268268
uint64_t lookup(T gram, Adaptor adaptor)
269269
{
270270
static uint64_t word_ids[global::max_order];
271-
uint64_t order =
271+
uint64_t o =
272272
m_mapper.map_query(adaptor(gram), word_ids,
273273
&m_vocab, &m_arrays.front(),
274274
m_remapping_order);
275275

276-
if (order == global::not_found) {
276+
if (o == global::not_found or o > order()) {
277277
return global::not_found;
278278
}
279-
assert(order < m_order);
280279

281280
pointer_range r;
282281
uint64_t pos = word_ids[0];
283-
for (uint64_t i = 1; i <= order; ++i) {
282+
for (uint64_t i = 1; i <= o; ++i) {
284283
r = m_arrays[i - 1].range(pos);
285284
pos = m_arrays[i].position(r, word_ids[i]);
286285
if (pos == global::not_found) {
287286
return global::not_found;
288287
}
289288
}
290289

291-
uint64_t count_rank = m_arrays[order].count_rank(pos);
292-
return m_distinct_counts.access(order, count_rank);
290+
uint64_t count_rank = m_arrays[o].count_rank(pos);
291+
return m_distinct_counts.access(o, count_rank);
293292
}
294293

295294
inline uint64_t order() const {

0 commit comments

Comments
 (0)