mirror of
https://github.com/meilisearch/MeiliSearch
synced 2025-07-03 11:57:07 +02:00
Add linear facet databases
This commit is contained in:
parent
b17896d899
commit
51b6293738
4 changed files with 202 additions and 23 deletions
|
@ -27,17 +27,34 @@ impl heed::BytesEncode<'_> for OrderedF64Codec {
|
|||
fn bytes_encode(f: &Self::EItem) -> Result<Cow<'_, [u8]>, BoxedError> {
|
||||
let mut buffer = [0u8; 16];
|
||||
|
||||
// write the globally ordered float
|
||||
let bytes = f64_into_bytes(*f).ok_or(InvalidGloballyOrderedFloatError { float: *f })?;
|
||||
buffer[..8].copy_from_slice(&bytes[..]);
|
||||
// Then the f64 value just to be able to read it back
|
||||
let bytes = f.to_be_bytes();
|
||||
buffer[8..16].copy_from_slice(&bytes[..]);
|
||||
encode_f64_into_ordered_bytes(*f, &mut buffer)?;
|
||||
|
||||
Ok(Cow::Owned(buffer.to_vec()))
|
||||
}
|
||||
}
|
||||
|
||||
impl OrderedF64Codec {
|
||||
pub fn serialize_into(
|
||||
f: f64,
|
||||
buffer: &mut [u8; 16],
|
||||
) -> Result<(), InvalidGloballyOrderedFloatError> {
|
||||
encode_f64_into_ordered_bytes(f, buffer)
|
||||
}
|
||||
}
|
||||
|
||||
fn encode_f64_into_ordered_bytes(
|
||||
f: f64,
|
||||
buffer: &mut [u8; 16],
|
||||
) -> Result<(), InvalidGloballyOrderedFloatError> {
|
||||
let bytes = f64_into_bytes(f).ok_or(InvalidGloballyOrderedFloatError { float: f })?;
|
||||
buffer[..8].copy_from_slice(&bytes[..]);
|
||||
// Then the f64 value just to be able to read it back
|
||||
let bytes = f.to_be_bytes();
|
||||
buffer[8..16].copy_from_slice(&bytes[..]);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[derive(Error, Debug)]
|
||||
#[error("the float {float} cannot be converted to a globally ordered representation")]
|
||||
pub struct InvalidGloballyOrderedFloatError {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue