demo/
demo.rs

1use swapvec::{SwapVec, SwapVecConfig};
2
3const DATA_MB: u64 = 20;
4
5fn main() {
6    let element_count = DATA_MB / 8;
7    let big_iterator = 0..element_count * 1024 * 1024;
8
9    let config = swapvec::SwapVecConfig {
10        batch_size: 8 * 1024,
11        ..SwapVecConfig::default()
12    };
13    let mut swapvec: SwapVec<_> = SwapVec::with_config(config);
14    swapvec.consume(big_iterator.into_iter()).unwrap();
15
16    println!("Data size: {}MB", DATA_MB);
17    println!("Done. Batches written: {}", swapvec.batches_written());
18    println!(
19        "Filesize: {}MB",
20        swapvec
21            .file_size()
22            .map(|x| x as f32 / 1024. / 1024.)
23            .unwrap_or(0.)
24    );
25    println!("Read back");
26
27    let read_back: Vec<_> = swapvec.into_iter().map(|x| x.unwrap()).collect();
28
29    println!("Elements read back: {}", read_back.len());
30}