diff --git a/Cargo.lock b/Cargo.lock index 4d0084fb0..0b900223f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -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" diff --git a/Cargo.toml b/Cargo.toml index 889079f53..6eb2a9fef 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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" diff --git a/src/heed_codec/mod.rs b/src/heed_codec/mod.rs index e81e9416a..a6c1d9555 100644 --- a/src/heed_codec/mod.rs +++ b/src/heed_codec/mod.rs @@ -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; diff --git a/src/heed_codec/obkv_codec.rs b/src/heed_codec/obkv_codec.rs new file mode 100644 index 000000000..94a230e05 --- /dev/null +++ b/src/heed_codec/obkv_codec.rs @@ -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 { + Some(KvReader::new(bytes)) + } +} + +impl heed::BytesEncode<'_> for ObkvCodec { + type EItem = KvWriter>; + + fn bytes_encode(item: &Self::EItem) -> Option> { + item.clone().into_inner().map(Cow::Owned).ok() + } +}