mirror of
https://github.com/quickwit-oss/tantivy.git
synced 2026-05-25 20:50:43 +00:00
Format, small changes in VInt
This commit is contained in:
@@ -19,20 +19,19 @@ impl BinarySerializable for VInt {
|
||||
fn serialize<W: Write>(&self, writer: &mut W) -> io::Result<()> {
|
||||
let mut remaining = self.0;
|
||||
let mut buffer = [0u8; 10];
|
||||
let mut written = 0;
|
||||
let mut i = 0;
|
||||
loop {
|
||||
let next_byte: u8 = (remaining % 128u64) as u8;
|
||||
remaining /= 128u64;
|
||||
if remaining == 0u64 {
|
||||
buffer[written] = next_byte | 128u8;
|
||||
written += 1;
|
||||
break;
|
||||
buffer[i] = next_byte | 128u8;
|
||||
return writer.write_all(&buffer[0..i + 1]);
|
||||
} else {
|
||||
buffer[written] = next_byte;
|
||||
written += 1;
|
||||
buffer[i] = next_byte;
|
||||
}
|
||||
i += 1;
|
||||
}
|
||||
writer.write_all(&buffer[0..written])
|
||||
|
||||
}
|
||||
|
||||
fn deserialize<R: Read>(reader: &mut R) -> io::Result<Self> {
|
||||
|
||||
@@ -128,14 +128,18 @@ impl From<Vec<u64>> for U64FastFieldReader {
|
||||
}
|
||||
directory
|
||||
.open_read(path)
|
||||
.chain_err(|| "Failed to open the file")
|
||||
.and_then(|source| FastFieldsReader::from_source(source)
|
||||
.chain_err(|| "Failed to read the file."))
|
||||
.and_then(|ff_readers| ff_readers
|
||||
.open_reader(field)
|
||||
.ok_or_else(|| {"Failed to find the requested field".into() }))
|
||||
.chain_err(|| "Failed to open the file")
|
||||
.and_then(|source| {
|
||||
FastFieldsReader::from_source(source)
|
||||
.chain_err(|| "Failed to read the file.")
|
||||
})
|
||||
.and_then(|ff_readers| {
|
||||
ff_readers
|
||||
.open_reader(field)
|
||||
.ok_or_else(|| "Failed to find the requested field".into())
|
||||
})
|
||||
.expect("This should never happen, please report.")
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -48,7 +48,6 @@ impl<'a, V> Ord for HeapItem<'a, V>
|
||||
/// - the term
|
||||
/// - a slice with the ordinal of the segments containing
|
||||
/// the terms.
|
||||
#[allow(should_implement_trait)]
|
||||
pub struct TermMerger<'a, V>
|
||||
where V: 'a + BinarySerializable + Default
|
||||
{
|
||||
@@ -131,6 +130,7 @@ impl<'a, V> TermMerger<'a, V>
|
||||
}
|
||||
|
||||
/// Iterates through terms
|
||||
#[allow(should_implement_trait)]
|
||||
pub fn next(&mut self) -> Option<Term<&[u8]>> {
|
||||
if self.advance() {
|
||||
Some(Term::wrap(self.current_streamers[0].streamer.key()))
|
||||
|
||||
Reference in New Issue
Block a user