Format, small changes in VInt

This commit is contained in:
Paul Masurel
2017-05-31 08:22:53 +09:00
parent 8d4778f94d
commit 0521844e56
3 changed files with 18 additions and 15 deletions

View File

@@ -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> {

View File

@@ -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.")
}
}

View File

@@ -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()))