rlucene 0.1.0-alpha.3

A Rust port of Apache Lucene, a full-text search engine library
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
use crate::core::index::point_values::IntersectVisitor;
use crate::core::search::doc_id_set_iterator::{DocIdSetIterator, NO_MORE_DOCS};
use crate::core::store::{DataOutput, IndexInput};
use crate::core::util::TryIntoInt;
use crate::core::util::array_util::ArrayUtil;
use crate::core::util::bit_set::BitSet;
use crate::core::util::doc_base_bit_set_iterator::DocBaseBitSetIterator;
use crate::core::util::error::lucene_error::{LuceneError, Result};
use crate::core::util::fixed_bit_set::FixedBitSet;
use crate::core::util::ints_ref::IntsRef;
use crate::core::util::longs_ref::LongsRef;

pub struct DocIdsWriter {
  scratch_longs: LongsRef,
  /// IntsRef to be used to iterate over the scratch buffer. A single
  /// instance owns the scratch buffer; only its length is reset for each visit.
  ///
  /// The main reason for existing is to be able to call the
  /// [`IntersectVisitor::visit_with_ints_ref`]
  /// method rather than the
  /// [`IntersectVisitor::visit`]
  /// method. This seems to make a difference in performance, probably due to
  /// fewer virtual calls then happening (once per read call rather than
  /// once per doc).
  scratch_ints_ref: IntsRef<Vec<i32>>,
  max_points_in_leaf: usize,
}
impl Clone for DocIdsWriter {
  fn clone(&self) -> Self {
    Self::new(self.max_points_in_leaf)
  }
}

impl DocIdsWriter {
  pub const CONTINUOUS_IDS: i8 = -2;
  pub const BITSET_IDS: i8 = -1;
  pub const DELTA_BPV_16: i8 = 16;
  pub const BPV_24: i8 = 24;
  pub const BPV_32: i8 = 32;
  // These signs are legacy, should no longer be used in the writing side.
  pub const LEGACY_DELTA_VINT: i8 = 0;

  pub fn new(max_points_in_leaf: usize) -> Self {
    Self {
      scratch_longs: LongsRef::new(),
      scratch_ints_ref: IntsRef::from_slice(Vec::new(), 0, 0),
      max_points_in_leaf,
    }
  }

  fn scratch_ints(&mut self) -> &mut IntsRef<Vec<i32>> {
    if self.scratch_ints_ref.ints.is_empty() {
      self
        .scratch_ints_ref
        .ints
        .resize(self.max_points_in_leaf, 0);
    }
    &mut self.scratch_ints_ref
  }

  pub(crate) fn write_doc_ids<DO>(
    &mut self,
    doc_ids: &[i32],
    start: usize,
    count: usize,
    out: &mut DO,
  ) -> Result<()>
  where
    DO: DataOutput,
  {
    // docs can be sorted either when all docs in a block have the same
    // value or when a segment is sorted
    let mut strictly_sorted = true;
    let mut min = doc_ids[0];
    let mut max = doc_ids[0];
    if count == 1 {
      out.write_byte(DocIdsWriter::CONTINUOUS_IDS as u8)?;
      out.write_vint(doc_ids[start])?;
      return Ok(());
    }
    for i in 1..count {
      let last = doc_ids[start + i - 1];
      let current = doc_ids[start + i];
      if last >= current {
        strictly_sorted = false;
      }
      min = min.min(current);
      max = max.max(current);
    }

    let min2max: usize = (max - min + 1).try_convert()?;
    if strictly_sorted {
      if min2max == count {
        // continuous ids, typically happens when segment is sorted
        out.write_byte(DocIdsWriter::CONTINUOUS_IDS as u8)?;
        out.write_vint(doc_ids[start])?;
        return Ok(());
      } else if min2max <= ((count) << 4) {
        debug_assert!(min2max > count, "min2max: {min2max}, count: {count}");
        // Only trigger bitset optimization when max - min + 1 <= 16 *
        // count in order to avoid expanding too much
        // storage. A field with lower cardinality will
        // have higher probability to trigger this optimization.
        out.write_byte(DocIdsWriter::BITSET_IDS as u8)?;
        Self::write_ids_as_bit_set(doc_ids, start, count, out)?;
        return Ok(());
      }
    }
    if min2max <= 0xffff {
      out.write_byte(DocIdsWriter::DELTA_BPV_16 as u8)?;
      let docs = &doc_ids[start..start + count];
      out.write_vint(min)?;
      let (first, second) = docs.split_at(count >> 1);
      let (first, second) = if cfg!(debug_assertions) {
        (first, second)
      } else {
        let (high_groups, high_tail) = first.as_chunks::<4>();
        let (low_groups, low_tail) = second[..first.len()].as_chunks::<4>();
        let base = wide::i32x4::splat(min);
        for (&high, &low) in high_groups.iter().zip(low_groups) {
          let packed = ((wide::i32x4::new(high) - base) << 16u32) | (wide::i32x4::new(low) - base);
          out.write_ints(&packed.to_array())?;
        }
        (high_tail, low_tail)
      };
      for (&high, &low) in first.iter().zip(second) {
        out.write_int((low - min) | ((high - min) << 16))?;
      }
      if count & 1 == 1 {
        out.write_short((docs[count - 1] - min) as i16)?;
      }
    } else if max <= 0xFFFFFF {
      out.write_byte(DocIdsWriter::BPV_24 as u8)?;
      // write them the same way we are reading them.
      let (groups, tail) = doc_ids[start..start + count].as_chunks::<8>();
      for &[doc1, doc2, doc3, doc4, doc5, doc6, doc7, doc8] in groups {
        // Rearrange the low three bytes of each DocID into the original
        // three long values, with the same byte order on every platform.
        let first: wide::u8x16 =
          wide::bytemuck::cast([doc1.to_le(), doc2.to_le(), doc3.to_le(), doc4.to_le()]);
        let second: wide::u8x16 =
          wide::bytemuck::cast([doc5.to_le(), doc6.to_le(), doc7.to_le(), doc8.to_le()]);
        // This safe API also supports the minimum wide dependency version.
        #[allow(deprecated)]
        let first_two = first.swizzle(wide::i8x16::new([
          9, 10, 4, 5, 6, 0, 1, 2, -1, -1, -1, -1, 12, 13, 14, 8,
        ]))
          | second.swizzle(wide::i8x16::new([
            -1, -1, -1, -1, -1, -1, -1, -1, 6, 0, 1, 2, -1, -1, -1, -1,
          ]));
        #[allow(deprecated)]
        let last = second.swizzle(wide::i8x16::new([
          12, 13, 14, 8, 9, 10, 4, 5, -1, -1, -1, -1, -1, -1, -1, -1,
        ]));
        let first_two: [u64; 2] = wide::bytemuck::cast(first_two);
        let last: [u64; 2] = wide::bytemuck::cast(last);
        let l1 = u64::from_le(first_two[0]) as i64;
        let l2 = u64::from_le(first_two[1]) as i64;
        let l3 = u64::from_le(last[0]) as i64;
        out.write_long(l1)?;
        out.write_long(l2)?;
        out.write_long(l3)?;
      }

      for &doc in tail {
        out.write_short(((doc as u32) >> 8) as i16)?;
        out.write_byte(doc as u8)?;
      }
    } else {
      out.write_byte(DocIdsWriter::BPV_32 as u8)?;
      if let Some(docs) = doc_ids.get(start..).and_then(|docs| docs.get(..count)) {
        if docs.len() <= 32 {
          out.write_ints(docs)?;
        } else {
          for chunk in docs.chunks(16) {
            out.write_ints(chunk)?;
          }
        }
      } else {
        for i in 0..count {
          out.write_int(doc_ids[start + i])?;
        }
      }
    }
    Ok(())
  }
  fn write_ids_as_bit_set<DO>(
    doc_ids: &[i32],
    start: usize,
    count: usize,
    out: &mut DO,
  ) -> Result<()>
  where
    DO: DataOutput,
  {
    let min = doc_ids[start];
    let max = doc_ids[start + count - 1];

    let offset_words = min >> 6;
    let offset_bits = offset_words << 6;
    let total_word_count = FixedBitSet::bits2words((max - offset_bits + 1).try_convert()?);
    let mut current_word: i64 = 0;
    let mut current_word_index = 0;

    out.write_vint(offset_words)?;
    out.write_vint(total_word_count.try_convert()?)?;
    // build bit set streaming
    let mut remaining = &doc_ids[start..start + count];
    while let Some((&doc, tail)) = remaining.split_first() {
      let index = doc - offset_bits;
      let next_word_index = index >> 6;
      debug_assert!(
        current_word_index <= next_word_index,
        "current_word_index: {current_word_index}, next_word_index: {next_word_index}"
      );
      if current_word_index < next_word_index {
        out.write_long(current_word)?;
        current_word = 0;
        current_word_index += 1;
        while current_word_index < next_word_index {
          current_word_index += 1;
          out.write_long(0)?;
        }
      }
      // In this sorted slice, matching endpoint words also cover both inner IDs.
      if let Some(&[first, second, third, fourth]) = remaining.first_chunk::<4>()
        && (first >> 6) == (fourth >> 6)
      {
        let first_pair = wide::u64x2::new([first as u32 as u64, second as u32 as u64]);
        let second_pair = wide::u64x2::new([third as u32 as u64, fourth as u32 as u64]);
        let bits = (wide::u64x2::ONE << first_pair) | (wide::u64x2::ONE << second_pair);
        let [low, high] = bits.to_array();
        current_word |= (low | high) as i64;
        remaining = &remaining[4..];
      } else {
        current_word |= 1i64.wrapping_shl(index as u32);
        remaining = tail;
      }
    }
    out.write_long(current_word)?;
    debug_assert!(
      current_word_index + 1 == total_word_count as i32,
      "current_word_index + 1: {}, total_word_count: {}",
      current_word_index + 1,
      total_word_count
    );
    Ok(())
  }

  /// Read `count` integers into `doc_ids`.
  pub(crate) fn read_ints<II>(
    &mut self,
    input: &mut II,
    count: usize,
    doc_ids: &mut [i32],
  ) -> Result<()>
  where
    II: IndexInput,
  {
    let bpv = input.read_byte()? as i8;
    match bpv {
      DocIdsWriter::CONTINUOUS_IDS => Self::read_continuous_ids(input, count, doc_ids),
      DocIdsWriter::BITSET_IDS => self.read_bit_set(input, count, doc_ids),
      DocIdsWriter::DELTA_BPV_16 => Self::read_delta16(input, count, doc_ids),
      DocIdsWriter::BPV_24 => Self::read_ints24(input, count, doc_ids),
      DocIdsWriter::BPV_32 => Self::read_ints32(input, count, doc_ids),
      DocIdsWriter::LEGACY_DELTA_VINT => Self::read_legacy_delta_vints(input, count, doc_ids),
      _ => Err(LuceneError::illegal_state(format!(
        "Unsupported number of bits per value: {bpv}"
      ))),
    }
  }
  fn read_bit_set_iterator<II>(
    &mut self,
    input: &mut II,
    count: usize,
  ) -> Result<DocBaseBitSetIterator>
  where
    II: IndexInput,
  {
    let offset_words = input.read_vint()?;
    let long_len = input.read_vint()?.try_convert()?;
    ArrayUtil::grow_no_copy(&mut self.scratch_longs.longs, long_len, || 0)?;
    input.read_longs(&mut self.scratch_longs.longs, 0, long_len)?;
    // make ghost bits clear for FixedBitSet.
    if (long_len) < self.scratch_longs.length {
      self.scratch_longs.longs[long_len..].fill(0);
    }
    self.scratch_longs.length = long_len;
    let bit_set =
      FixedBitSet::with_capacity(std::mem::take(&mut self.scratch_longs.longs), long_len << 6)?;
    DocBaseBitSetIterator::new(bit_set, count as i64, (offset_words << 6).try_convert()?)
  }

  fn read_continuous_ids<II>(input: &mut II, count: usize, doc_ids: &mut [i32]) -> Result<()>
  where
    II: IndexInput,
  {
    let start = input.read_vint()?;
    if doc_ids.len() < count {
      for (i, doc_id) in doc_ids.iter_mut().enumerate() {
        *doc_id = start + i as i32;
      }
      return Err(LuceneError::array_index_out_of_bounds(format!(
        "Index {} out of bounds for length {}",
        doc_ids.len(),
        doc_ids.len()
      )));
    }
    for (i, doc_id) in doc_ids.iter_mut().take(count).enumerate() {
      *doc_id = start + i as i32;
    }
    Ok(())
  }

  fn read_legacy_delta_vints<II>(input: &mut II, count: usize, doc_ids: &mut [i32]) -> Result<()>
  where
    II: IndexInput,
  {
    let mut doc = 0;
    let length = doc_ids.len();
    let mut i = 0;
    while i < count {
      doc += input.read_vint()?;
      let doc_id = doc_ids.get_mut(i).ok_or_else(|| {
        LuceneError::array_index_out_of_bounds(format!(
          "Index {i} out of bounds for length {length}"
        ))
      })?;
      *doc_id = doc;
      i += 1;
    }
    Ok(())
  }

  fn read_bit_set<II>(&mut self, input: &mut II, count: usize, doc_ids: &mut [i32]) -> Result<()>
  where
    II: IndexInput,
  {
    let mut iterator = self.read_bit_set_iterator(input, count)?;
    let doc_base = iterator.get_doc_base();
    let word_count = self.scratch_longs.length;
    let end = word_count
      .checked_mul(64)
      .and_then(|bits| doc_base.checked_add(bits));
    if word_count == 0 || end.is_none_or(|end| end >= NO_MORE_DOCS as usize) {
      let mut pos = 0;
      loop {
        let doc_id = iterator.next_doc()?;
        if doc_id == NO_MORE_DOCS {
          break;
        }
        doc_ids[pos] = doc_id;
        pos += 1;
      }
      debug_assert!(pos == count, "pos: {pos}, count: {count}");
      self.scratch_longs.longs = iterator.bits.bits;
      return Ok(());
    }
    let mut pos = 0usize;
    for (word_index, &bits) in iterator
      .get_bit_set()
      .get_bits()
      .iter()
      .take(self.scratch_longs.length)
      .enumerate()
    {
      let mut word = bits as u64;
      if word == u64::MAX
        && let Some(end) = pos.checked_add(64)
        && let Some(dst) = doc_ids.get_mut(pos..end)
      {
        let base = doc_base + (word_index << 6);
        for (bit, doc_id) in dst.iter_mut().enumerate() {
          *doc_id = (base + bit) as i32;
        }
        pos = end;
        continue;
      }
      while word != 0 {
        let bit = word.trailing_zeros() as usize;
        doc_ids[pos] = (doc_base + (word_index << 6) + bit) as i32;
        pos += 1;
        word &= word - 1;
      }
    }
    debug_assert!(pos == count, "pos: {pos}, count: {count}");
    self.scratch_longs.longs = iterator.bits.bits;
    Ok(())
  }

  fn read_delta16<II>(input: &mut II, count: usize, doc_ids: &mut [i32]) -> Result<()>
  where
    II: IndexInput,
  {
    let min = input.read_vint()?;
    let half_len = count >> 1;
    input.read_ints(doc_ids, 0, half_len)?;
    for i in 0..half_len {
      let l = doc_ids[i];
      doc_ids[i] = ((l as u32) >> 16) as i32 + min;
      doc_ids[half_len + i] = (l & 0xffff) + min;
    }
    if count & 1 == 1 {
      doc_ids[count - 1] = (input.read_short()? as u16 as i32) + min;
    }
    Ok(())
  }

  fn read_ints24<II>(input: &mut II, count: usize, doc_ids: &mut [i32]) -> Result<()>
  where
    II: IndexInput,
  {
    let mut i = 0;
    let count_usize = count;
    while i < count_usize.saturating_sub(7) {
      let l1 = input.read_long()? as u64;
      let l2 = input.read_long()? as u64;
      let l3 = input.read_long()? as u64;
      let ids = [
        (l1 >> 40) as i32,
        ((l1 >> 16) & 0xffffff) as i32,
        (((l1 & 0xffff) << 8) | ((l2 >> 56) & 0xff)) as i32,
        ((l2 >> 32) & 0xffffff) as i32,
        ((l2 >> 8) & 0xffffff) as i32,
        (((l2 & 0xff) << 16) | ((l3 >> 48) & 0xffff)) as i32,
        ((l3 >> 24) & 0xffffff) as i32,
        (l3 & 0xffffff) as i32,
      ];
      if let Some(dst) = doc_ids.get_mut(i..i + 8) {
        dst.copy_from_slice(&ids);
      } else {
        for (j, doc_id) in ids.into_iter().enumerate() {
          doc_ids[i + j] = doc_id;
        }
      }
      i += 8;
    }
    while i < count_usize {
      doc_ids[i] =
        ((input.read_short()? as u16 as i32) << 8) | ((input.read_byte()? as i32) & 0xff);
      i += 1;
    }
    Ok(())
  }

  fn read_ints32<II>(input: &mut II, count: usize, doc_ids: &mut [i32]) -> Result<()>
  where
    II: IndexInput,
  {
    input.read_ints(doc_ids, 0, count)?;
    Ok(())
  }
  pub(crate) fn read_ints_with_visitor<II, V>(
    &mut self,
    input: &mut II,
    count: usize,
    visitor: &mut V,
  ) -> Result<()>
  where
    II: IndexInput,
    V: IntersectVisitor,
  {
    let bpv = input.read_byte()? as i8;
    match bpv {
      DocIdsWriter::CONTINUOUS_IDS => Self::read_continuous_ids_with_visitor(input, count, visitor),
      DocIdsWriter::BITSET_IDS => self.read_bit_set_with_visitor(input, count, visitor),
      DocIdsWriter::DELTA_BPV_16 => self.read_delta16_with_visitor(input, count, visitor),
      DocIdsWriter::BPV_24 => Self::read_ints24_with_visitor(input, count, visitor),
      DocIdsWriter::BPV_32 => self.read_ints32_with_visitor(input, count, visitor),
      DocIdsWriter::LEGACY_DELTA_VINT => {
        Self::read_legacy_delta_vints_with_visitor(input, count, visitor)
      },
      _ => Err(LuceneError::illegal_state(format!(
        "Unsupported number of bits per value: {bpv}"
      ))),
    }
  }

  fn read_bit_set_with_visitor<II, V>(
    &mut self,
    input: &mut II,
    count: usize,
    visitor: &mut V,
  ) -> Result<()>
  where
    II: IndexInput,
    V: IntersectVisitor,
  {
    let mut bit_set_iterator = self.read_bit_set_iterator(input, count)?;
    let result = visitor.visit_with_iterator(&mut bit_set_iterator);
    self.scratch_longs.longs = bit_set_iterator.bits.bits;
    result
  }
  fn read_continuous_ids_with_visitor<II, V>(
    input: &mut II,
    count: usize,
    visitor: &mut V,
  ) -> Result<()>
  where
    II: IndexInput,
    V: IntersectVisitor,
  {
    let start: usize = input.read_vint()?.try_convert()?;
    let extra = start & 63;
    let offset = start - extra;
    let num_bits = count + extra;
    let mut bit_set = FixedBitSet::with_set_prefix(num_bits, num_bits);
    bit_set.clear_range(0, extra)?;
    let mut disi = DocBaseBitSetIterator::new(bit_set, count as i64, offset)?;
    visitor.visit_with_iterator(&mut disi)?;
    Ok(())
  }
  fn read_legacy_delta_vints_with_visitor<II, V>(
    input: &mut II,
    count: usize,
    visitor: &mut V,
  ) -> Result<()>
  where
    II: IndexInput,
    V: IntersectVisitor,
  {
    let mut doc = 0;
    for _ in 0..count {
      doc += input.read_vint()?;
      visitor.visit(doc)?;
    }
    Ok(())
  }
  fn read_delta16_with_visitor<II, V>(
    &mut self,
    input: &mut II,
    count: usize,
    visitor: &mut V,
  ) -> Result<()>
  where
    II: IndexInput,
    V: IntersectVisitor,
  {
    let scratch = self.scratch_ints();
    Self::read_delta16(input, count, &mut scratch.ints)?;
    scratch.length = count;
    visitor.visit_with_ints_ref(scratch)?;
    Ok(())
  }
  fn read_ints24_with_visitor<II, V>(input: &mut II, count: usize, visitor: &mut V) -> Result<()>
  where
    II: IndexInput,
    V: IntersectVisitor,
  {
    let mut i = 0;
    let count_usize = count;
    while i < count_usize.saturating_sub(7) {
      let l1 = input.read_long()? as u64;
      let l2 = input.read_long()? as u64;
      let l3 = input.read_long()? as u64;
      visitor.visit((l1 >> 40) as i32)?;
      visitor.visit(((l1 >> 16) & 0xffffff) as i32)?;
      visitor.visit((((l1 & 0xffff) << 8) | ((l2 >> 56) & 0xff)) as i32)?;
      visitor.visit(((l2 >> 32) & 0xffffff) as i32)?;
      visitor.visit(((l2 >> 8) & 0xffffff) as i32)?;
      visitor.visit((((l2 & 0xff) << 16) | ((l3 >> 48) & 0xffff)) as i32)?;
      visitor.visit(((l3 >> 24) & 0xffffff) as i32)?;
      visitor.visit((l3 & 0xffffff) as i32)?;
      i += 8;
    }
    while i < count_usize {
      let s = input.read_short()? as u16 as i32;
      let b = input.read_byte()? as i32;
      visitor.visit((s << 8) | b)?;
      i += 1;
    }
    Ok(())
  }
  fn read_ints32_with_visitor<II, V>(
    &mut self,
    input: &mut II,
    count: usize,
    visitor: &mut V,
  ) -> Result<()>
  where
    II: IndexInput,
    V: IntersectVisitor,
  {
    let scratch = self.scratch_ints();
    input.read_ints(&mut scratch.ints, 0, count)?;
    scratch.length = count;
    visitor.visit_with_ints_ref(scratch)?;
    Ok(())
  }
}