From d65da7653dedb3dd011bf3abe4d09f09a5ed8bfd Mon Sep 17 00:00:00 2001 From: Luiz Irber Date: Sat, 12 Dec 2020 17:29:25 -0800 Subject: [PATCH] wip --- src/core/src/index/greyhound.rs | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/src/core/src/index/greyhound.rs b/src/core/src/index/greyhound.rs index c632bed4a5..e558336c99 100644 --- a/src/core/src/index/greyhound.rs +++ b/src/core/src/index/greyhound.rs @@ -1,3 +1,4 @@ +use std::collections::hash_map::Entry; use std::collections::{HashMap, HashSet}; use std::path::{Path, PathBuf}; use std::sync::atomic::{AtomicUsize, Ordering}; @@ -179,14 +180,21 @@ impl RevIndex { (a, b) }; - small_hashes.into_iter().for_each(|(hash, color)| { - let entry = large_hashes.entry(hash).or_insert_with(|| color); - if *entry != color { - let ids: Vec<_> = small_colors.indices(&color).cloned().collect(); - let new_color = - large_colors.update(Some(*entry), ids.as_slice()).unwrap(); - *entry = new_color; - } + small_hashes.into_iter().for_each(|(hash, small_color)| { + match large_hashes.entry(hash) { + Entry::Occupied(mut color) => { + let old_color = color.get(); + if *old_color != small_color { + let ids: Vec<_> = + small_colors.indices(&small_color).cloned().collect(); + let new_color = large_colors + .update(Some(*old_color), ids.as_slice()) + .unwrap(); + *color.get_mut() = new_color; + } + } + Entry::Vacant(old_color) => unimplemented!(), + }; }); (large_hashes, large_colors)