Store the facet string values in multiple FSTs

This commit is contained in:
Clément Renault 2023-05-02 09:34:28 +02:00 committed by Louis Dureuil
parent 9deeec88e0
commit 15a4c05379
No known key found for this signature in database
6 changed files with 73 additions and 3 deletions

View file

@ -0,0 +1,23 @@
use fst::Set;
use std::borrow::Cow;
use heed::{BytesDecode, BytesEncode};
/// A codec for values of type `Set<&[u8]>`.
pub struct FstSetCodec;
impl<'a> BytesEncode<'a> for FstSetCodec {
type EItem = Set<Vec<u8>>;
fn bytes_encode(item: &'a Self::EItem) -> Option<Cow<'a, [u8]>> {
Some(Cow::Borrowed(item.as_fst().as_bytes()))
}
}
impl<'a> BytesDecode<'a> for FstSetCodec {
type DItem = Set<&'a [u8]>;
fn bytes_decode(bytes: &'a [u8]) -> Option<Self::DItem> {
Some(Set::new(bytes).ok()?)
}
}