-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add FST cache serialization/deserialization support (#160)
* Add serialization for FST cache * Add parsers for FST cache * Some refactoring + tests * Small fixes * Implement PartialEq for FST caches & fix serialization/deserialization issue * Make tests more exhaustives & fix hashmap cache serialization/deserialization issue * Add State table serialization/deserialization support * Adding new traits and implementing binary serialization/deserialization for state table dependant structs * Refining the code * Changes following review * Add tests for StateTable serialization * Changes following review * Update changelog * Remove unused import
- Loading branch information
1 parent
552671c
commit 54083cc
Showing
41 changed files
with
1,457 additions
and
156 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,38 @@ | ||
pub struct ComposeFstOpOptions<M1, M2, CFB, ST> { | ||
pub struct ComposeFstOpOptions<M1, M2, CFB, OS> { | ||
pub matcher1: Option<M1>, | ||
pub matcher2: Option<M2>, | ||
pub filter_builder: Option<CFB>, | ||
pub state_table: Option<ST>, | ||
pub op_state: Option<OS>, | ||
} | ||
|
||
impl<M1, M2, CFB, ST> Default for ComposeFstOpOptions<M1, M2, CFB, ST> { | ||
impl<M1, M2, CFB, OS> Default for ComposeFstOpOptions<M1, M2, CFB, OS> { | ||
fn default() -> Self { | ||
Self { | ||
matcher1: None, | ||
matcher2: None, | ||
filter_builder: None, | ||
state_table: None, | ||
op_state: None, | ||
} | ||
} | ||
} | ||
|
||
impl<M1, M2, CFB, ST> ComposeFstOpOptions<M1, M2, CFB, ST> { | ||
impl<M1, M2, CFB, OS> ComposeFstOpOptions<M1, M2, CFB, OS> { | ||
pub fn new< | ||
IM1: Into<Option<M1>>, | ||
IM2: Into<Option<M2>>, | ||
ICFB: Into<Option<CFB>>, | ||
IST: Into<Option<ST>>, | ||
IST: Into<Option<OS>>, | ||
>( | ||
matcher1: IM1, | ||
matcher2: IM2, | ||
filter: ICFB, | ||
state_table: IST, | ||
op_state: IST, | ||
) -> Self { | ||
Self { | ||
matcher1: matcher1.into(), | ||
matcher2: matcher2.into(), | ||
filter_builder: filter.into(), | ||
state_table: state_table.into(), | ||
op_state: op_state.into(), | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,39 @@ | ||
use crate::algorithms::compose::filter_states::FilterState; | ||
use crate::parsers::nom_utils::NomCustomError; | ||
use crate::parsers::{parse_bin_u64, write_bin_u64, SerializeBinary}; | ||
use crate::StateId; | ||
|
||
use anyhow::Result; | ||
use nom::IResult; | ||
use std::io::Write; | ||
|
||
#[derive(Default, PartialEq, Eq, Clone, Hash, PartialOrd, Debug)] | ||
pub struct ComposeStateTuple<FS> { | ||
pub struct ComposeStateTuple<FS: FilterState> { | ||
pub fs: FS, | ||
pub s1: StateId, | ||
pub s2: StateId, | ||
} | ||
|
||
impl<FS: FilterState + SerializeBinary> SerializeBinary for ComposeStateTuple<FS> { | ||
/// Parse a filter state from a binary buffer. | ||
fn parse_binary(i: &[u8]) -> IResult<&[u8], Self, NomCustomError<&[u8]>> { | ||
let (i, fs) = FS::parse_binary(i)?; | ||
let (i, s1) = parse_bin_u64(i)?; | ||
let (i, s2) = parse_bin_u64(i)?; | ||
Ok(( | ||
i, | ||
Self { | ||
fs, | ||
s1: s1 as StateId, | ||
s2: s2 as StateId, | ||
}, | ||
)) | ||
} | ||
/// Writes a filter state to a writable buffer. | ||
fn write_binary<W: Write>(&self, writer: &mut W) -> Result<()> { | ||
self.fs.write_binary(writer)?; | ||
write_bin_u64(writer, self.s1 as u64)?; | ||
write_bin_u64(writer, self.s2 as u64)?; | ||
Ok(()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.