From 6cc91824c1d831950187cfa6b4ca047cf0b89683 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Lecrenier?= Date: Wed, 31 Aug 2022 07:51:11 +0200 Subject: [PATCH] Remove unused heed codec files --- .../facet_string_zero_bounds_value_codec.rs | 114 ------------------ .../facet/facet_value_string_codec.rs | 35 ------ milli/src/heed_codec/facet/mod.rs | 4 +- milli/src/update/delete_documents.rs | 2 +- 4 files changed, 3 insertions(+), 152 deletions(-) delete mode 100644 milli/src/heed_codec/facet/facet_string_zero_bounds_value_codec.rs delete mode 100644 milli/src/heed_codec/facet/facet_value_string_codec.rs diff --git a/milli/src/heed_codec/facet/facet_string_zero_bounds_value_codec.rs b/milli/src/heed_codec/facet/facet_string_zero_bounds_value_codec.rs deleted file mode 100644 index 337433c2b..000000000 --- a/milli/src/heed_codec/facet/facet_string_zero_bounds_value_codec.rs +++ /dev/null @@ -1,114 +0,0 @@ -use std::borrow::Cow; -use std::convert::TryInto; -use std::{marker, str}; - -use super::try_split_at; - -/// A codec that optionally encodes two strings in front of the value. -/// -/// The usecase is for the facet string levels algorithm where we must -/// know the origin of a group, the group left and right bounds are stored -/// in the value to not break the lexicographical ordering of the LMDB keys. -pub struct FacetStringZeroBoundsValueCodec(marker::PhantomData); - -impl<'a, C> heed::BytesDecode<'a> for FacetStringZeroBoundsValueCodec -where - C: heed::BytesDecode<'a>, -{ - type DItem = (Option<(&'a str, &'a str)>, C::DItem); - - fn bytes_decode(bytes: &'a [u8]) -> Option { - let (contains_bounds, bytes) = bytes.split_first()?; - - if *contains_bounds != 0 { - let (left_len, bytes) = try_split_at(bytes, 2)?; - let (right_len, bytes) = try_split_at(bytes, 2)?; - - let left_len = left_len.try_into().ok().map(u16::from_be_bytes)?; - let right_len = right_len.try_into().ok().map(u16::from_be_bytes)?; - - let (left, bytes) = try_split_at(bytes, left_len as usize)?; - let (right, bytes) = try_split_at(bytes, right_len as usize)?; - - let left = str::from_utf8(left).ok()?; - let right = str::from_utf8(right).ok()?; - - C::bytes_decode(bytes).map(|item| (Some((left, right)), item)) - } else { - C::bytes_decode(bytes).map(|item| (None, item)) - } - } -} - -impl<'a, C> heed::BytesEncode<'a> for FacetStringZeroBoundsValueCodec -where - C: heed::BytesEncode<'a>, -{ - type EItem = (Option<(&'a str, &'a str)>, C::EItem); - - fn bytes_encode((bounds, value): &'a Self::EItem) -> Option> { - let mut bytes = Vec::new(); - - match bounds { - Some((left, right)) => { - bytes.push(u8::max_value()); - - if left.is_empty() || right.is_empty() { - return None; - } - - let left_len: u16 = left.len().try_into().ok()?; - let right_len: u16 = right.len().try_into().ok()?; - - bytes.extend_from_slice(&left_len.to_be_bytes()); - bytes.extend_from_slice(&right_len.to_be_bytes()); - - bytes.extend_from_slice(left.as_bytes()); - bytes.extend_from_slice(right.as_bytes()); - - let value_bytes = C::bytes_encode(&value)?; - bytes.extend_from_slice(&value_bytes[..]); - - Some(Cow::Owned(bytes)) - } - None => { - bytes.push(0); - let value_bytes = C::bytes_encode(&value)?; - bytes.extend_from_slice(&value_bytes[..]); - Some(Cow::Owned(bytes)) - } - } - } -} - -#[cfg(test)] -mod tests { - use heed::types::Unit; - use heed::{BytesDecode, BytesEncode}; - use roaring::RoaringBitmap; - - use super::*; - use crate::CboRoaringBitmapCodec; - - #[test] - fn deserialize_roaring_bitmaps() { - let bounds = Some(("abc", "def")); - let docids: RoaringBitmap = (0..100).chain(3500..4398).collect(); - let key = (bounds, docids.clone()); - let bytes = - FacetStringZeroBoundsValueCodec::::bytes_encode(&key).unwrap(); - let (out_bounds, out_docids) = - FacetStringZeroBoundsValueCodec::::bytes_decode(&bytes).unwrap(); - assert_eq!((out_bounds, out_docids), (bounds, docids)); - } - - #[test] - fn deserialize_unit() { - let bounds = Some(("abc", "def")); - let key = (bounds, ()); - let bytes = FacetStringZeroBoundsValueCodec::::bytes_encode(&key).unwrap(); - let (out_bounds, out_unit) = - FacetStringZeroBoundsValueCodec::::bytes_decode(&bytes).unwrap(); - assert_eq!((out_bounds, out_unit), (bounds, ())); - } -} diff --git a/milli/src/heed_codec/facet/facet_value_string_codec.rs b/milli/src/heed_codec/facet/facet_value_string_codec.rs deleted file mode 100644 index 54abb7886..000000000 --- a/milli/src/heed_codec/facet/facet_value_string_codec.rs +++ /dev/null @@ -1,35 +0,0 @@ -use std::borrow::Cow; -use std::str; - -use crate::{try_split_array_at, FieldId}; - -pub struct FacetValueStringCodec; - -impl FacetValueStringCodec { - pub fn serialize_into(field_id: FieldId, value: &str, out: &mut Vec) { - out.reserve(value.len() + 2); - out.extend_from_slice(&field_id.to_be_bytes()); - out.extend_from_slice(value.as_bytes()); - } -} - -impl<'a> heed::BytesDecode<'a> for FacetValueStringCodec { - type DItem = (FieldId, &'a str); - - fn bytes_decode(bytes: &'a [u8]) -> Option { - let (field_id_bytes, bytes) = try_split_array_at(bytes)?; - let field_id = u16::from_be_bytes(field_id_bytes); - let value = str::from_utf8(bytes).ok()?; - Some((field_id, value)) - } -} - -impl<'a> heed::BytesEncode<'a> for FacetValueStringCodec { - type EItem = (FieldId, &'a str); - - fn bytes_encode((field_id, value): &Self::EItem) -> Option> { - let mut bytes = Vec::new(); - FacetValueStringCodec::serialize_into(*field_id, value, &mut bytes); - Some(Cow::Owned(bytes)) - } -} diff --git a/milli/src/heed_codec/facet/mod.rs b/milli/src/heed_codec/facet/mod.rs index d23ab391e..e145e311e 100644 --- a/milli/src/heed_codec/facet/mod.rs +++ b/milli/src/heed_codec/facet/mod.rs @@ -2,7 +2,7 @@ // mod facet_level_value_u32_codec; // mod facet_string_level_zero_codec; // mod facet_string_level_zero_value_codec; -mod facet_string_zero_bounds_value_codec; +// mod facet_string_zero_bounds_value_codec; mod field_doc_id_facet_f64_codec; mod field_doc_id_facet_string_codec; @@ -16,7 +16,7 @@ use heed::types::OwnedType; // pub use self::facet_string_level_zero_value_codec::{ // decode_prefix_string, encode_prefix_string, FacetStringLevelZeroValueCodec, // }; -pub use self::facet_string_zero_bounds_value_codec::FacetStringZeroBoundsValueCodec; +// pub use self::facet_string_zero_bounds_value_codec::FacetStringZeroBoundsValueCodec; pub use self::field_doc_id_facet_f64_codec::FieldDocIdFacetF64Codec; pub use self::field_doc_id_facet_string_codec::FieldDocIdFacetStringCodec; use crate::BEU16; diff --git a/milli/src/update/delete_documents.rs b/milli/src/update/delete_documents.rs index bb30f24c9..5eebff913 100644 --- a/milli/src/update/delete_documents.rs +++ b/milli/src/update/delete_documents.rs @@ -10,7 +10,7 @@ use time::OffsetDateTime; use super::ClearDocuments; use crate::error::{InternalError, SerializationError, UserError}; -use crate::heed_codec::facet::FacetStringZeroBoundsValueCodec; +// use crate::heed_codec::facet::FacetStringZeroBoundsValueCodec; use crate::heed_codec::CboRoaringBitmapCodec; use crate::index::{db_name, main_key}; use crate::{