Replace the HashMap by a Vec for attributes documents ids

This commit is contained in:
Kerollmops 2020-06-26 14:39:26 +02:00
parent 6a2834f2b0
commit fe3be8f18a
No known key found for this signature in database
GPG Key ID: 92ADA4E935E71FA4

View File

@ -134,7 +134,7 @@ impl Index {
positions.push(union_positions.iter().collect()); positions.push(union_positions.iter().collect());
} }
let mut words_attributes_docids = HashMap::new(); let mut words_attributes_docids = Vec::new();
let number_attributes: u32 = 6; let number_attributes: u32 = 6;
for i in 0..number_attributes { for i in 0..number_attributes {
@ -155,9 +155,7 @@ impl Index {
None => intersect_docids = Some(union_docids), None => intersect_docids = Some(union_docids),
} }
} }
if let Some(docids) = intersect_docids { words_attributes_docids.push(intersect_docids);
words_attributes_docids.insert(i, docids);
}
} }
eprintln!("The documents you must find for each attribute: {:?}", words_attributes_docids); eprintln!("The documents you must find for each attribute: {:?}", words_attributes_docids);
@ -182,7 +180,7 @@ impl Index {
let mut union_cache = HashMap::new(); let mut union_cache = HashMap::new();
let mut intersect_cache = HashMap::new(); let mut intersect_cache = HashMap::new();
// Returns `true` if there is documents in common between the two words and positions given. // Returns `true` if there is documents in common between the two words and positions given.
let mut contains_documents = |(lword, lpos), (rword, rpos), union_cache: &mut HashMap<_, _>, words_attributes_docids: &HashMap<_, _>| { let mut contains_documents = |(lword, lpos), (rword, rpos), union_cache: &mut HashMap<_, _>, words_attributes_docids: &[_]| {
let proximity = best_proximity::positions_proximity(lpos, rpos); let proximity = best_proximity::positions_proximity(lpos, rpos);
if proximity == 0 { return false } if proximity == 0 { return false }
@ -200,7 +198,7 @@ impl Index {
let lattr = lpos / 1000; let lattr = lpos / 1000;
let rattr = rpos / 1000; let rattr = rpos / 1000;
if lattr == rattr { if lattr == rattr {
if let Some(docids) = words_attributes_docids.get(&lattr) { if let Some(docids) = &words_attributes_docids[lattr as usize] {
if lunion_docids.is_disjoint(&docids) { return false } if lunion_docids.is_disjoint(&docids) { return false }
if runion_docids.is_disjoint(&docids) { return false } if runion_docids.is_disjoint(&docids) { return false }
} }
@ -252,8 +250,10 @@ impl Index {
} }
// We achieve to find valid documents ids so we remove them from the candidate list. // We achieve to find valid documents ids so we remove them from the candidate list.
for (_, docids) in &mut words_attributes_docids { for docids in &mut words_attributes_docids {
docids.difference_with(&same_proximity_union); if let Some(docids) = docids {
docids.difference_with(&same_proximity_union);
}
} }
documents.push(same_proximity_union); documents.push(same_proximity_union);