Do a merge two by two

This commit is contained in:
Kerollmops 2020-06-01 18:27:26 +02:00
parent 5404776f7a
commit 6a047519f6
No known key found for this signature in database
GPG Key ID: 92ADA4E935E71FA4

View File

@ -285,7 +285,8 @@ fn main() -> anyhow::Result<()> {
.open(opt.database)?;
let index = Index::new(&env)?;
let mtbl_store = opt.files_to_index
let mut stores: Vec<_> = opt.files_to_index
.into_par_iter()
.try_fold(MtblKvStore::default, |acc, path| {
let rdr = csv::Reader::from_path(path)?;
@ -295,7 +296,20 @@ fn main() -> anyhow::Result<()> {
.inspect(|_| {
eprintln!("Total number of documents seen so far is {}", ID_GENERATOR.load(Ordering::Relaxed))
})
.try_reduce(MtblKvStore::default, MtblKvStore::merge_with)?;
.collect::<Result<_, _>>()?;
while stores.len() >= 1 {
let s = std::mem::take(&mut stores);
stores = s.into_par_iter().chunks(2).map(|mut v| {
match (v.pop(), v.pop()) {
(Some(a), Some(b)) => a.merge_with(b),
(Some(a), _) => Ok(a),
_ => unreachable!(),
}
}).collect::<Result<_, _>>()?;
}
let mtbl_store = stores.pop().unwrap_or_default();
eprintln!("We are writing into LMDB...");
let mut wtxn = env.write_txn()?;