mirror of
https://github.com/meilisearch/meilisearch.git
synced 2025-07-27 00:31:02 +00:00
Introduce an heed codec that reduce the size of small amount of serialized integers
This commit is contained in:
committed by
Clément Renault
parent
3e2250423c
commit
5664c37539
29
src/heed_codec/byteorder_x_roaring_bitmap_codec.rs
Normal file
29
src/heed_codec/byteorder_x_roaring_bitmap_codec.rs
Normal file
@ -0,0 +1,29 @@
|
||||
use std::borrow::Cow;
|
||||
use byteorder::{NativeEndian, ReadBytesExt, WriteBytesExt};
|
||||
use roaring::RoaringBitmap;
|
||||
|
||||
pub struct ByteorderXRoaringBitmapCodec;
|
||||
|
||||
impl heed::BytesDecode<'_> for ByteorderXRoaringBitmapCodec {
|
||||
type DItem = RoaringBitmap;
|
||||
|
||||
fn bytes_decode(mut bytes: &[u8]) -> Option<Self::DItem> {
|
||||
let mut bitmap = RoaringBitmap::new();
|
||||
while let Ok(integer) = bytes.read_u32::<NativeEndian>() {
|
||||
bitmap.insert(integer);
|
||||
}
|
||||
Some(bitmap)
|
||||
}
|
||||
}
|
||||
|
||||
impl heed::BytesEncode<'_> for ByteorderXRoaringBitmapCodec {
|
||||
type EItem = RoaringBitmap;
|
||||
|
||||
fn bytes_encode(item: &Self::EItem) -> Option<Cow<[u8]>> {
|
||||
let mut bytes = Vec::with_capacity(item.len() as usize * 4);
|
||||
for integer in item.iter() {
|
||||
bytes.write_u32::<NativeEndian>(integer).ok()?;
|
||||
}
|
||||
Some(Cow::Owned(bytes))
|
||||
}
|
||||
}
|
@ -1,7 +1,9 @@
|
||||
mod beu32_str_codec;
|
||||
mod byteorder_x_roaring_bitmap_codec;
|
||||
mod csv_string_record_codec;
|
||||
mod roaring_bitmap_codec;
|
||||
mod beu32_str_codec;
|
||||
|
||||
pub use self::beu32_str_codec::BEU32StrCodec;
|
||||
pub use self::byteorder_x_roaring_bitmap_codec::ByteorderXRoaringBitmapCodec;
|
||||
pub use self::csv_string_record_codec::CsvStringRecordCodec;
|
||||
pub use self::roaring_bitmap_codec::RoaringBitmapCodec;
|
||||
pub use self::beu32_str_codec::BEU32StrCodec;
|
||||
|
Reference in New Issue
Block a user