A vector which swaps to disk when exceeding a certain length.
T: Serialize + Deserialize
Result
String
)Compression
currently does not compress. It is there to keep the API stable.rust
use swapvec::SwapVec;
let iterator = (0..9).into_iter();
let mut much_data = SwapVec::default();
// Starts using disk for big iterators
much_data.consume(iterator).unwrap();
for value in much_data.into_iter() {
println!("Read back: {}", value.unwrap());
}
This is the code for cargo run
(src/main.rs
).
```rust
use swapvec::{SwapVec, SwapVecConfig};
const DATA_MB: u64 = 1024;
fn main() { let elementcount = DATAMB / 8; let bigiterator = 0..elementcount * 1024 * 1024;
let config = swapvec::SwapVecConfig {
batch_size: 8 * 1024,
..SwapVecConfig::default()
};
let mut swapvec: SwapVec<_> = SwapVec::with_config(config);
swapvec.consume(big_iterator.into_iter()).unwrap();
println!("Data size: {}MB", DATA_MB);
println!("Done. Batches written: {}", swapvec.batches_written());
println!(
"Filesize: {}MB",
swapvec
.file_size()
.map(|x| x.unwrap() / 1024 / 1024)
.unwrap_or(0)
);
println!("Read back");
let read_back: Vec<_> = swapvec.into_iter().map(|x| x.unwrap()).collect();
println!("{:#?}", read_back.len());
} ```