-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #55 from meilisearch/various-improvements
Various Improvements
- Loading branch information
Showing
12 changed files
with
259 additions
and
148 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
[package] | ||
name = "grenad" | ||
description = "Tools to sort, merge, write, and read immutable key-value pairs." | ||
version = "0.4.7" | ||
version = "0.5.0" | ||
authors = ["Kerollmops <[email protected]>"] | ||
repository = "https://github.com/meilisearch/grenad" | ||
documentation = "https://docs.rs/grenad" | ||
|
@@ -11,6 +11,7 @@ license = "MIT" | |
[dependencies] | ||
bytemuck = { version = "1.16.1", features = ["derive"] } | ||
byteorder = "1.5.0" | ||
either = { version = "1.13.0", default-features = false } | ||
flate2 = { version = "1.0", optional = true } | ||
lz4_flex = { version = "0.11.3", optional = true } | ||
rayon = { version = "1.10.0", optional = true } | ||
|
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
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 |
---|---|---|
@@ -0,0 +1,46 @@ | ||
use std::borrow::Cow; | ||
use std::result::Result; | ||
|
||
use either::Either; | ||
|
||
/// A trait defining the way we merge multiple | ||
/// values sharing the same key. | ||
pub trait MergeFunction { | ||
type Error; | ||
fn merge<'a>(&self, key: &[u8], values: &[Cow<'a, [u8]>]) | ||
-> Result<Cow<'a, [u8]>, Self::Error>; | ||
} | ||
|
||
impl<MF> MergeFunction for &MF | ||
where | ||
MF: MergeFunction, | ||
{ | ||
type Error = MF::Error; | ||
|
||
fn merge<'a>( | ||
&self, | ||
key: &[u8], | ||
values: &[Cow<'a, [u8]>], | ||
) -> Result<Cow<'a, [u8]>, Self::Error> { | ||
(*self).merge(key, values) | ||
} | ||
} | ||
|
||
impl<MFA, MFB> MergeFunction for Either<MFA, MFB> | ||
where | ||
MFA: MergeFunction, | ||
MFB: MergeFunction<Error = MFA::Error>, | ||
{ | ||
type Error = MFA::Error; | ||
|
||
fn merge<'a>( | ||
&self, | ||
key: &[u8], | ||
values: &[Cow<'a, [u8]>], | ||
) -> Result<Cow<'a, [u8]>, Self::Error> { | ||
match self { | ||
Either::Left(mfa) => mfa.merge(key, values), | ||
Either::Right(mfb) => mfb.merge(key, values), | ||
} | ||
} | ||
} |
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
Oops, something went wrong.