Introduce the obkv heed codec

This commit is contained in:
Clément Renault 2020-10-21 15:51:48 +02:00
parent f6eecb855e
commit 2210818114
No known key found for this signature in database
GPG Key ID: 92ADA4E935E71FA4
4 changed files with 30 additions and 0 deletions

7
Cargo.lock generated
View File

@ -1021,6 +1021,7 @@ dependencies = [
"log 0.4.11",
"memmap",
"near-proximity",
"obkv",
"once_cell",
"rayon",
"ringtail",
@ -1241,6 +1242,12 @@ version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b8f8bdf33df195859076e54ab11ee78a1b208382d3a26ec40d142ffc1ecc49ef"
[[package]]
name = "obkv"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ce30a214135d83e7250f2e8fad781f7cb987e3a3f1b4529712d891594bda311c"
[[package]]
name = "once_cell"
version = "1.4.0"

View File

@ -21,6 +21,7 @@ levenshtein_automata = { version = "0.2.0", features = ["fst_automaton"] }
linked-hash-map = "0.5.3"
memmap = "0.7.0"
near-proximity = { git = "https://github.com/Kerollmops/plane-sweep-proximity", rev = "6608205" }
obkv = "0.1.0"
once_cell = "1.4.0"
rayon = "1.3.1"
ringtail = "0.3.0"

View File

@ -2,6 +2,7 @@ mod beu32_str_codec;
mod bo_roaring_bitmap_codec;
mod cbo_roaring_bitmap_codec;
mod csv_string_record_codec;
mod obkv_codec;
mod roaring_bitmap_codec;
mod str_str_u8_codec;
@ -9,5 +10,6 @@ pub use self::beu32_str_codec::BEU32StrCodec;
pub use self::bo_roaring_bitmap_codec::BoRoaringBitmapCodec;
pub use self::cbo_roaring_bitmap_codec::CboRoaringBitmapCodec;
pub use self::csv_string_record_codec::CsvStringRecordCodec;
pub use self::obkv_codec::ObkvCodec;
pub use self::roaring_bitmap_codec::RoaringBitmapCodec;
pub use self::str_str_u8_codec::StrStrU8Codec;

View File

@ -0,0 +1,20 @@
use std::borrow::Cow;
use obkv::{KvReader, KvWriter};
pub struct ObkvCodec;
impl<'a> heed::BytesDecode<'a> for ObkvCodec {
type DItem = KvReader<'a>;
fn bytes_decode(bytes: &'a [u8]) -> Option<Self::DItem> {
Some(KvReader::new(bytes))
}
}
impl heed::BytesEncode<'_> for ObkvCodec {
type EItem = KvWriter<Vec<u8>>;
fn bytes_encode(item: &Self::EItem) -> Option<Cow<[u8]>> {
item.clone().into_inner().map(Cow::Owned).ok()
}
}