-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow providing own implementation of compression algorithm.
- Loading branch information
Julian Büttner
committed
May 15, 2023
1 parent
b8a76ac
commit 3369988
Showing
7 changed files
with
104 additions
and
11 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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,35 @@ | ||
use swapvec::{Compress, CompressBoxedClone, Compression, SwapVec, SwapVecConfig}; | ||
|
||
#[derive(Debug)] | ||
struct MyCompression; | ||
|
||
impl Compress for MyCompression { | ||
fn compress(&self, block: Vec<u8>) -> Vec<u8> { | ||
block | ||
} | ||
fn decompress(&self, block: Vec<u8>) -> Result<Vec<u8>, ()> { | ||
Ok(block) | ||
} | ||
} | ||
|
||
impl CompressBoxedClone for MyCompression { | ||
fn boxed_clone(&self) -> Box<dyn CompressBoxedClone> { | ||
Box::new(MyCompression) | ||
} | ||
} | ||
|
||
#[test] | ||
fn custom_compression() { | ||
let config = SwapVecConfig { | ||
compression: Some(Compression::Custom(Box::new(MyCompression))), | ||
swap_after: 16, | ||
batch_size: 5, | ||
}; | ||
|
||
let vector: Vec<u64> = (0..999).collect(); | ||
let mut v = SwapVec::with_config(config); | ||
v.consume(vector.clone().into_iter()).unwrap(); | ||
assert!(v.written_to_file()); | ||
let vector_read_back: Vec<u64> = v.into_iter().map(|x| x.unwrap()).collect(); | ||
assert_eq!(vector, vector_read_back); | ||
} |